From 47af22c7244b5092b954e42fd90af6e83f3154f7 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Sun, 6 Aug 2023 08:45:54 -0400 Subject: [PATCH] Update rpcclient library to latest version `ClientConnector` is no longer defined within `rpcclient` in its latest version. It has been changed to be obtained from the `cgrates/birpc` library instead. Replaced `net/rpc` with `cgrates/birpc` and `net/rpc/jsonrpc` with `cgrates/birpc/jsonrpc` libraries. The implementations of `CallBiRPC()` and `Handlers()` were removed, along with the methods associated with them. The `rpcclient.BIRPCConector` and the methods prefixed with `BiRPC` were removed from the `BiRPClient` interface. The `BiRPClient` interface was renamed to `BIRPCClient`, although not sure if needed (seems useful just to test if the structure is correct). `rpcclient.BiRPCConector` has been replaced with `context.ClientConnector`, which is now passed alongside `context.Context` within the same struct (`cgrates/birpc/context.Context`). Consequently, functions that were previously relying on it are now receiving the context instead. The changes were made in the following functions: - `engine/connmanager.go` - `*ConnManager.Call` - `engine/connmanager.go` - `*ConnManager.getConn` - `engine/connmanager.go` - `*ConnManager.getConnWithConfig` - `engine/libengine.go` - `NewRPCPool` - `engine/libengine.go` - `NewRPCConnection` - `agents/libagents.go` - `processRequest` Compilation errors related to the `rpcclient.NewRPCClient` function were resolved by adding the missing `context`, `max_reconnect_interval`, and `delayFunc` parameters. Additionally, context was added to all calls made by the client. An effort was made to avoid passing hardcoded values as much as possible, and extra flags were added where necessary for cgr binaries. The `max_reconnect_interval` parameter is now passed from parent functions, which required adjustments to the function signature. A new context field was added to all agent objects to ensure access to it before sending it to the `connmanager's Call`, effectively replacing `birpcclient`. Although an alternative would have been to create the new service and add it to the context right before passing it to the handlers, the chosen approach is definitely more comfortable. With the addition of a context field for the SIP servers agents, an additional error needed to be handled, coming from the creation of the service. Agent constructors within the services package log errors as they occur and return. Alternate solutions considered were either shutting down the engine instead of returning, or just logging the occurrence as a warning, particularly when the `ctx.Client` isn't required, especially in cases where bidirectional connections are not needed. For the latter option, it's crucial to return the object with the error rather than nil or to make the error nil immediately after logging. Context has been integrated into all internal Call implementations to ensure the objects conform to the `birpc.ClientConnector` interface. These implementations will be removed in the near future as all service objects are being wrapped in a `birpc.Service` type that satisfies the `birpc.ClientConnector` interface. Currently, they are being retained as a reference in case of any unexpected issues that arise. Ensured that the `birpc.Service` wrapped service objects are passed to the internal channel getters rather than the objects themselves. Add context.TODO() to all \*ConnManager.Call function calls. To be replaced with the context passed to the Method, when available. For all `*ConnManager.Call` function calls, `context.TODO()` has been added. This will be replaced with the context passed to the method when it becomes available. The value returned by StringGetOpts is now passed directly to the FirstNonEmpty function, instead of being assigned to a variable first. The implementation of the `*AnalyzerService.GetInternalBiRPCCodec` function has been removed from the services package. Additionally, the AnalyzerBiRPCConnector type definition and its associated methods have been removed. The codec implementation has been revised to include the following changes: - `rpc.ServerCodec` -> `birpc.ServerCodec`; - `rpc2.ServerCodec` -> `birpc.BirpcCodec`; - `rpc2.Request` -> `birpc.Request`; - `rpc2.Response` -> `birpc.Response`; - The constructors for json and gob birpc codecs in `cenkalti/rpc` have been replaced with ones from the `birpc/jsonrpc` library; - The gob codec implementation has been removed in favor of the version already implemented in the birpc external library. The server implementation has been updated with the following changes: - A field that represents a simple RPC server has been added to the Server struct; - Both the simple and bidirectional RPC servers are now initialized inside the Server constructor, eliminating the need for nil checks; - Usage of `net/rpc` and `cenkalti/rpc2` has been replaced with `cgrates/birpc`; - Additional `(Bi)RPCUnregisterName` methods have been added; - The implementations for (bi)json/gob servers have been somewhat simplified. Before deleting the Call functions and using the `birpc.NewService` method to register the methods for all cgrates components, update the Call functions to satisfy the `birpc.ClientConnector` interface. This way it will be a bit safer. Had to be done for SessionS though. The `BiRPCCall` method has been removed from coreutils.go. The `RPCCall` and `APIerRPCCall` methods are also to be removed in the future. Ensured that all methods for `SessionSv1` and `SessionS` have the correct function signature with context. The same adjustments were made for the session dispatcher methods and for the `SessionSv1Interface`. Also removed sessionsbirpc.go and smgbirpc.go files. Implemented the following methods to help with the registration of methods across all subsystems: - `NewServiceWithName`; - `NewDispatcherService` for all dispatcher methods; - `NewService` for the remaining methods that are already named correctly. Compared to the constructor from the external library, these also make sure that the naming of the methods is consistent with our constants. Added context to the Call methods for the mock client connectors (used in tests). Removed unused rpc fields from inside the following services: - EeS - LoaderS - ResourceS - RouteS - StatS - ThresholdS - SessionS - CoreS Updated the methods implementing the logic for API methods to align with the latest changes, ensuring consistency and correctness. The modifications include: - Adjusting the function signature to the new format (ctx, args, reply). - Prefixing names with 'V*' to indicate that they are utilized by or registered as APIs. - Containing the complete logic within the methods, enabling APIs to call them and return their reply directly. The subsystems affected by these changes are detailed as follows: - CoreS: Additional methods were implementing utilizing the existing ones. Though modifying them directly was possible, certain methods (e.g., StopCPUProfiling()) were used elsewhere and not as RPC requests. - CDRs: Renamed V1CountCDRs to V1GetCDRsCount. - StatS: V1GetQueueFloatMetrics, V1GetQueueStringMetrics, V1GetStatQueue accept different arguments compared to API functions (opted to register StatSv1 instead). - ResourceS: Renamed V1ResourcesForEvent to V1GetResourcesForEvent to align with API naming. - DispatcherS: Renamed V1GetProfilesForEvent to DispatcherSv1GetProfilesForEvent. - For the rest, adding context to the function signature was enough. In the unit tests, wrapping the object within a biprc.Service is now ensured before passing it to the internal connections map under the corresponding key. Some tests that are covering error cases, are also checking the other return value besides the error. That check has been removed since it is redundant. Revised the RPC/BiRPC clients' constructors (for use in tests) A different approach has been chosen for the handling of ping methods within subsystems. Instead of defining the same structure in every file, the ping methods were added inside the Service constructor function. Though the existing Ping methods were left as they were, they will be removed in the future. An additional method has been implemented to register the Ping method from outside of the engine package. Implemented Sleep and CapsError methods for SessionS (before they were exclusively for bidirectional use, I believe). A specific issue has been fixed within the CapsError SessionSv1 API implementation, which is designed to overwrite methods that cannot be allocated due to the threshold limit being reached. Previously, it was deallocating when writing the response, even when a spot hadn't been allocated in the first place (due to the cap being hit). The reason behind this, especially why the test was passing before, still needs to be looked into, as the problem should have occurred from before. Implement `*SessionSv1.RegisterInternalBiJSONConn` method in apier. All agent methods have been registered under the SessionSv1 name. For the correct method names, the leading "V1" prefix has been trimmed using the `birpc.NewServiceWithMethodsRename` function. Revise the RegisterRpcParams function to populate the parameters while relying on the `*birpc.Service` type instead. This will automatically also deal with the validation. At the moment, any error encountered is logged without being returned. Might be changed in the future. Inside the cgrRPCAction function, `mapstructure.Decode`'s output parameter is now guaranteed to always be a pointer. Updated go.mod and go.sum. Fixed some typos. --- agents/astagent.go | 104 +-- agents/astagent_test.go | 2 +- agents/diam_it_test.go | 29 +- agents/diamagent.go | 104 +-- agents/diamagent_test.go | 33 +- agents/dnsagent.go | 10 +- agents/dnsagent_it_test.go | 7 +- agents/fsagent.go | 105 +-- agents/fsagent_test.go | 2 +- agents/httpagent.go | 5 +- agents/httpagent_it_test.go | 13 +- agents/kamagent.go | 112 +-- agents/kamagent_test.go | 2 +- agents/lib_test.go | 8 +- agents/libagents.go | 22 +- agents/radagent.go | 15 +- agents/radagent_it_test.go | 13 +- agents/sipagent.go | 5 +- agents/sipagent_it_test.go | 7 +- analyzers/analyzers.go | 3 +- analyzers/analyzers_it_test.go | 51 +- analyzers/analyzers_test.go | 126 +-- analyzers/codec.go | 27 +- analyzers/codec_test.go | 62 +- analyzers/connector.go | 48 +- analyzers/connector_test.go | 76 +- apier/v1/accounts.go | 33 +- apier/v1/accounts_it_test.go | 167 ++-- apier/v1/accounts_test.go | 11 +- apier/v1/analyzer.go | 11 +- apier/v1/api_interfaces.go | 363 ++++---- apier/v1/apier.go | 110 +-- apier/v1/apier2_it_test.go | 85 +- apier/v1/apier_it_test.go | 435 +++++----- apier/v1/attributes.go | 25 +- apier/v1/attributes_it_test.go | 221 ++--- apier/v1/auth.go | 12 +- apier/v1/cache_replication_it_test.go | 13 +- apier/v1/caches.go | 75 +- apier/v1/caches_it_test.go | 61 +- apier/v1/caches_test.go | 19 +- apier/v1/caps_it_test.go | 23 +- apier/v1/cdrs.go | 37 +- apier/v1/cdrs_it_test.go | 57 +- apier/v1/chargers.go | 23 +- apier/v1/chargers_it_test.go | 81 +- apier/v1/config.go | 25 +- apier/v1/config_it_test.go | 43 +- apier/v1/core.go | 57 +- apier/v1/core_it_test.go | 25 +- apier/v1/costs.go | 17 +- apier/v1/costs_it_test.go | 9 +- apier/v1/debit.go | 24 +- apier/v1/debit_test.go | 9 +- apier/v1/dispatcher.go | 799 +++++++++--------- apier/v1/dispatcher_it_test.go | 79 +- apier/v1/dispatchersv1_it_test.go | 11 +- apier/v1/ees.go | 7 +- apier/v1/ees_it_test.go | 13 +- apier/v1/filter_indexes.go | 29 +- apier/v1/filter_indexes_health_it_test.go | 91 +- apier/v1/filter_indexes_it_test.go | 469 +++++----- apier/v1/filterindexecache_it_test.go | 189 ++--- apier/v1/filters.go | 9 +- apier/v1/filters_it_test.go | 35 +- apier/v1/filters_test.go | 44 +- apier/v1/full_remote_it_test.go | 87 +- apier/v1/guardian.go | 11 +- apier/v1/guardian_it_test.go | 7 +- apier/v1/lib_test.go | 8 +- apier/v1/libapier.go | 11 +- apier/v1/libapier_test.go | 9 +- apier/v1/loaders.go | 15 +- apier/v1/precache_it_test.go | 13 +- apier/v1/preload_it_test.go | 9 +- apier/v1/rals.go | 9 +- apier/v1/rating_profile_late_it_test.go | 18 +- apier/v1/remote_it_test.go | 119 +-- apier/v1/replicate_it_test.go | 281 +++--- apier/v1/replicator.go | 155 ++-- apier/v1/resourcesv1.go | 39 +- apier/v1/resourcesv1_it_test.go | 147 ++-- apier/v1/routes.go | 27 +- apier/v1/routes_it_test.go | 125 +-- apier/v1/scheduler.go | 3 +- apier/v1/schedulers.go | 13 +- apier/v1/schedulers_it_test.go | 35 +- apier/v1/servicemanager.go | 19 +- apier/v1/sessions.go | 118 +-- apier/v1/sessions_process_event_it_test.go | 59 +- apier/v1/sessions_thresholds_it_test.go | 59 +- apier/v1/sessionsbirpc.go | 213 ----- apier/v1/sessionsv1_it_test.go | 126 +-- apier/v1/smg.go | 21 +- apier/v1/smgbirpc.go | 72 -- apier/v1/stats.go | 43 +- apier/v1/stats_it_test.go | 209 ++--- apier/v1/thresholds.go | 37 +- apier/v1/thresholds_it_test.go | 141 ++-- apier/v1/timing.go | 7 +- apier/v1/timing_it_test.go | 13 +- apier/v1/tp.go | 11 +- apier/v1/tp_it_test.go | 11 +- apier/v1/tpaccountactions.go | 13 +- apier/v1/tpaccountactions_it_test.go | 27 +- apier/v1/tpactionplans.go | 9 +- apier/v1/tpactionplans_it_test.go | 23 +- apier/v1/tpactions.go | 9 +- apier/v1/tpactions_it_test.go | 23 +- apier/v1/tpactiontriggers.go | 9 +- apier/v1/tpactiontriggers_it_test.go | 23 +- apier/v1/tpattributes.go | 9 +- apier/v1/tpattributes_it_test.go | 23 +- apier/v1/tpchargers.go | 9 +- apier/v1/tpchargers_it_test.go | 23 +- apier/v1/tpdestinationrates.go | 9 +- apier/v1/tpdestinationrates_it_test.go | 21 +- apier/v1/tpdestinations.go | 9 +- apier/v1/tpdestinations_it_test.go | 23 +- apier/v1/tpdispatchers.go | 17 +- apier/v1/tpdispatchers_it_test.go | 23 +- apier/v1/tpfilters.go | 9 +- apier/v1/tpfilters_it_test.go | 23 +- apier/v1/tprates.go | 9 +- apier/v1/tprates_it_test.go | 23 +- apier/v1/tpratingplans.go | 9 +- apier/v1/tpratingplans_it_test.go | 23 +- apier/v1/tpratingprofiles.go | 13 +- apier/v1/tpratingprofiles_it_test.go | 27 +- apier/v1/tpresources.go | 9 +- apier/v1/tpresources_it_test.go | 21 +- apier/v1/tproutes.go | 9 +- apier/v1/tproutes_it_test.go | 23 +- apier/v1/tpsharedgroups.go | 9 +- apier/v1/tpsharedgroups_it_test.go | 23 +- apier/v1/tpstats.go | 9 +- apier/v1/tpstats_it_test.go | 21 +- apier/v1/tpthresholds.go | 9 +- apier/v1/tpthresholds_it_test.go | 23 +- apier/v1/tptimings.go | 9 +- apier/v1/tptimings_it_test.go | 23 +- apier/v1/triggers.go | 23 +- apier/v1/versions.go | 9 +- apier/v1/versions_it_test.go | 21 +- apier/v2/accounts.go | 11 +- apier/v2/accounts_it_test.go | 26 +- apier/v2/apier.go | 23 +- apier/v2/apierv2_it_test.go | 103 +-- apier/v2/attributes.go | 3 +- apier/v2/attributes_it_test.go | 18 +- apier/v2/cdrs.go | 13 +- apier/v2/cdrs_it_test.go | 145 ++-- apier/v2/cdrs_offline_it_test.go | 48 +- apier/v2/dispatcher.go | 9 +- apier/v2/lib_test.go | 8 +- apier/v2/tp_it_test.go | 24 +- apier/v2/tpdestinations.go | 7 +- cmd/cgr-console/cgr-console.go | 42 +- cmd/cgr-console/cgr-console_flags_test.go | 2 +- cmd/cgr-console/cgr-console_it_test.go | 16 +- cmd/cgr-engine/cgr-engine.go | 166 ++-- cmd/cgr-loader/cgr-loader_remove_it_test.go | 52 +- cmd/cgr-tester/cdr_repl/process_cdr.go | 7 +- cmd/cgr-tester/cgr-tester.go | 15 +- cmd/cgr-tester/sessions.go | 31 +- config/config.go | 15 +- config/config_it_test.go | 222 ++--- config/config_test.go | 214 ++--- console/account_actionplan_get_test.go | 6 +- console/account_remove_test.go | 6 +- console/account_set_test.go | 6 +- console/account_trigger_add_test.go | 6 +- console/account_trigger_remove_test.go | 6 +- console/account_trigger_reset_test.go | 6 +- console/account_trigger_set_test.go | 6 +- console/accounts_test.go | 6 +- console/action_execute_test.go | 6 +- console/actionplan_get_test.go | 6 +- console/actionplan_remove_test.go | 6 +- console/actionplan_set_test.go | 6 +- console/active_sessions_test.go | 6 +- console/attributes_for_event_test.go | 6 +- console/attributes_process_event_test.go | 6 +- console/attributes_profile_ids_test.go | 6 +- console/attributes_profile_rem_test.go | 6 +- console/attributes_profile_set_test.go | 6 +- console/attributes_profile_test.go | 6 +- console/balance_add_test.go | 6 +- console/balance_debit_test.go | 6 +- console/balance_remove_test.go | 6 +- console/balance_set_test.go | 6 +- console/cache_clear_test.go | 6 +- console/cache_group_item_id_test.go | 6 +- console/cache_has_group_test.go | 6 +- console/cache_has_item_test.go | 6 +- console/cache_item_expiry_time_test.go | 6 +- console/cache_item_ids_test.go | 6 +- console/cache_precache_status_test.go | 6 +- console/cache_reload_test.go | 6 +- console/cache_remove_group_test.go | 6 +- console/cache_remove_item_test.go | 6 +- console/cache_stats_test.go | 6 +- console/cdrs_test.go | 6 +- console/chargers_for_event_test.go | 6 +- console/chargers_process_event_test.go | 6 +- console/chargers_profile_ids_test.go | 6 +- console/chargers_profile_rem_test.go | 6 +- console/chargers_profile_set_test.go | 6 +- console/chargers_profile_test.go | 6 +- console/compute_actionplan_indexes_test.go | 4 +- console/compute_filter_indexes_test.go | 6 +- console/cost_details_test.go | 6 +- console/cost_test.go | 6 +- console/datacost_test.go | 6 +- console/datadb_versions_test.go | 4 +- console/debit_max_test.go | 6 +- console/debit_test.go | 6 +- console/destination_set_test.go | 6 +- console/destinations_test.go | 6 +- console/dispatchers_for_event_test.go | 6 +- console/dispatchers_host_ids_test.go | 6 +- console/dispatchers_host_rem_test.go | 6 +- console/dispatchers_host_set_test.go | 6 +- console/dispatchers_host_test.go | 6 +- console/dispatchers_profile_ids_test.go | 6 +- console/dispatchers_profile_rem_test.go | 6 +- console/dispatchers_profile_set_test.go | 6 +- console/dispatchers_profile_test.go | 6 +- console/filter_ids_test.go | 6 +- console/filter_indexes_remove_test.go | 6 +- console/filter_indexes_test.go | 6 +- console/filter_remove_test.go | 6 +- console/filter_set_test.go | 6 +- console/filter_test.go | 6 +- console/get_json_section_test.go | 6 +- console/import_tp_from_folder_test.go | 6 +- console/load_history_test.go | 6 +- console/load_ids_test.go | 4 +- console/load_times_test.go | 6 +- console/load_tp_from_folder_test.go | 6 +- console/load_tp_from_stordb_test.go | 6 +- console/loader_load_test.go | 6 +- console/loader_remove_test.go | 6 +- console/maxduration_test.go | 6 +- console/maxusage_test.go | 6 +- console/passive_sessions_test.go | 6 +- console/ping_test.go | 60 +- console/ratingplan_cost_test.go | 6 +- console/ratingprofile_ids_test.go | 6 +- console/ratingprofile_remove_test.go | 6 +- console/ratingprofile_set_test.go | 6 +- console/ratingprofile_test.go | 6 +- console/reload_config_test.go | 6 +- console/resources_allocate_test.go | 6 +- console/resources_authorize_test.go | 6 +- console/resources_for_event_test.go | 6 +- console/resources_profile_ids_test.go | 6 +- console/resources_profile_rem_test.go | 6 +- console/resources_profile_set_test.go | 6 +- console/resources_profiles_test.go | 6 +- console/resources_release_test.go | 6 +- console/resources_test.go | 6 +- console/routes_profile_ids_test.go | 6 +- console/routes_profile_remove_test.go | 6 +- console/routes_profile_set_test.go | 6 +- console/routes_profile_test.go | 6 +- console/routes_profiles_for_event_test.go | 6 +- console/routes_test.go | 6 +- console/scheduler_execute_test.go | 6 +- console/scheduler_queue_test.go | 6 +- console/scheduler_reload_test.go | 6 +- console/session_authorize_event_test.go | 6 +- console/session_force_disconnect_test.go | 6 +- console/session_initiate_test.go | 6 +- console/session_process_cdr_test.go | 6 +- console/session_process_message_test.go | 6 +- console/session_terminate_test.go | 6 +- console/session_update_test.go | 6 +- console/set_datadb_versions_test.go | 6 +- console/set_stordb_versions_test.go | 6 +- console/sharedgroup_test.go | 4 +- console/sleep_test.go | 6 +- console/stats_for_event_test.go | 6 +- console/stats_metrics_test.go | 6 +- console/stats_process_event_test.go | 6 +- console/stats_profile_ids_test.go | 6 +- console/stats_profile_rem_test.go | 6 +- console/stats_profile_set_test.go | 6 +- console/stats_profile_test.go | 6 +- console/status_test.go | 6 +- console/stordb_versions_test.go | 4 +- console/threshold_test.go | 6 +- console/thresholds_for_event_test.go | 6 +- console/thresholds_process_event_test.go | 6 +- console/thresholds_profile_ids_test.go | 6 +- console/thresholds_profile_remove_test.go | 6 +- console/thresholds_profile_set_test.go | 6 +- console/thresholds_profile_test.go | 6 +- console/trigger_remove_test.go | 11 +- console/trigger_set_test.go | 6 +- console/triggers_test.go | 6 +- cores/caps.go | 42 +- cores/caps_test.go | 84 +- cores/core.go | 54 +- cores/core_test.go | 5 +- cores/gob_codec.go | 87 -- cores/gob_codec_test.go | 146 ---- cores/server.go | 87 +- cores/server_it_test.go | 75 +- cores/server_test.go | 6 +- data/ansible/drone/main.yaml | 95 +-- dispatchers/attributes.go | 7 +- dispatchers/attributes_it_test.go | 71 +- dispatchers/attributes_test.go | 19 +- dispatchers/caches.go | 37 +- dispatchers/caches_it_test.go | 31 +- dispatchers/caches_test.go | 71 +- dispatchers/cdrs.go | 21 +- dispatchers/cdrs_it_test.go | 53 +- dispatchers/cdrs_test.go | 45 +- dispatchers/chargers.go | 7 +- dispatchers/chargers_it_test.go | 25 +- dispatchers/chargers_test.go | 15 +- dispatchers/config.go | 11 +- dispatchers/config_it_test.go | 3 +- dispatchers/config_test.go | 21 +- dispatchers/cores.go | 17 +- dispatchers/dispatchers.go | 17 +- dispatchers/dispatchers_it_test.go | 10 +- dispatchers/dispatchers_test.go | 88 +- dispatchers/ees.go | 5 +- dispatchers/ees_it_test.go | 25 +- dispatchers/guardian.go | 7 +- dispatchers/guardian_it_test.go | 9 +- dispatchers/guardian_test.go | 15 +- dispatchers/lib_test.go | 13 +- dispatchers/libdispatcher.go | 7 +- dispatchers/libdispatcher_test.go | 18 +- dispatchers/rals.go | 5 +- dispatchers/rals_it_test.go | 7 +- dispatchers/rals_test.go | 11 +- dispatchers/replicator.go | 151 ++-- dispatchers/replicator_it_test.go | 239 +++--- dispatchers/replicator_test.go | 429 +++++----- dispatchers/resources.go | 15 +- dispatchers/resources_it_test.go | 31 +- dispatchers/resources_test.go | 31 +- dispatchers/responder.go | 21 +- dispatchers/responder_it_test.go | 27 +- dispatchers/responder_test.go | 39 +- dispatchers/routes.go | 9 +- dispatchers/routes_it_test.go | 27 +- dispatchers/routes_test.go | 19 +- dispatchers/scheduler.go | 9 +- dispatchers/scheduler_it_test.go | 5 +- dispatchers/scheduler_test.go | 19 +- dispatchers/servicemanager.go | 9 +- dispatchers/servicemanager_test.go | 19 +- dispatchers/sessions.go | 47 +- dispatchers/sessions_it_test.go | 87 +- dispatchers/sessions_test.go | 93 +- dispatchers/stats.go | 13 +- dispatchers/stats_it_test.go | 37 +- dispatchers/stats_test.go | 27 +- dispatchers/thresholds.go | 11 +- dispatchers/thresholds_it_test.go | 29 +- dispatchers/thresholds_test.go | 23 +- ees/amqp_it_test.go | 8 +- ees/amqpv1_it_test.go | 9 +- ees/ees.go | 10 +- ees/ees_test.go | 30 +- ees/elastic_it_test.go | 15 +- ees/filecsv_it_test.go | 28 +- ees/filefwv_it_test.go | 8 +- ees/httppost_it_test.go | 14 +- ees/kafka_it_test.go | 9 +- ees/lib_test.go | 8 +- ees/poster_it_test.go | 3 +- ees/posterjsonmap_it_test.go | 14 +- ees/rpc.go | 3 +- ees/rpc_test.go | 12 +- ees/s3_it_test.go | 8 +- ees/sql_it_test.go | 10 +- ees/sqs_it_test.go | 8 +- ees/virtual_ee_it_test.go | 10 +- engine/account.go | 7 +- engine/account_test.go | 11 +- engine/action.go | 53 +- engine/actions_test.go | 112 +-- engine/attributes.go | 5 +- engine/attributes_test.go | 141 ++-- engine/caches.go | 48 +- engine/caches_test.go | 89 +- engine/cdrs.go | 60 +- engine/cdrs_test.go | 274 +++--- engine/chargers.go | 7 +- engine/chargers_test.go | 3 +- engine/connmanager.go | 68 +- engine/connmanager_test.go | 236 ++---- engine/datamanager.go | 56 +- engine/datamanager_test.go | 594 ++++++------- engine/destinations_test.go | 27 +- engine/dispatcherprfl.go | 24 +- engine/dispatcherprfl_test.go | 7 +- engine/dynamicdp.go | 7 +- engine/dynamicdp_test.go | 11 +- engine/filters.go | 9 +- engine/filters_test.go | 43 +- engine/lib_test.go | 8 +- engine/libengine.go | 236 +++++- engine/libengine_test.go | 105 ++- engine/libtest.go | 2 +- engine/remoterepl.go | 5 +- engine/resources.go | 17 +- engine/responder.go | 23 +- engine/responder_test.go | 102 +-- engine/routes.go | 29 +- engine/routes_test.go | 149 ++-- engine/stats.go | 21 +- engine/stats_test.go | 242 +++--- engine/thresholds.go | 11 +- engine/thresholds_test.go | 73 +- engine/tpreader.go | 13 +- engine/tpreader_test.go | 71 +- engine/z_actions2_it_test.go | 25 +- engine/z_actions_it_test.go | 129 +-- engine/z_attributes_test.go | 49 +- engine/z_chargers_test.go | 58 +- engine/z_loader_it_test.go | 12 +- engine/z_resources_test.go | 161 ++-- ers/amqpv1_it_test.go | 3 +- ers/ers.go | 15 +- ers/ers_it_test.go | 8 +- ers/ers_reload_it_test.go | 10 +- ers/filecsv_it_test.go | 26 +- ers/filefwv_it_test.go | 12 +- ers/filejson_it_test.go | 18 +- ers/filexml_it_test.go | 12 +- ers/flatstore_it_test.go | 18 +- ers/kafka_it_test.go | 3 +- ers/lib_test.go | 8 +- ers/partial_csv_it_test.go | 14 +- general_tests/a1_it_test.go | 41 +- general_tests/accounts_it_test.go | 35 +- .../accountswiththresholds_it_test.go | 23 +- general_tests/all_cfg_sect_rld_it_test.go | 209 ++--- .../attributes_filters_index_it_test.go | 27 +- general_tests/attributes_it_test.go | 75 +- general_tests/auth_test.go | 7 +- general_tests/broadcast_client_it_test.go | 17 +- .../cacherpl_filter_update_it_test.go | 33 +- general_tests/cacherpl_it_test.go | 59 +- general_tests/cdrs_exp_it_test.go | 10 +- general_tests/cdrs_internal_it_test.go | 11 +- general_tests/cdrs_it_test.go | 87 +- general_tests/cdrs_onlexp_it_test.go | 23 +- general_tests/cdrs_post_failover_it_test.go | 17 +- general_tests/cdrs_processevent_it_test.go | 63 +- general_tests/cgrloader_it_test.go | 7 +- general_tests/data_it_test.go | 61 +- general_tests/dest_management_it_test.go | 60 +- general_tests/destination_combined_it_test.go | 7 +- general_tests/dispatcher_opts_it_test.go | 69 +- general_tests/doubleremove_it_test.go | 45 +- general_tests/export_it_test.go | 23 +- general_tests/filtered_replication_it_test.go | 373 ++++---- general_tests/filters_it_test.go | 129 +-- general_tests/filters_test.go | 23 +- general_tests/fltr_sep_it_test.go | 15 +- general_tests/fraud_detection_it_test.go | 21 +- general_tests/gocs_it_test.go | 65 +- general_tests/lib_test.go | 10 +- general_tests/libengine_it_test.go | 14 +- general_tests/loader_nocontext_it_test.go | 23 +- .../loaders_internal_indexes_it_test.go | 11 +- general_tests/oldtutorial_it_test.go | 82 +- general_tests/poster_it_test.go | 27 +- general_tests/redis_cluster_it_test.go | 15 +- general_tests/redis_tls_it_test.go | 7 +- general_tests/rerate_cdrs_it_test.go | 29 +- general_tests/rerate_exp_it_test.go | 35 +- general_tests/resourcesv1_it_test.go | 15 +- general_tests/route_it_test.go | 71 +- general_tests/routes_cases_it_test.go | 99 +-- general_tests/rpccaching_it_test.go | 115 +-- general_tests/rpcclient_it_test.go | 77 +- general_tests/sentinel_it_test.go | 13 +- general_tests/session2_it_test.go | 27 +- general_tests/session3_it_test.go | 33 +- general_tests/session4_it_test.go | 13 +- .../session_graceful_shutdown_it_test.go | 21 +- general_tests/session_it_test.go | 17 +- .../session_money_rating_subject_it_test.go | 21 +- general_tests/session_nonereq_it_test.go | 9 +- .../session_refund_expired_it_test.go | 29 +- ...ion_replications_automaticdebit_it_test.go | 43 +- general_tests/session_rounding_it_test.go | 39 +- general_tests/session_rpl_prepaid_it_test.go | 19 +- general_tests/sessionpause_it_test.go | 23 +- general_tests/sessionrefund_it_test.go | 25 +- general_tests/sessionroutes_it_test.go | 31 +- general_tests/sessions_benchmark_it_test.go | 17 +- general_tests/sessions_concur_test.go | 627 +++++++------- general_tests/sessions_message_it_test.go | 17 +- general_tests/sessions_race_test.go | 97 +-- .../sessions_tnt_change_cdr_it_test.go | 23 +- general_tests/sessions_tnt_change_it_test.go | 23 +- general_tests/shared_client_lock_it_test.go | 11 +- general_tests/suretax_it_test.go | 15 +- general_tests/tls_it_test.go | 27 +- general_tests/tp_it_test.go | 73 +- general_tests/tut_smgeneric_it_test.go | 11 +- general_tests/tutorial2_calls_test.go | 46 +- general_tests/tutorial2_it_test.go | 47 +- general_tests/tutorial_calls_test.go | 59 +- general_tests/tutorial_it_test.go | 9 +- general_tests/twoengines_it_test.go | 37 +- go.mod | 4 +- go.sum | 9 +- loaders/lib_test.go | 35 +- loaders/loader_it_test.go | 19 +- loaders/loader_test.go | 40 +- loaders/loaders.go | 5 +- loaders/loaders_it_test.go | 76 +- registrarc/lib_test.go | 8 +- registrarc/libregistrarc_test.go | 7 +- registrarc/registrarc.go | 7 +- registrarc/registrarc_it_test.go | 8 +- registrarc/registrarc_test.go | 9 +- registrarc/registrarcrpc_it_test.go | 12 +- services/analyzers.go | 35 +- services/analyzers_it_test.go | 20 +- services/analyzers_test.go | 8 +- services/apiers_it_test.go | 26 +- services/apiers_test.go | 22 +- services/apierv1.go | 40 +- services/apierv2.go | 39 +- services/asteriskagent.go | 12 +- services/asteriskagent_it_test.go | 80 +- services/asteriskagent_test.go | 16 +- services/attributes.go | 24 +- services/attributes_it_test.go | 19 +- services/attributes_test.go | 14 +- services/cdrs.go | 40 +- services/cdrs_it_test.go | 26 +- services/cdrs_test.go | 14 +- services/chargers.go | 23 +- services/chargers_it_test.go | 21 +- services/chargers_test.go | 17 +- services/cores.go | 26 +- services/cores_it_test.go | 19 +- services/cores_test.go | 12 +- services/datadb_it_test.go | 19 +- services/diameteragent.go | 16 +- services/diameteragent_it_test.go | 62 +- services/dispatchers.go | 218 +++-- services/dispatchers_it_test.go | 21 +- services/dispatchers_test.go | 15 +- services/dnsagent.go | 2 +- services/dnsagent_it_test.go | 53 +- services/dnsagent_test.go | 10 +- services/ees.go | 25 +- services/ees_it_test.go | 25 +- services/ees_test.go | 14 +- services/ers_it_test.go | 18 +- services/freeswitchagent.go | 15 +- services/freeswitchagent_it_test.go | 87 +- services/freeswitchagent_test.go | 10 +- services/httpagent_it_test.go | 28 +- services/httpagent_test.go | 4 +- services/kamailioagent.go | 17 +- services/kamailioagent_it_test.go | 35 +- services/kamailioagent_test.go | 10 +- services/loaders.go | 30 +- services/loaders_it_test.go | 24 +- services/loaders_test.go | 14 +- services/radiusagent_it_test.go | 55 +- services/radiusagent_test.go | 10 +- services/rals.go | 20 +- services/rals_it_test.go | 30 +- services/rals_test.go | 20 +- services/registrarc_it_test.go | 15 +- services/registrarc_test.go | 6 +- services/resources.go | 26 +- services/resources_it_test.go | 21 +- services/resources_test.go | 8 +- services/responders.go | 20 +- services/responders_it_test.go | 11 +- services/responders_test.go | 6 +- services/routes.go | 26 +- services/routes_it_test.go | 18 +- services/routes_test.go | 15 +- services/schedulers.go | 23 +- services/schedulers_it_test.go | 18 +- services/schedulers_test.go | 6 +- services/sessions.go | 52 +- services/sessions_it_test.go | 44 +- services/sessions_test.go | 18 +- services/sipagent_it_test.go | 49 +- services/sipagent_test.go | 10 +- services/stats.go | 25 +- services/stats_it_test.go | 21 +- services/stats_test.go | 8 +- services/stordb_it_test.go | 35 +- services/thresholds.go | 25 +- services/thresholds_it_test.go | 33 +- services/thresholds_test.go | 8 +- servmanager/servmanager.go | 9 +- sessions/lib_test.go | 10 +- sessions/libsessions.go | 23 +- sessions/sessions.go | 288 +++---- sessions/sessions_bench_test.go | 19 +- sessions/sessions_birpc_it_test.go | 50 +- sessions/sessions_data_it_test.go | 145 ++-- sessions/sessions_it_test.go | 49 +- sessions/sessions_rpl_it_test.go | 79 +- sessions/sessions_test.go | 136 +-- sessions/sessions_voice_it_test.go | 153 ++-- sessions/sessionscover_test.go | 465 +++++----- utils/birpcint_client.go | 13 +- utils/birpcint_client_test.go | 50 -- utils/consts.go | 35 +- utils/coreutils.go | 39 - utils/coreutils_test.go | 73 +- utils/rpc_params.go | 59 +- utils/rpc_params_test.go | 13 +- 626 files changed, 12030 insertions(+), 12199 deletions(-) delete mode 100644 apier/v1/sessionsbirpc.go delete mode 100644 apier/v1/smgbirpc.go delete mode 100644 cores/gob_codec.go delete mode 100644 cores/gob_codec_test.go delete mode 100644 utils/birpcint_client_test.go diff --git a/agents/astagent.go b/agents/astagent.go index e9ee08169..6c0664506 100644 --- a/agents/astagent.go +++ b/agents/astagent.go @@ -27,13 +27,13 @@ import ( "sync" "time" - "github.com/cenkalti/rpc2" "github.com/cgrates/aringo" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // constants used by AsteriskAgent @@ -57,14 +57,21 @@ const ( // NewAsteriskAgent constructs a new Asterisk Agent func NewAsteriskAgent(cgrCfg *config.CGRConfig, astConnIdx int, - connMgr *engine.ConnManager) *AsteriskAgent { + connMgr *engine.ConnManager) (*AsteriskAgent, error) { sma := &AsteriskAgent{ cgrCfg: cgrCfg, astConnIdx: astConnIdx, connMgr: connMgr, eventsCache: make(map[string]*utils.CGREvent), } - return sma + srv, err := birpc.NewServiceWithMethodsRename(sma, utils.SessionSv1, true, func(oldFn string) (newFn string) { + return strings.TrimPrefix(oldFn, "V1") + }) + if err != nil { + return nil, err + } + sma.ctx = context.WithClient(context.TODO(), srv) + return sma, nil } // AsteriskAgent used to cominicate with asterisk @@ -77,6 +84,7 @@ type AsteriskAgent struct { astErrChan chan error eventsCache map[string]*utils.CGREvent // used to gather information about events during various phases evCacheMux sync.RWMutex // Protect eventsCache + ctx *context.Context } func (sma *AsteriskAgent) connectAsterisk(stopChan <-chan struct{}) (err error) { @@ -86,7 +94,8 @@ func (sma *AsteriskAgent) connectAsterisk(stopChan <-chan struct{}) (err error) sma.astConn, err = aringo.NewARInGO(fmt.Sprintf("ws://%s/ari/events?api_key=%s:%s&app=%s", connCfg.Address, connCfg.User, connCfg.Password, CGRAuthAPP), "http://cgrates.org", connCfg.User, connCfg.Password, fmt.Sprintf("%s@%s", utils.CGRateS, utils.Version), - sma.astEvChan, sma.astErrChan, stopChan, connCfg.ConnectAttempts, connCfg.Reconnects, connCfg.MaxReconnectInterval, utils.FibDuration) + sma.astEvChan, sma.astErrChan, stopChan, connCfg.ConnectAttempts, connCfg.Reconnects, + connCfg.MaxReconnectInterval, utils.FibDuration) return } @@ -170,8 +179,9 @@ func (sma *AsteriskAgent) handleStasisStart(ev *SMAsteriskEvent) { return } var authReply sessions.V1AuthorizeReply - if err := sma.connMgr.Call(sma.cgrCfg.AsteriskAgentCfg().SessionSConns, sma, - utils.SessionSv1AuthorizeEvent, authArgs, &authReply); err != nil { + if err := sma.connMgr.Call(sma.ctx, sma.cgrCfg.AsteriskAgentCfg().SessionSConns, + utils.SessionSv1AuthorizeEvent, + authArgs, &authReply); err != nil { sma.hangupChannel(ev.ChannelID(), fmt.Sprintf("<%s> error: %s authorizing session for channelID: %s", utils.AsteriskAgent, err.Error(), ev.ChannelID())) @@ -263,7 +273,7 @@ func (sma *AsteriskAgent) handleChannelStateChange(ev *SMAsteriskEvent) { //initit Session var initReply sessions.V1InitSessionReply - if err := sma.connMgr.Call(sma.cgrCfg.AsteriskAgentCfg().SessionSConns, sma, + if err := sma.connMgr.Call(sma.ctx, sma.cgrCfg.AsteriskAgentCfg().SessionSConns, utils.SessionSv1InitiateSession, initSessionArgs, &initReply); err != nil { sma.hangupChannel(ev.ChannelID(), @@ -305,14 +315,14 @@ func (sma *AsteriskAgent) handleChannelDestroyed(ev *SMAsteriskEvent) { } var reply string - if err := sma.connMgr.Call(sma.cgrCfg.AsteriskAgentCfg().SessionSConns, sma, + if err := sma.connMgr.Call(sma.ctx, sma.cgrCfg.AsteriskAgentCfg().SessionSConns, utils.SessionSv1TerminateSession, tsArgs, &reply); err != nil { utils.Logger.Err(fmt.Sprintf("<%s> Error: %s when attempting to terminate session for channelID: %s", utils.AsteriskAgent, err.Error(), chID)) } if sma.cgrCfg.AsteriskAgentCfg().CreateCDR { - if err := sma.connMgr.Call(sma.cgrCfg.AsteriskAgentCfg().SessionSConns, sma, + if err := sma.connMgr.Call(sma.ctx, sma.cgrCfg.AsteriskAgentCfg().SessionSConns, utils.SessionSv1ProcessCDR, cgrEvDisp, &reply); err != nil { utils.Logger.Err(fmt.Sprintf("<%s> Error: %s when attempting to process CDR for channelID: %s", @@ -322,13 +332,13 @@ func (sma *AsteriskAgent) handleChannelDestroyed(ev *SMAsteriskEvent) { } -// Call implements rpcclient.ClientConnector interface -func (sma *AsteriskAgent) Call(serviceMethod string, args any, reply any) error { +// Call implements birpc.ClientConnector interface +func (sma *AsteriskAgent) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.RPCCall(sma, serviceMethod, args, reply) } // V1DisconnectSession is internal method to disconnect session in asterisk -func (sma *AsteriskAgent) V1DisconnectSession(args utils.AttrDisconnectSession, reply *string) error { +func (sma *AsteriskAgent) V1DisconnectSession(ctx *context.Context, args utils.AttrDisconnectSession, reply *string) error { channelID := engine.NewMapEvent(args.EventStart).GetStringIgnoreErrors(utils.OriginID) sma.hangupChannel(channelID, "") *reply = utils.OK @@ -336,7 +346,7 @@ func (sma *AsteriskAgent) V1DisconnectSession(args utils.AttrDisconnectSession, } // V1GetActiveSessionIDs is internal method to get all active sessions in asterisk -func (sma *AsteriskAgent) V1GetActiveSessionIDs(ignParam string, +func (sma *AsteriskAgent) V1GetActiveSessionIDs(ctx *context.Context, ignParam string, sessionIDs *[]*sessions.SessionID) error { var slMpIface []map[string]any // decode the result from ari into a slice of map[string]any if byts, err := sma.astConn.Call( @@ -364,76 +374,16 @@ func (sma *AsteriskAgent) V1GetActiveSessionIDs(ignParam string, } // V1ReAuthorize is used to implement the sessions.BiRPClient interface -func (*AsteriskAgent) V1ReAuthorize(originID string, reply *string) (err error) { +func (*AsteriskAgent) V1ReAuthorize(ctx *context.Context, originID string, reply *string) (err error) { return utils.ErrNotImplemented } // V1DisconnectPeer is used to implement the sessions.BiRPClient interface -func (*AsteriskAgent) V1DisconnectPeer(args *utils.DPRArgs, reply *string) (err error) { +func (*AsteriskAgent) V1DisconnectPeer(ctx *context.Context, args *utils.DPRArgs, reply *string) (err error) { return utils.ErrNotImplemented } // V1WarnDisconnect is used to implement the sessions.BiRPClient interface -func (sma *AsteriskAgent) V1WarnDisconnect(args map[string]any, reply *string) (err error) { +func (sma *AsteriskAgent) V1WarnDisconnect(ctx *context.Context, args map[string]any, reply *string) (err error) { return utils.ErrNotImplemented } - -// CallBiRPC is part of utils.BiRPCServer interface to help internal connections do calls over rpcclient.ClientConnector interface -func (sma *AsteriskAgent) CallBiRPC(clnt rpcclient.ClientConnector, serviceMethod string, args any, reply any) error { - return utils.BiRPCCall(sma, clnt, serviceMethod, args, reply) -} - -// BiRPCv1DisconnectSession is internal method to disconnect session in asterisk -func (sma *AsteriskAgent) BiRPCv1DisconnectSession(clnt rpcclient.ClientConnector, args utils.AttrDisconnectSession, reply *string) error { - return sma.V1DisconnectSession(args, reply) -} - -// BiRPCv1GetActiveSessionIDs is internal method to get all active sessions in asterisk -func (sma *AsteriskAgent) BiRPCv1GetActiveSessionIDs(clnt rpcclient.ClientConnector, ignParam string, sessionIDs *[]*sessions.SessionID) error { - return sma.V1GetActiveSessionIDs(ignParam, sessionIDs) - -} - -// BiRPCv1ReAuthorize is used to implement the sessions.BiRPClient interface -func (sma *AsteriskAgent) BiRPCv1ReAuthorize(clnt rpcclient.ClientConnector, originID string, reply *string) (err error) { - return sma.V1ReAuthorize(originID, reply) -} - -// BiRPCv1DisconnectPeer is used to implement the sessions.BiRPClient interface -func (sma *AsteriskAgent) BiRPCv1DisconnectPeer(clnt rpcclient.ClientConnector, args *utils.DPRArgs, reply *string) (err error) { - return sma.V1DisconnectPeer(args, reply) -} - -// BiRPCv1WarnDisconnect is used to implement the sessions.BiRPClient interface -func (sma *AsteriskAgent) BiRPCv1WarnDisconnect(clnt rpcclient.ClientConnector, args map[string]any, reply *string) (err error) { - return sma.V1WarnDisconnect(args, reply) -} - -// BiRPCv1CapsError is used to return error when the caps limit is hit -func (sma *AsteriskAgent) BiRPCv1CapsError(clnt rpcclient.ClientConnector, args any, reply *string) (err error) { - return utils.ErrMaxConcurrentRPCExceeded -} - -// Handlers is used to implement the rpcclient.BiRPCConector interface -func (sma *AsteriskAgent) Handlers() map[string]any { - return map[string]any{ - utils.SessionSv1DisconnectSession: func(clnt *rpc2.Client, args utils.AttrDisconnectSession, rply *string) error { - return sma.BiRPCv1DisconnectSession(clnt, args, rply) - }, - utils.SessionSv1GetActiveSessionIDs: func(clnt *rpc2.Client, args string, rply *[]*sessions.SessionID) error { - return sma.BiRPCv1GetActiveSessionIDs(clnt, args, rply) - }, - utils.SessionSv1ReAuthorize: func(clnt *rpc2.Client, args string, rply *string) (err error) { - return sma.BiRPCv1ReAuthorize(clnt, args, rply) - }, - utils.SessionSv1DisconnectPeer: func(clnt *rpc2.Client, args *utils.DPRArgs, rply *string) (err error) { - return sma.BiRPCv1DisconnectPeer(clnt, args, rply) - }, - utils.SessionSv1WarnDisconnect: func(clnt *rpc2.Client, args map[string]any, rply *string) (err error) { - return sma.BiRPCv1WarnDisconnect(clnt, args, rply) - }, - utils.SessionSv1CapsError: func(clnt *rpc2.Client, args any, rply *string) (err error) { - return sma.BiRPCv1CapsError(clnt, args, rply) - }, - } -} diff --git a/agents/astagent_test.go b/agents/astagent_test.go index 30017fe9e..813020ef0 100644 --- a/agents/astagent_test.go +++ b/agents/astagent_test.go @@ -24,5 +24,5 @@ import ( ) func TestAAsSessionSClientIface(t *testing.T) { - _ = sessions.BiRPClient(new(AsteriskAgent)) + _ = sessions.BiRPCClient(new(AsteriskAgent)) } diff --git a/agents/diam_it_test.go b/agents/diam_it_test.go index d6f368074..a3c8447c0 100644 --- a/agents/diam_it_test.go +++ b/agents/diam_it_test.go @@ -24,7 +24,6 @@ package agents import ( "flag" "fmt" - "net/rpc" "os/exec" "path" "strings" @@ -32,6 +31,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -48,7 +49,7 @@ var ( daCfgPath, diamConfigDIR string daCfg *config.CGRConfig - apierRpc *rpc.Client + apierRpc *birpc.Client diamClnt *DiameterClient rplyTimeout time.Duration @@ -282,7 +283,7 @@ func testDiamItApierRpcConn(t *testing.T) { func testDiamItTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} var loadInst utils.LoadInstance - if err := apierRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := apierRpc.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } if isDispatcherActive { @@ -929,7 +930,7 @@ func testDiamItCCRTerminate(t *testing.T) { time.Sleep(time.Duration(*waitRater) * time.Millisecond) var cdrs []*engine.CDR args := utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{utils.MetaRaw}}} - if err := apierRpc.Call(utils.CDRsV1GetCDRs, &args, &cdrs); err != nil { + if err := apierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -1014,7 +1015,7 @@ func testDiamItCCRSMS(t *testing.T) { var cdrs []*engine.CDR args := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{utils.MetaRaw}, ToRs: []string{utils.MetaSMS}}} - if err := apierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := apierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -1093,7 +1094,7 @@ func testDiamItCCRMMS(t *testing.T) { var cdrs []*engine.CDR args := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{utils.MetaRaw}, ToRs: []string{utils.MetaMMS}}} - if err := apierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := apierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -1113,7 +1114,7 @@ func testDiamInitWithSessionDisconnect(t *testing.T) { }, } var reply string - if err := apierRpc.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := apierRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -1233,7 +1234,7 @@ func testDiamItRAR(t *testing.T) { wait.Add(1) go func() { var reply string - if err := apierRpc.Call(utils.SessionSv1ReAuthorize, &utils.SessionFilter{}, &reply); err != nil { + if err := apierRpc.Call(context.Background(), utils.SessionSv1ReAuthorize, &utils.SessionFilter{}, &reply); err != nil { t.Error(err) } wait.Done() @@ -1344,7 +1345,7 @@ func testDiamItDRR(t *testing.T) { wait.Add(1) go func() { var reply string - if err := apierRpc.Call(utils.SessionSv1DisconnectPeer, &utils.DPRArgs{ + if err := apierRpc.Call(context.Background(), utils.SessionSv1DisconnectPeer, &utils.DPRArgs{ OriginHost: "INTEGRATION_TESTS", OriginRealm: "cgrates.org", DisconnectCause: 1, // BUSY @@ -1480,7 +1481,7 @@ func testDiamItEmulateTerminate(t *testing.T) { }, } - if err := apierRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := apierRpc.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1496,7 +1497,7 @@ func testDiamItEmulateTerminate(t *testing.T) { }, } - if err := apierRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile2, &result); err != nil { + if err := apierRpc.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1513,14 +1514,14 @@ func testDiamItEmulateTerminate(t *testing.T) { }, } var reply string - if err := apierRpc.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := apierRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.com", Account: "testDiamItEmulateTerminate"} - if err := apierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := apierRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != float64(time.Hour) { t.Errorf("Expected: %f, received: %f", float64(time.Hour), acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) @@ -1612,7 +1613,7 @@ func testDiamItEmulateTerminate(t *testing.T) { t.Errorf("expecting: %s, received: <%s>", eVal, val) } - if err := apierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := apierRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != float64(time.Hour) { t.Errorf("Expected: %f, received: %f", float64(time.Hour), acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) diff --git a/agents/diamagent.go b/agents/diamagent.go index 5c558602e..9ea2a2b87 100644 --- a/agents/diamagent.go +++ b/agents/diamagent.go @@ -26,12 +26,12 @@ import ( "sync" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" "github.com/fiorix/go-diameter/v4/diam" "github.com/fiorix/go-diameter/v4/diam/avp" "github.com/fiorix/go-diameter/v4/diam/datatype" @@ -57,6 +57,13 @@ func NewDiameterAgent(cgrCfg *config.CGRConfig, filterS *engine.FilterS, dpa: make(map[string]chan *diam.Message), peers: make(map[string]diam.Conn), } + srv, err := birpc.NewServiceWithMethodsRename(da, utils.SessionSv1, true, func(oldFn string) (newFn string) { + return strings.TrimPrefix(oldFn, "V1") + }) + if err != nil { + return nil, err + } + da.ctx = context.WithClient(context.TODO(), srv) dictsPath := cgrCfg.DiameterAgentCfg().DictionariesPath if len(dictsPath) != 0 { if err := loadDictionaries(dictsPath, utils.DiameterAgent); err != nil { @@ -94,6 +101,8 @@ type DiameterAgent struct { peers map[string]diam.Conn // peer index by OriginHost;OriginRealm dpa map[string]chan *diam.Message dpaLck sync.RWMutex + + ctx *context.Context } // ListenAndServe is called when DiameterAgent is started, usually from within cmd/cgr-engine @@ -268,16 +277,20 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) { for _, reqProcessor := range da.cgrCfg.DiameterAgentCfg().RequestProcessors { var lclProcessed bool lclProcessed, err = processRequest( + da.ctx, reqProcessor, NewAgentRequest( - diamDP, reqVars, cgrRplyNM, rply, opts, - reqProcessor.Tenant, da.cgrCfg.GeneralCfg().DefaultTenant, - utils.FirstNonEmpty(reqProcessor.Timezone, - da.cgrCfg.GeneralCfg().DefaultTimezone), + diamDP, reqVars, cgrRplyNM, rply, + opts, reqProcessor.Tenant, + da.cgrCfg.GeneralCfg().DefaultTenant, + utils.FirstNonEmpty( + reqProcessor.Timezone, + da.cgrCfg.GeneralCfg().DefaultTimezone, + ), da.filterS, nil), utils.DiameterAgent, da.connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, - da, da.filterS) + da.filterS) if lclProcessed { processed = lclProcessed } @@ -312,13 +325,13 @@ func (da *DiameterAgent) handleMessage(c diam.Conn, m *diam.Message) { writeOnConn(c, a) } -// Call implements rpcclient.ClientConnector interface -func (da *DiameterAgent) Call(serviceMethod string, args any, reply any) error { +// Call implements birpc.ClientConnector interface +func (da *DiameterAgent) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.RPCCall(da, serviceMethod, args, reply) } // V1DisconnectSession is part of the sessions.BiRPClient -func (da *DiameterAgent) V1DisconnectSession(args utils.AttrDisconnectSession, reply *string) (err error) { +func (da *DiameterAgent) V1DisconnectSession(ctx *context.Context, args utils.AttrDisconnectSession, reply *string) (err error) { ssID, has := args.EventStart[utils.OriginID] if !has { utils.Logger.Info( @@ -334,14 +347,14 @@ func (da *DiameterAgent) V1DisconnectSession(args utils.AttrDisconnectSession, r case utils.MetaASR: return da.sendASR(originID, reply) case utils.MetaRAR: - return da.V1ReAuthorize(originID, reply) + return da.V1ReAuthorize(ctx, originID, reply) default: return fmt.Errorf("Unsupported request type <%s>", da.cgrCfg.DiameterAgentCfg().ForcedDisconnect) } } // V1GetActiveSessionIDs is part of the sessions.BiRPClient -func (da *DiameterAgent) V1GetActiveSessionIDs(ignParam string, +func (da *DiameterAgent) V1GetActiveSessionIDs(ctx *context.Context, ignParam string, sessionIDs *[]*sessions.SessionID) error { return utils.ErrNotImplemented } @@ -383,7 +396,7 @@ func (da *DiameterAgent) sendASR(originID string, reply *string) (err error) { } // V1ReAuthorize sends a rar message to diameter client -func (da *DiameterAgent) V1ReAuthorize(originID string, reply *string) (err error) { +func (da *DiameterAgent) V1ReAuthorize(ctx *context.Context, originID string, reply *string) (err error) { if originID == "" { utils.Logger.Info( fmt.Sprintf("<%s> cannot send RAR, missing session ID", @@ -506,7 +519,7 @@ func (da *DiameterAgent) handleDPA(c diam.Conn, m *diam.Message) { } // V1DisconnectPeer sends a DPR meseage to diameter client -func (da *DiameterAgent) V1DisconnectPeer(args *utils.DPRArgs, reply *string) (err error) { +func (da *DiameterAgent) V1DisconnectPeer(ctx *context.Context, args *utils.DPRArgs, reply *string) (err error) { if args == nil { utils.Logger.Info( fmt.Sprintf("<%s> cannot send DPR, missing arrguments", @@ -566,67 +579,6 @@ func (da *DiameterAgent) V1DisconnectPeer(args *utils.DPRArgs, reply *string) (e } // V1WarnDisconnect is used to implement the sessions.BiRPClient interface -func (*DiameterAgent) V1WarnDisconnect(args map[string]any, reply *string) (err error) { +func (*DiameterAgent) V1WarnDisconnect(ctx *context.Context, args map[string]any, reply *string) (err error) { return utils.ErrNotImplemented } - -// CallBiRPC is part of utils.BiRPCServer interface to help internal connections do calls over rpcclient.ClientConnector interface -func (da *DiameterAgent) CallBiRPC(clnt rpcclient.ClientConnector, serviceMethod string, args any, reply any) error { - return utils.BiRPCCall(da, clnt, serviceMethod, args, reply) -} - -// BiRPCv1DisconnectSession is internal method to disconnect session in asterisk -func (da *DiameterAgent) BiRPCv1DisconnectSession(clnt rpcclient.ClientConnector, args utils.AttrDisconnectSession, reply *string) error { - return da.V1DisconnectSession(args, reply) -} - -// BiRPCv1GetActiveSessionIDs is internal method to get all active sessions in asterisk -func (da *DiameterAgent) BiRPCv1GetActiveSessionIDs(clnt rpcclient.ClientConnector, ignParam string, - sessionIDs *[]*sessions.SessionID) error { - return da.V1GetActiveSessionIDs(ignParam, sessionIDs) - -} - -// BiRPCv1ReAuthorize is used to implement the sessions.BiRPClient interface -func (da *DiameterAgent) BiRPCv1ReAuthorize(clnt rpcclient.ClientConnector, originID string, reply *string) (err error) { - return da.V1ReAuthorize(originID, reply) -} - -// BiRPCv1DisconnectPeer is used to implement the sessions.BiRPClient interface -func (da *DiameterAgent) BiRPCv1DisconnectPeer(clnt rpcclient.ClientConnector, args *utils.DPRArgs, reply *string) (err error) { - return da.V1DisconnectPeer(args, reply) -} - -// BiRPCv1WarnDisconnect is used to implement the sessions.BiRPClient interface -func (da *DiameterAgent) BiRPCv1WarnDisconnect(clnt rpcclient.ClientConnector, args map[string]any, reply *string) (err error) { - return da.V1WarnDisconnect(args, reply) -} - -// BiRPCv1CapsError is used to return error when the caps limit is hit -func (da *DiameterAgent) BiRPCv1CapsError(clnt rpcclient.ClientConnector, args any, reply *string) (err error) { - return utils.ErrMaxConcurrentRPCExceeded -} - -// Handlers is used to implement the rpcclient.BiRPCConector interface -func (da *DiameterAgent) Handlers() map[string]any { - return map[string]any{ - utils.SessionSv1DisconnectSession: func(clnt *rpc2.Client, args utils.AttrDisconnectSession, rply *string) error { - return da.BiRPCv1DisconnectSession(clnt, args, rply) - }, - utils.SessionSv1GetActiveSessionIDs: func(clnt *rpc2.Client, args string, rply *[]*sessions.SessionID) error { - return da.BiRPCv1GetActiveSessionIDs(clnt, args, rply) - }, - utils.SessionSv1ReAuthorize: func(clnt *rpc2.Client, args string, rply *string) (err error) { - return da.BiRPCv1ReAuthorize(clnt, args, rply) - }, - utils.SessionSv1DisconnectPeer: func(clnt *rpc2.Client, args *utils.DPRArgs, rply *string) (err error) { - return da.BiRPCv1DisconnectPeer(clnt, args, rply) - }, - utils.SessionSv1WarnDisconnect: func(clnt *rpc2.Client, args map[string]any, rply *string) (err error) { - return da.BiRPCv1WarnDisconnect(clnt, args, rply) - }, - utils.SessionSv1CapsError: func(clnt *rpc2.Client, args any, rply *string) (err error) { - return da.BiRPCv1CapsError(clnt, args, rply) - }, - } -} diff --git a/agents/diamagent_test.go b/agents/diamagent_test.go index 39fc2b7aa..cb5082567 100644 --- a/agents/diamagent_test.go +++ b/agents/diamagent_test.go @@ -22,6 +22,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -30,32 +32,20 @@ import ( ) func TestDAsSessionSClientIface(t *testing.T) { - _ = sessions.BiRPClient(new(DiameterAgent)) + _ = sessions.BiRPCClient(new(DiameterAgent)) } type testMockSessionConn struct { calls map[string]func(arg any, rply any) error } -func (s *testMockSessionConn) Call(method string, arg any, rply any) error { +func (s *testMockSessionConn) Call(_ *context.Context, method string, arg any, rply any) error { if call, has := s.calls[method]; has { return call(arg, rply) } return rpcclient.ErrUnsupporteServiceMethod } -func (s *testMockSessionConn) CallBiRPC(_ rpcclient.ClientConnector, method string, arg any, rply any) error { - return s.Call(method, arg, rply) -} - -func (s *testMockSessionConn) Handlers() (b map[string]any) { - b = make(map[string]any) - for n, f := range s.calls { - b[n] = f - } - return -} - func TestProcessRequest(t *testing.T) { data := engine.NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil) @@ -447,9 +437,9 @@ func TestProcessRequest(t *testing.T) { reqProcessor.Tenant, config.CgrConfig().GeneralCfg().DefaultTenant, config.CgrConfig().GeneralCfg().DefaultTimezone, filters, nil) - internalSessionSChan := make(chan rpcclient.ClientConnector, 1) + internalSessionSChan := make(chan birpc.ClientConnector, 1) internalSessionSChan <- sS - connMgr := engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(config.CgrConfig(), map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS): internalSessionSChan, utils.ConcatenatedKey(rpcclient.BiRPCInternal, utils.MetaSessionS): internalSessionSChan, }) @@ -458,7 +448,8 @@ func TestProcessRequest(t *testing.T) { filterS: filters, connMgr: connMgr, } - pr, err := processRequest(reqProcessor, agReq, utils.DiameterAgent, connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, da, da.filterS) + ctx := context.WithClient(context.Background(), da) + pr, err := processRequest(ctx, reqProcessor, agReq, utils.DiameterAgent, connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, da.filterS) if err != nil { t.Error(err) } else if !pr { @@ -475,7 +466,7 @@ func TestProcessRequest(t *testing.T) { reqProcessor.Tenant, config.CgrConfig().GeneralCfg().DefaultTenant, config.CgrConfig().GeneralCfg().DefaultTimezone, filters, nil) - pr, err = processRequest(reqProcessor, agReq, utils.DiameterAgent, connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, da, da.filterS) + pr, err = processRequest(ctx, reqProcessor, agReq, utils.DiameterAgent, connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, da.filterS) if err != nil { t.Error(err) } else if !pr { @@ -492,7 +483,7 @@ func TestProcessRequest(t *testing.T) { reqProcessor.Tenant, config.CgrConfig().GeneralCfg().DefaultTenant, config.CgrConfig().GeneralCfg().DefaultTimezone, filters, nil) - pr, err = processRequest(reqProcessor, agReq, utils.DiameterAgent, connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, da, da.filterS) + pr, err = processRequest(ctx, reqProcessor, agReq, utils.DiameterAgent, connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, da.filterS) if err != nil { t.Error(err) } else if !pr { @@ -515,7 +506,7 @@ func TestProcessRequest(t *testing.T) { reqProcessor.Tenant, config.CgrConfig().GeneralCfg().DefaultTenant, config.CgrConfig().GeneralCfg().DefaultTimezone, filters, nil) - pr, err = processRequest(reqProcessor, agReq, utils.DiameterAgent, connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, da, da.filterS) + pr, err = processRequest(ctx, reqProcessor, agReq, utils.DiameterAgent, connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, da.filterS) if err != nil { t.Error(err) } else if !pr { @@ -532,7 +523,7 @@ func TestProcessRequest(t *testing.T) { reqProcessor.Tenant, config.CgrConfig().GeneralCfg().DefaultTenant, config.CgrConfig().GeneralCfg().DefaultTimezone, filters, nil) - pr, err = processRequest(reqProcessor, agReq, utils.DiameterAgent, connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, da, da.filterS) + pr, err = processRequest(ctx, reqProcessor, agReq, utils.DiameterAgent, connMgr, da.cgrCfg.DiameterAgentCfg().SessionSConns, da.filterS) if err != nil { t.Error(err) } else if !pr { diff --git a/agents/dnsagent.go b/agents/dnsagent.go index 63c54055c..e1403260f 100644 --- a/agents/dnsagent.go +++ b/agents/dnsagent.go @@ -24,6 +24,7 @@ import ( "strings" "sync" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -168,17 +169,20 @@ func (da *DNSAgent) handleQuestion(dnsDP utils.DataProvider, rply *dns.Msg, q *d for _, reqProcessor := range da.cgrCfg.DNSAgentCfg().RequestProcessors { var lclProcessed bool if lclProcessed, err = processRequest( + context.TODO(), reqProcessor, NewAgentRequest( dnsDP, reqVars, cgrRplyNM, rplyNM, opts, reqProcessor.Tenant, da.cgrCfg.GeneralCfg().DefaultTenant, - utils.FirstNonEmpty(da.cgrCfg.DNSAgentCfg().Timezone, - da.cgrCfg.GeneralCfg().DefaultTimezone), + utils.FirstNonEmpty( + da.cgrCfg.DNSAgentCfg().Timezone, + da.cgrCfg.GeneralCfg().DefaultTimezone, + ), da.fltrS, nil), utils.DNSAgent, da.connMgr, da.cgrCfg.DNSAgentCfg().SessionSConns, - nil, da.fltrS); err != nil { + da.fltrS); err != nil { utils.Logger.Warning( fmt.Sprintf("<%s> error: %s processing message: %s from %s", utils.DNSAgent, err.Error(), dnsDP, rmtAddr)) diff --git a/agents/dnsagent_it_test.go b/agents/dnsagent_it_test.go index 97c985911..eb28ff6cf 100644 --- a/agents/dnsagent_it_test.go +++ b/agents/dnsagent_it_test.go @@ -23,11 +23,12 @@ package agents import ( "crypto/tls" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -44,7 +45,7 @@ var ( dnsCfgPath string dnsCfgDIR string dnsCfg *config.CGRConfig - dnsRPC *rpc.Client + dnsRPC *birpc.Client dnsClnt *dnsConns // so we can cache the connection sTestsDNS = []func(t *testing.T){ @@ -131,7 +132,7 @@ func testDNSitApierRpcConn(t *testing.T) { func testDNSitTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "dnsagent")} var loadInst utils.LoadInstance - if err := dnsRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := dnsRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } diff --git a/agents/fsagent.go b/agents/fsagent.go index 7585ebefe..37efecdb6 100644 --- a/agents/fsagent.go +++ b/agents/fsagent.go @@ -24,24 +24,32 @@ import ( "strings" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" "github.com/cgrates/fsock" - "github.com/cgrates/rpcclient" ) func NewFSsessions(fsAgentConfig *config.FsAgentCfg, - timezone string, connMgr *engine.ConnManager) (fsa *FSsessions) { - return &FSsessions{ + timezone string, connMgr *engine.ConnManager) (*FSsessions, error) { + fsa := &FSsessions{ cfg: fsAgentConfig, conns: make([]*fsock.FSock, len(fsAgentConfig.EventSocketConns)), senderPools: make([]*fsock.FSockPool, len(fsAgentConfig.EventSocketConns)), timezone: timezone, connMgr: connMgr, } + srv, err := birpc.NewServiceWithMethodsRename(fsa, utils.SessionSv1, true, func(oldFn string) (newFn string) { + return strings.TrimPrefix(oldFn, "V1") + }) + if err != nil { + return nil, err + } + fsa.ctx = context.WithClient(context.TODO(), srv) + return fsa, nil } // FSsessions is the freeswitch session manager @@ -53,6 +61,7 @@ type FSsessions struct { senderPools []*fsock.FSockPool // Keep sender pools here timezone string connMgr *engine.ConnManager + ctx *context.Context } func (fsa *FSsessions) createHandlers() map[string][]func(string, int) { @@ -148,7 +157,9 @@ func (fsa *FSsessions) onChannelPark(fsev FSEvent, connIdx int) { authArgs := fsev.V1AuthorizeArgs() authArgs.CGREvent.Event[FsConnID] = connIdx // Attach the connection ID var authReply sessions.V1AuthorizeReply - if err := fsa.connMgr.Call(fsa.cfg.SessionSConns, fsa, utils.SessionSv1AuthorizeEvent, authArgs, &authReply); err != nil { + if err := fsa.connMgr.Call(fsa.ctx, fsa.cfg.SessionSConns, + utils.SessionSv1AuthorizeEvent, + authArgs, &authReply); err != nil { utils.Logger.Err( fmt.Sprintf("<%s> Could not authorize event %s, error: %s", utils.FreeSWITCHAgent, fsev.GetUUID(), err.Error())) @@ -238,7 +249,8 @@ func (fsa *FSsessions) onChannelAnswer(fsev FSEvent, connIdx int) { initSessionArgs := fsev.V1InitSessionArgs() initSessionArgs.CGREvent.Event[FsConnID] = connIdx // Attach the connection ID so we can properly disconnect later var initReply sessions.V1InitSessionReply - if err := fsa.connMgr.Call(fsa.cfg.SessionSConns, fsa, utils.SessionSv1InitiateSession, + if err := fsa.connMgr.Call(fsa.ctx, fsa.cfg.SessionSConns, + utils.SessionSv1InitiateSession, initSessionArgs, &initReply); err != nil { utils.Logger.Err( fmt.Sprintf("<%s> could not process answer for event %s, error: %s", @@ -262,7 +274,8 @@ func (fsa *FSsessions) onChannelHangupComplete(fsev FSEvent, connIdx int) { if fsev[VarAnswerEpoch] != "0" { // call was answered terminateSessionArgs := fsev.V1TerminateSessionArgs() terminateSessionArgs.CGREvent.Event[FsConnID] = connIdx // Attach the connection ID in case we need to create a session and disconnect it - if err := fsa.connMgr.Call(fsa.cfg.SessionSConns, fsa, utils.SessionSv1TerminateSession, + if err := fsa.connMgr.Call(fsa.ctx, fsa.cfg.SessionSConns, + utils.SessionSv1TerminateSession, terminateSessionArgs, &reply); err != nil { utils.Logger.Err( fmt.Sprintf("<%s> Could not terminate session with event %s, error: %s", @@ -274,7 +287,8 @@ func (fsa *FSsessions) onChannelHangupComplete(fsev FSEvent, connIdx int) { if err != nil { return } - if err := fsa.connMgr.Call(fsa.cfg.SessionSConns, fsa, utils.SessionSv1ProcessCDR, + if err := fsa.connMgr.Call(fsa.ctx, fsa.cfg.SessionSConns, + utils.SessionSv1ProcessCDR, cgrEv, &reply); err != nil { utils.Logger.Err(fmt.Sprintf("<%s> Failed processing CGREvent: %s, error: <%s>", utils.FreeSWITCHAgent, utils.ToJSON(cgrEv), err.Error())) @@ -374,13 +388,13 @@ func (fsa *FSsessions) Shutdown() (err error) { return } -// Call implements rpcclient.ClientConnector interface -func (fsa *FSsessions) Call(serviceMethod string, args any, reply any) error { +// Call implements birpc.ClientConnector interface +func (fsa *FSsessions) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.RPCCall(fsa, serviceMethod, args, reply) } // V1DisconnectSession internal method to disconnect session in FreeSWITCH -func (fsa *FSsessions) V1DisconnectSession(args utils.AttrDisconnectSession, reply *string) (err error) { +func (fsa *FSsessions) V1DisconnectSession(ctx *context.Context, args utils.AttrDisconnectSession, reply *string) (err error) { ev := engine.NewMapEvent(args.EventStart) channelID := ev.GetStringIgnoreErrors(utils.OriginID) connIdx, err := ev.GetTInt64(FsConnID) @@ -405,7 +419,7 @@ func (fsa *FSsessions) V1DisconnectSession(args utils.AttrDisconnectSession, rep } // V1GetActiveSessionIDs used to return all active sessions -func (fsa *FSsessions) V1GetActiveSessionIDs(_ string, +func (fsa *FSsessions) V1GetActiveSessionIDs(ctx *context.Context, _ string, sessionIDs *[]*sessions.SessionID) (err error) { var sIDs []*sessions.SessionID for connIdx, senderPool := range fsa.senderPools { @@ -444,17 +458,17 @@ func (fsa *FSsessions) Reload() { } // V1ReAuthorize is used to implement the sessions.BiRPClient interface -func (*FSsessions) V1ReAuthorize(originID string, reply *string) (err error) { +func (*FSsessions) V1ReAuthorize(ctx *context.Context, originID string, reply *string) (err error) { return utils.ErrNotImplemented } // V1DisconnectPeer is used to implement the sessions.BiRPClient interface -func (*FSsessions) V1DisconnectPeer(args *utils.DPRArgs, reply *string) (err error) { +func (*FSsessions) V1DisconnectPeer(ctx *context.Context, args *utils.DPRArgs, reply *string) (err error) { return utils.ErrNotImplemented } // V1WarnDisconnect is called when call goes under the minimum duration threshold, so FreeSWITCH can play an announcement message -func (fsa *FSsessions) V1WarnDisconnect(args map[string]any, reply *string) (err error) { +func (fsa *FSsessions) V1WarnDisconnect(ctx *context.Context, args map[string]any, reply *string) (err error) { if fsa.cfg.LowBalanceAnnFile == utils.EmptyString { *reply = utils.OK return @@ -481,64 +495,3 @@ func (fsa *FSsessions) V1WarnDisconnect(args map[string]any, reply *string) (err *reply = utils.OK return } - -// CallBiRPC is part of utils.BiRPCServer interface to help internal connections do calls over rpcclient.ClientConnector interface -func (fsa *FSsessions) CallBiRPC(clnt rpcclient.ClientConnector, serviceMethod string, args any, reply any) error { - return utils.BiRPCCall(fsa, clnt, serviceMethod, args, reply) -} - -// BiRPCv1DisconnectSession is internal method to disconnect session in asterisk -func (fsa *FSsessions) BiRPCv1DisconnectSession(clnt rpcclient.ClientConnector, args utils.AttrDisconnectSession, reply *string) error { - return fsa.V1DisconnectSession(args, reply) -} - -// BiRPCv1GetActiveSessionIDs is internal method to get all active sessions in asterisk -func (fsa *FSsessions) BiRPCv1GetActiveSessionIDs(clnt rpcclient.ClientConnector, ignParam string, - sessionIDs *[]*sessions.SessionID) error { - return fsa.V1GetActiveSessionIDs(ignParam, sessionIDs) - -} - -// BiRPCv1ReAuthorize is used to implement the sessions.BiRPClient interface -func (fsa *FSsessions) BiRPCv1ReAuthorize(clnt rpcclient.ClientConnector, originID string, reply *string) (err error) { - return fsa.V1ReAuthorize(originID, reply) -} - -// BiRPCv1DisconnectPeer is used to implement the sessions.BiRPClient interface -func (fsa *FSsessions) BiRPCv1DisconnectPeer(clnt rpcclient.ClientConnector, args *utils.DPRArgs, reply *string) (err error) { - return fsa.V1DisconnectPeer(args, reply) -} - -// BiRPCv1WarnDisconnect is used to implement the sessions.BiRPClient interface -func (fsa *FSsessions) BiRPCv1WarnDisconnect(clnt rpcclient.ClientConnector, args map[string]any, reply *string) (err error) { - return fsa.V1WarnDisconnect(args, reply) -} - -// BiRPCv1CapsError is used to return error when the caps limit is hit -func (fsa *FSsessions) BiRPCv1CapsError(clnt rpcclient.ClientConnector, args any, reply *string) (err error) { - return utils.ErrMaxConcurrentRPCExceeded -} - -// Handlers is used to implement the rpcclient.BiRPCConector interface -func (fsa *FSsessions) Handlers() map[string]any { - return map[string]any{ - utils.SessionSv1DisconnectSession: func(clnt *rpc2.Client, args utils.AttrDisconnectSession, rply *string) error { - return fsa.BiRPCv1DisconnectSession(clnt, args, rply) - }, - utils.SessionSv1GetActiveSessionIDs: func(clnt *rpc2.Client, args string, rply *[]*sessions.SessionID) error { - return fsa.BiRPCv1GetActiveSessionIDs(clnt, args, rply) - }, - utils.SessionSv1ReAuthorize: func(clnt *rpc2.Client, args string, rply *string) (err error) { - return fsa.BiRPCv1ReAuthorize(clnt, args, rply) - }, - utils.SessionSv1DisconnectPeer: func(clnt *rpc2.Client, args *utils.DPRArgs, rply *string) (err error) { - return fsa.BiRPCv1DisconnectPeer(clnt, args, rply) - }, - utils.SessionSv1WarnDisconnect: func(clnt *rpc2.Client, args map[string]any, rply *string) (err error) { - return fsa.BiRPCv1WarnDisconnect(clnt, args, rply) - }, - utils.SessionSv1CapsError: func(clnt *rpc2.Client, args any, rply *string) (err error) { - return fsa.BiRPCv1CapsError(clnt, args, rply) - }, - } -} diff --git a/agents/fsagent_test.go b/agents/fsagent_test.go index 0be8df8b1..8214f5e39 100644 --- a/agents/fsagent_test.go +++ b/agents/fsagent_test.go @@ -24,5 +24,5 @@ import ( ) func TestFAsSessionSClientIface(t *testing.T) { - _ = sessions.BiRPClient(new(FSsessions)) + _ = sessions.BiRPCClient(new(FSsessions)) } diff --git a/agents/httpagent.go b/agents/httpagent.go index 0d4809b5a..15e88de06 100644 --- a/agents/httpagent.go +++ b/agents/httpagent.go @@ -22,6 +22,7 @@ import ( "fmt" "net/http" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -72,9 +73,9 @@ func (ha *HTTPAgent) ServeHTTP(w http.ResponseWriter, req *http.Request) { utils.FirstNonEmpty(reqProcessor.Timezone, config.CgrConfig().GeneralCfg().DefaultTimezone), ha.filterS, nil) - lclProcessed, err := processRequest(reqProcessor, agReq, + lclProcessed, err := processRequest(context.TODO(), reqProcessor, agReq, utils.HTTPAgent, ha.connMgr, ha.sessionConns, - nil, agReq.filterS) + agReq.filterS) if err != nil { utils.Logger.Warning( fmt.Sprintf("<%s> error: %s processing request: %s", diff --git a/agents/httpagent_it_test.go b/agents/httpagent_it_test.go index 65891a934..375736851 100644 --- a/agents/httpagent_it_test.go +++ b/agents/httpagent_it_test.go @@ -28,13 +28,14 @@ import ( "fmt" "io" "net/http" - "net/rpc" "os" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -44,7 +45,7 @@ var ( haCfgPath string haCfgDIR string haCfg *config.CGRConfig - haRPC *rpc.Client + haRPC *birpc.Client httpC *http.Client // so we can cache the connection err error isTls bool @@ -183,7 +184,7 @@ func testHAitApierRpcConn(t *testing.T) { func testHAitTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance - if err := haRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := haRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -232,7 +233,7 @@ func testHAitAuth1001(t *testing.T) { }, } var reply string - if err := haRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := haRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -293,7 +294,7 @@ func testHAitCDRmtcall(t *testing.T) { time.Sleep(50 * time.Millisecond) var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}} - if err := haRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := haRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -334,7 +335,7 @@ func testHAitCDRmtcall2(t *testing.T) { time.Sleep(50 * time.Millisecond) var cdrs []*engine.ExternalCDR fltr := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{"447700086788"}} - if err := haRPC.Call(utils.APIerSv2GetCDRs, &fltr, &cdrs); err != nil { + if err := haRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &fltr, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) diff --git a/agents/kamagent.go b/agents/kamagent.go index 49d0d1e44..c6ee74925 100644 --- a/agents/kamagent.go +++ b/agents/kamagent.go @@ -26,9 +26,9 @@ import ( "strings" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" - "github.com/cgrates/rpcclient" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/sessions" @@ -46,15 +46,22 @@ var ( ) func NewKamailioAgent(kaCfg *config.KamAgentCfg, - connMgr *engine.ConnManager, timezone string) (ka *KamailioAgent) { - ka = &KamailioAgent{ + connMgr *engine.ConnManager, timezone string) (*KamailioAgent, error) { + ka := &KamailioAgent{ cfg: kaCfg, connMgr: connMgr, timezone: timezone, conns: make([]*kamevapi.KamEvapi, len(kaCfg.EvapiConns)), activeSessionIDs: make(chan []*sessions.SessionID), } - return + srv, err := birpc.NewServiceWithMethodsRename(ka, utils.SessionSv1, true, func(oldFn string) (newFn string) { + return strings.TrimPrefix(oldFn, "V1") + }) + if err != nil { + return nil, err + } + ka.ctx = context.WithClient(context.TODO(), srv) + return ka, nil } type KamailioAgent struct { @@ -63,6 +70,7 @@ type KamailioAgent struct { timezone string conns []*kamevapi.KamEvapi activeSessionIDs chan []*sessions.SessionID + ctx *context.Context } func (self *KamailioAgent) Connect() (err error) { @@ -106,7 +114,7 @@ func (self *KamailioAgent) Shutdown() (err error) { return } -// rpcclient.ClientConnector interface +// birpc.ClientConnector interface func (ka *KamailioAgent) Call(serviceMethod string, args any, reply any) error { return utils.RPCCall(ka, serviceMethod, args, reply) } @@ -147,7 +155,9 @@ func (ka *KamailioAgent) onCgrAuth(evData []byte, connIdx int) { var authReply sessions.V1AuthorizeReply // take the error after calling SessionSv1.AuthorizeEvent // and send it as parameter to AsKamAuthReply - err = ka.connMgr.Call(ka.cfg.SessionSConns, ka, utils.SessionSv1AuthorizeEvent, authArgs, &authReply) + err = ka.connMgr.Call(ka.ctx, ka.cfg.SessionSConns, + utils.SessionSv1AuthorizeEvent, + authArgs, &authReply) if kar, err := kev.AsKamAuthReply(authArgs, &authReply, err); err != nil { utils.Logger.Err(fmt.Sprintf("<%s> failed building auth reply for event: %s, error: %s", utils.KamailioAgent, kev[utils.OriginID], err.Error())) @@ -187,7 +197,8 @@ func (ka *KamailioAgent) onCallStart(evData []byte, connIdx int) { initSessionArgs.CGREvent.Event[EvapiConnID] = connIdx // Attach the connection ID so we can properly disconnect later var initReply sessions.V1InitSessionReply - if err := ka.connMgr.Call(ka.cfg.SessionSConns, ka, utils.SessionSv1InitiateSession, + if err := ka.connMgr.Call(ka.ctx, ka.cfg.SessionSConns, + utils.SessionSv1InitiateSession, initSessionArgs, &initReply); err != nil { utils.Logger.Err( fmt.Sprintf("<%s> could not process answer for event %s, error: %s", @@ -227,7 +238,8 @@ func (ka *KamailioAgent) onCallEnd(evData []byte, connIdx int) { } var reply string tsArgs.CGREvent.Event[EvapiConnID] = connIdx // Attach the connection ID in case we need to create a session and disconnect it - if err := ka.connMgr.Call(ka.cfg.SessionSConns, ka, utils.SessionSv1TerminateSession, + if err := ka.connMgr.Call(ka.ctx, ka.cfg.SessionSConns, + utils.SessionSv1TerminateSession, tsArgs, &reply); err != nil { utils.Logger.Err( fmt.Sprintf("<%s> could not terminate session with event %s, error: %s", @@ -235,7 +247,8 @@ func (ka *KamailioAgent) onCallEnd(evData []byte, connIdx int) { // no return here since we want CDR anyhow } if ka.cfg.CreateCdr || strings.Index(kev[utils.CGRFlags], utils.MetaCDRs) != -1 { - if err := ka.connMgr.Call(ka.cfg.SessionSConns, ka, utils.SessionSv1ProcessCDR, + if err := ka.connMgr.Call(ka.ctx, ka.cfg.SessionSConns, + utils.SessionSv1ProcessCDR, tsArgs.CGREvent, &reply); err != nil { utils.Logger.Err(fmt.Sprintf("%s> failed processing CGREvent: %s, error: %s", utils.KamailioAgent, utils.ToJSON(tsArgs.CGREvent), err.Error())) @@ -312,7 +325,9 @@ func (ka *KamailioAgent) onCgrProcessMessage(evData []byte, connIdx int) { procEvArgs.CGREvent.Event[EvapiConnID] = connIdx // Attach the connection ID var processReply sessions.V1ProcessMessageReply - err = ka.connMgr.Call(ka.cfg.SessionSConns, ka, utils.SessionSv1ProcessMessage, procEvArgs, &processReply) + err = ka.connMgr.Call(ka.ctx, ka.cfg.SessionSConns, + utils.SessionSv1ProcessMessage, + procEvArgs, &processReply) // take the error after calling SessionSv1.ProcessMessage // and send it as parameter to AsKamProcessMessageReply if kar, err := kev.AsKamProcessMessageReply(procEvArgs, &processReply, err); err != nil { @@ -357,7 +372,9 @@ func (ka *KamailioAgent) onCgrProcessCDR(evData []byte, connIdx int) { procCDRArgs.Event[EvapiConnID] = connIdx // Attach the connection ID var processReply string - err = ka.connMgr.Call(ka.cfg.SessionSConns, ka, utils.SessionSv1ProcessCDR, procCDRArgs, &processReply) + err = ka.connMgr.Call(ka.ctx, ka.cfg.SessionSConns, + utils.SessionSv1ProcessCDR, + procCDRArgs, &processReply) // take the error after calling SessionSv1.ProcessCDR // and send it as parameter to AsKamProcessCDRReply if kar, err := kev.AsKamProcessCDRReply(procCDRArgs, &processReply, err); err != nil { @@ -378,7 +395,7 @@ func (self *KamailioAgent) disconnectSession(connIdx int, dscEv *KamSessionDisco } // Internal method to disconnect session in Kamailio -func (ka *KamailioAgent) V1DisconnectSession(args utils.AttrDisconnectSession, reply *string) (err error) { +func (ka *KamailioAgent) V1DisconnectSession(ctx *context.Context, args utils.AttrDisconnectSession, reply *string) (err error) { hEntry := utils.IfaceAsString(args.EventStart[KamHashEntry]) hID := utils.IfaceAsString(args.EventStart[KamHashID]) connIdxIface, has := args.EventStart[EvapiConnID] @@ -408,7 +425,7 @@ func (ka *KamailioAgent) V1DisconnectSession(args utils.AttrDisconnectSession, r } // V1GetActiveSessionIDs returns a list of CGRIDs based on active sessions from agent -func (ka *KamailioAgent) V1GetActiveSessionIDs(ignParam string, sessionIDs *[]*sessions.SessionID) (err error) { +func (ka *KamailioAgent) V1GetActiveSessionIDs(ctx *context.Context, ignParam string, sessionIDs *[]*sessions.SessionID) (err error) { kamEv := utils.ToJSON(map[string]string{utils.Event: CGR_DLG_LIST}) var sentDLG int for i, evapi := range ka.conns { @@ -445,77 +462,16 @@ func (ka *KamailioAgent) Reload() { } // V1ReAuthorize is used to implement the sessions.BiRPClient interface -func (*KamailioAgent) V1ReAuthorize(originID string, reply *string) (err error) { +func (*KamailioAgent) V1ReAuthorize(ctx *context.Context, originID string, reply *string) (err error) { return utils.ErrNotImplemented } // V1DisconnectPeer is used to implement the sessions.BiRPClient interface -func (*KamailioAgent) V1DisconnectPeer(args *utils.DPRArgs, reply *string) (err error) { +func (*KamailioAgent) V1DisconnectPeer(ctx *context.Context, args *utils.DPRArgs, reply *string) (err error) { return utils.ErrNotImplemented } // V1WarnDisconnect is used to implement the sessions.BiRPClient interface -func (*KamailioAgent) V1WarnDisconnect(args map[string]any, reply *string) (err error) { +func (*KamailioAgent) V1WarnDisconnect(ctx *context.Context, args map[string]any, reply *string) (err error) { return utils.ErrNotImplemented } - -// CallBiRPC is part of utils.BiRPCServer interface to help internal connections do calls over rpcclient.ClientConnector interface -func (ka *KamailioAgent) CallBiRPC(clnt rpcclient.ClientConnector, serviceMethod string, args any, reply any) error { - return utils.BiRPCCall(ka, clnt, serviceMethod, args, reply) -} - -// BiRPCv1DisconnectSession is internal method to disconnect session in asterisk -func (ka *KamailioAgent) BiRPCv1DisconnectSession(clnt rpcclient.ClientConnector, args utils.AttrDisconnectSession, reply *string) error { - return ka.V1DisconnectSession(args, reply) -} - -// BiRPCv1GetActiveSessionIDs is internal method to get all active sessions in asterisk -func (ka *KamailioAgent) BiRPCv1GetActiveSessionIDs(clnt rpcclient.ClientConnector, ignParam string, - sessionIDs *[]*sessions.SessionID) error { - return ka.V1GetActiveSessionIDs(ignParam, sessionIDs) - -} - -// BiRPCv1ReAuthorize is used to implement the sessions.BiRPClient interface -func (ka *KamailioAgent) BiRPCv1ReAuthorize(clnt rpcclient.ClientConnector, originID string, reply *string) (err error) { - return ka.V1ReAuthorize(originID, reply) -} - -// BiRPCv1DisconnectPeer is used to implement the sessions.BiRPClient interface -func (ka *KamailioAgent) BiRPCv1DisconnectPeer(clnt rpcclient.ClientConnector, args *utils.DPRArgs, reply *string) (err error) { - return ka.V1DisconnectPeer(args, reply) -} - -// BiRPCv1WarnDisconnect is used to implement the sessions.BiRPClient interface -func (ka *KamailioAgent) BiRPCv1WarnDisconnect(clnt rpcclient.ClientConnector, args map[string]any, reply *string) (err error) { - return ka.V1WarnDisconnect(args, reply) -} - -// BiRPCv1CapsError is used to return error when the caps limit is hit -func (ka *KamailioAgent) BiRPCv1CapsError(clnt rpcclient.ClientConnector, args any, reply *string) (err error) { - return utils.ErrMaxConcurrentRPCExceeded -} - -// Handlers is used to implement the rpcclient.BiRPCConector interface -func (ka *KamailioAgent) Handlers() map[string]any { - return map[string]any{ - utils.SessionSv1DisconnectSession: func(clnt *rpc2.Client, args utils.AttrDisconnectSession, rply *string) error { - return ka.BiRPCv1DisconnectSession(clnt, args, rply) - }, - utils.SessionSv1GetActiveSessionIDs: func(clnt *rpc2.Client, args string, rply *[]*sessions.SessionID) error { - return ka.BiRPCv1GetActiveSessionIDs(clnt, args, rply) - }, - utils.SessionSv1ReAuthorize: func(clnt *rpc2.Client, args string, rply *string) (err error) { - return ka.BiRPCv1ReAuthorize(clnt, args, rply) - }, - utils.SessionSv1DisconnectPeer: func(clnt *rpc2.Client, args *utils.DPRArgs, rply *string) (err error) { - return ka.BiRPCv1DisconnectPeer(clnt, args, rply) - }, - utils.SessionSv1WarnDisconnect: func(clnt *rpc2.Client, args map[string]any, rply *string) (err error) { - return ka.BiRPCv1WarnDisconnect(clnt, args, rply) - }, - utils.SessionSv1CapsError: func(clnt *rpc2.Client, args any, rply *string) (err error) { - return ka.BiRPCv1CapsError(clnt, args, rply) - }, - } -} diff --git a/agents/kamagent_test.go b/agents/kamagent_test.go index 96ac1fa24..18776dfd1 100644 --- a/agents/kamagent_test.go +++ b/agents/kamagent_test.go @@ -24,5 +24,5 @@ import ( ) func TestKAsSessionSClientIface(t *testing.T) { - _ = sessions.BiRPClient(new(KamailioAgent)) + _ = sessions.BiRPCClient(new(KamailioAgent)) } diff --git a/agents/lib_test.go b/agents/lib_test.go index 0f42e0ec2..296b0206a 100644 --- a/agents/lib_test.go +++ b/agents/lib_test.go @@ -21,9 +21,9 @@ package agents import ( "errors" "flag" - "net/rpc" - "net/rpc/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -35,12 +35,12 @@ var ( dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/agents/libagents.go b/agents/libagents.go index ff0f9ec5c..a34e55c23 100644 --- a/agents/libagents.go +++ b/agents/libagents.go @@ -22,16 +22,16 @@ import ( "fmt" "strings" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) -func processRequest(reqProcessor *config.RequestProcessor, agReq *AgentRequest, - agentName string, connMgr *engine.ConnManager, sessionsConns []string, - aConn rpcclient.BiRPCConector, filterS *engine.FilterS) (_ bool, err error) { +func processRequest(ctx *context.Context, reqProcessor *config.RequestProcessor, + agReq *AgentRequest, agentName string, connMgr *engine.ConnManager, + sessionsConns []string, filterS *engine.FilterS) (_ bool, err error) { if pass, err := filterS.Pass(agReq.Tenant, reqProcessor.Filters, agReq); err != nil || !pass { return pass, err @@ -91,7 +91,7 @@ func processRequest(reqProcessor *config.RequestProcessor, agReq *AgentRequest, reqProcessor.Flags.ParamValue(utils.MetaRoutesMaxCost), ) rply := new(sessions.V1AuthorizeReply) - err = connMgr.Call(sessionsConns, aConn, utils.SessionSv1AuthorizeEvent, + err = connMgr.Call(ctx, sessionsConns, utils.SessionSv1AuthorizeEvent, authArgs, rply) rply.SetMaxUsageNeeded(authArgs.GetMaxUsage) agReq.setCGRReply(rply, err) @@ -107,7 +107,7 @@ func processRequest(reqProcessor *config.RequestProcessor, agReq *AgentRequest, reqProcessor.Flags.Has(utils.MetaAccounts), cgrEv, reqProcessor.Flags.Has(utils.MetaFD)) rply := new(sessions.V1InitSessionReply) - err = connMgr.Call(sessionsConns, aConn, utils.SessionSv1InitiateSession, + err = connMgr.Call(ctx, sessionsConns, utils.SessionSv1InitiateSession, initArgs, rply) rply.SetMaxUsageNeeded(initArgs.InitSession) agReq.setCGRReply(rply, err) @@ -119,7 +119,7 @@ func processRequest(reqProcessor *config.RequestProcessor, agReq *AgentRequest, cgrEv, reqProcessor.Flags.Has(utils.MetaFD)) rply := new(sessions.V1UpdateSessionReply) rply.SetMaxUsageNeeded(updateArgs.UpdateSession) - err = connMgr.Call(sessionsConns, aConn, utils.SessionSv1UpdateSession, + err = connMgr.Call(ctx, sessionsConns, utils.SessionSv1UpdateSession, updateArgs, rply) agReq.setCGRReply(rply, err) case utils.MetaTerminate: @@ -132,7 +132,7 @@ func processRequest(reqProcessor *config.RequestProcessor, agReq *AgentRequest, reqProcessor.Flags.ParamsSlice(utils.MetaStats, utils.MetaIDs), cgrEv, reqProcessor.Flags.Has(utils.MetaFD)) var rply string - err = connMgr.Call(sessionsConns, aConn, utils.SessionSv1TerminateSession, + err = connMgr.Call(ctx, sessionsConns, utils.SessionSv1TerminateSession, terminateArgs, &rply) agReq.setCGRReply(nil, err) case utils.MetaMessage: @@ -153,7 +153,7 @@ func processRequest(reqProcessor *config.RequestProcessor, agReq *AgentRequest, reqProcessor.Flags.ParamValue(utils.MetaRoutesMaxCost), ) rply := new(sessions.V1ProcessMessageReply) - err = connMgr.Call(sessionsConns, aConn, utils.SessionSv1ProcessMessage, + err = connMgr.Call(ctx, sessionsConns, utils.SessionSv1ProcessMessage, msgArgs, rply) if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) { cgrEv.Event[utils.Usage] = 0 // avoid further debits @@ -169,7 +169,7 @@ func processRequest(reqProcessor *config.RequestProcessor, agReq *AgentRequest, CGREvent: cgrEv, } rply := new(sessions.V1ProcessEventReply) - err = connMgr.Call(sessionsConns, aConn, utils.SessionSv1ProcessEvent, + err = connMgr.Call(ctx, sessionsConns, utils.SessionSv1ProcessEvent, evArgs, rply) if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) { cgrEv.Event[utils.Usage] = 0 // avoid further debits @@ -183,7 +183,7 @@ func processRequest(reqProcessor *config.RequestProcessor, agReq *AgentRequest, if reqProcessor.Flags.GetBool(utils.MetaCDRs) && !reqProcessor.Flags.Has(utils.MetaDryRun) { var rplyCDRs string - if err = connMgr.Call(sessionsConns, aConn, utils.SessionSv1ProcessCDR, + if err = connMgr.Call(ctx, sessionsConns, utils.SessionSv1ProcessCDR, cgrEv, &rplyCDRs); err != nil { agReq.CGRReply.Map[utils.Error] = utils.NewLeafNode(err.Error()) } diff --git a/agents/radagent.go b/agents/radagent.go index 803f4b5c1..e01ab9cc3 100644 --- a/agents/radagent.go +++ b/agents/radagent.go @@ -21,6 +21,7 @@ package agents import ( "fmt" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -222,7 +223,7 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R reqProcessor.Flags.ParamValue(utils.MetaRoutesMaxCost), ) rply := new(sessions.V1AuthorizeReply) - err = ra.connMgr.Call(ra.cgrCfg.RadiusAgentCfg().SessionSConns, nil, utils.SessionSv1AuthorizeEvent, + err = ra.connMgr.Call(context.TODO(), ra.cgrCfg.RadiusAgentCfg().SessionSConns, utils.SessionSv1AuthorizeEvent, authArgs, rply) rply.SetMaxUsageNeeded(authArgs.GetMaxUsage) agReq.setCGRReply(rply, err) @@ -238,7 +239,7 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R reqProcessor.Flags.Has(utils.MetaAccounts), cgrEv, reqProcessor.Flags.Has(utils.MetaFD)) rply := new(sessions.V1InitSessionReply) - err = ra.connMgr.Call(ra.cgrCfg.RadiusAgentCfg().SessionSConns, nil, utils.SessionSv1InitiateSession, + err = ra.connMgr.Call(context.TODO(), ra.cgrCfg.RadiusAgentCfg().SessionSConns, utils.SessionSv1InitiateSession, initArgs, rply) rply.SetMaxUsageNeeded(initArgs.InitSession) agReq.setCGRReply(rply, err) @@ -249,7 +250,7 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R reqProcessor.Flags.Has(utils.MetaAccounts), cgrEv, reqProcessor.Flags.Has(utils.MetaFD)) rply := new(sessions.V1UpdateSessionReply) - err = ra.connMgr.Call(ra.cgrCfg.RadiusAgentCfg().SessionSConns, nil, utils.SessionSv1UpdateSession, + err = ra.connMgr.Call(context.TODO(), ra.cgrCfg.RadiusAgentCfg().SessionSConns, utils.SessionSv1UpdateSession, updateArgs, rply) rply.SetMaxUsageNeeded(updateArgs.UpdateSession) agReq.setCGRReply(rply, err) @@ -263,7 +264,7 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R reqProcessor.Flags.ParamsSlice(utils.MetaStats, utils.MetaIDs), cgrEv, reqProcessor.Flags.Has(utils.MetaFD)) var rply string - err = ra.connMgr.Call(ra.cgrCfg.RadiusAgentCfg().SessionSConns, nil, utils.SessionSv1TerminateSession, + err = ra.connMgr.Call(context.TODO(), ra.cgrCfg.RadiusAgentCfg().SessionSConns, utils.SessionSv1TerminateSession, terminateArgs, &rply) agReq.setCGRReply(nil, err) case utils.MetaMessage: @@ -283,7 +284,7 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R reqProcessor.Flags.ParamValue(utils.MetaRoutesMaxCost), ) rply := new(sessions.V1ProcessMessageReply) - err = ra.connMgr.Call(ra.cgrCfg.RadiusAgentCfg().SessionSConns, nil, utils.SessionSv1ProcessMessage, evArgs, rply) + err = ra.connMgr.Call(context.TODO(), ra.cgrCfg.RadiusAgentCfg().SessionSConns, utils.SessionSv1ProcessMessage, evArgs, rply) if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) { cgrEv.Event[utils.Usage] = 0 // avoid further debits } else if evArgs.Debit { @@ -298,7 +299,7 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R Paginator: cgrArgs, } rply := new(sessions.V1ProcessEventReply) - err = ra.connMgr.Call(ra.cgrCfg.RadiusAgentCfg().SessionSConns, nil, utils.SessionSv1ProcessEvent, + err = ra.connMgr.Call(context.TODO(), ra.cgrCfg.RadiusAgentCfg().SessionSConns, utils.SessionSv1ProcessEvent, evArgs, rply) if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) { cgrEv.Event[utils.Usage] = 0 // avoid further debits @@ -317,7 +318,7 @@ func (ra *RadiusAgent) processRequest(req *radigo.Packet, reqProcessor *config.R // separate request so we can capture the Terminate/Event also here if reqProcessor.Flags.GetBool(utils.MetaCDRs) { var rplyCDRs string - if err = ra.connMgr.Call(ra.cgrCfg.RadiusAgentCfg().SessionSConns, nil, utils.SessionSv1ProcessCDR, + if err = ra.connMgr.Call(context.TODO(), ra.cgrCfg.RadiusAgentCfg().SessionSConns, utils.SessionSv1ProcessCDR, cgrEv, &rplyCDRs); err != nil { agReq.CGRReply.Map[utils.Error] = utils.NewLeafNode(err.Error()) } diff --git a/agents/radagent_it_test.go b/agents/radagent_it_test.go index 32e774ad8..806efb3ec 100644 --- a/agents/radagent_it_test.go +++ b/agents/radagent_it_test.go @@ -23,13 +23,14 @@ package agents import ( "fmt" - "net/rpc" "os/exec" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -42,7 +43,7 @@ var ( raCfgPath string raCfg *config.CGRConfig raAuthClnt, raAcctClnt *radigo.Client - raRPC *rpc.Client + raRPC *birpc.Client sTestsRadius = []func(t *testing.T){ testRAitInitCfg, @@ -166,7 +167,7 @@ func testRAitApierRpcConn(t *testing.T) { func testRAitTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance - if err := raRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := raRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } if isDispatcherActive { @@ -643,7 +644,7 @@ func testRAitAcctStart(t *testing.T) { expUsage = 3 * time.Hour } var aSessions []*sessions.ExternalSession - if err := raRPC.Call(utils.SessionSv1GetActiveSessions, + if err := raRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -714,7 +715,7 @@ func testRAitAcctStop(t *testing.T) { } // Make sure the sessin was disconnected from SMG var aSessions []*sessions.ExternalSession - if err := raRPC.Call(utils.SessionSv1GetActiveSessions, + if err := raRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -726,7 +727,7 @@ func testRAitAcctStop(t *testing.T) { time.Sleep(150 * time.Millisecond) var cdrs []*engine.ExternalCDR args := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, DestinationPrefixes: []string{"1002"}} - if err := raRPC.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := raRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) diff --git a/agents/sipagent.go b/agents/sipagent.go index d83dee200..61c64fb5c 100644 --- a/agents/sipagent.go +++ b/agents/sipagent.go @@ -25,6 +25,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -435,7 +436,7 @@ func (sa *SIPAgent) processRequest(reqProcessor *config.RequestProcessor, reqProcessor.Flags.ParamValue(utils.MetaRoutesMaxCost), ) rply := new(sessions.V1AuthorizeReply) - err = sa.connMgr.Call(sa.cfg.SIPAgentCfg().SessionSConns, nil, utils.SessionSv1AuthorizeEvent, + err = sa.connMgr.Call(context.TODO(), sa.cfg.SIPAgentCfg().SessionSConns, utils.SessionSv1AuthorizeEvent, authArgs, rply) rply.SetMaxUsageNeeded(authArgs.GetMaxUsage) agReq.setCGRReply(rply, err) @@ -447,7 +448,7 @@ func (sa *SIPAgent) processRequest(reqProcessor *config.RequestProcessor, } rply := new(sessions.V1ProcessEventReply) - err = sa.connMgr.Call(sa.cfg.SIPAgentCfg().SessionSConns, nil, utils.SessionSv1ProcessEvent, + err = sa.connMgr.Call(context.TODO(), sa.cfg.SIPAgentCfg().SessionSConns, utils.SessionSv1ProcessEvent, evArgs, rply) if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) { cgrEv.Event[utils.Usage] = 0 // avoid further debits diff --git a/agents/sipagent_it_test.go b/agents/sipagent_it_test.go index cf54d7469..c3229b94c 100644 --- a/agents/sipagent_it_test.go +++ b/agents/sipagent_it_test.go @@ -23,11 +23,12 @@ package agents import ( "net" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ var ( saonfigDIR string saCfgPath string saCfg *config.CGRConfig - saRPC *rpc.Client + saRPC *birpc.Client saConn net.Conn sTestsSIP = []func(t *testing.T){ @@ -126,7 +127,7 @@ func testSAitApierRpcConn(t *testing.T) { func testSAitTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tut_sip_redirect")} var loadInst utils.LoadInstance - if err := saRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := saRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups diff --git a/analyzers/analyzers.go b/analyzers/analyzers.go index 456173525..0119ee32b 100644 --- a/analyzers/analyzers.go +++ b/analyzers/analyzers.go @@ -30,6 +30,7 @@ import ( "github.com/blevesearch/bleve" "github.com/blevesearch/bleve/search" "github.com/blevesearch/bleve/search/query" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -144,7 +145,7 @@ type QueryArgs struct { } // V1StringQuery returns a list of API that match the query -func (aS *AnalyzerService) V1StringQuery(args *QueryArgs, reply *[]map[string]any) error { +func (aS *AnalyzerService) V1StringQuery(ctx *context.Context, args *QueryArgs, reply *[]map[string]any) error { var q query.Query if args.HeaderFilters == utils.EmptyString { q = bleve.NewMatchAllQuery() diff --git a/analyzers/analyzers_it_test.go b/analyzers/analyzers_it_test.go index 64232c50c..973cf203b 100644 --- a/analyzers/analyzers_it_test.go +++ b/analyzers/analyzers_it_test.go @@ -24,9 +24,6 @@ package analyzers import ( "errors" "flag" - "net" - "net/rpc" - "net/rpc/jsonrpc" "os" "path" "reflect" @@ -34,8 +31,9 @@ import ( "testing" "time" - "github.com/cenkalti/rpc2" - jsonrpc2 "github.com/cenkalti/rpc2/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -45,8 +43,8 @@ import ( var ( anzCfgPath string anzCfg *config.CGRConfig - anzRPC *rpc.Client - anzBiRPC *rpc2.Client + anzRPC *birpc.Client + anzBiRPC *birpc.BirpcClient sTestsAlsPrf = []func(t *testing.T){ testAnalyzerSInitCfg, @@ -66,16 +64,16 @@ var ( var ( dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here") - waitRater = flag.Int("wait_rater", 100, "Number of miliseconds to wait for rater to start and cache") + waitRater = flag.Int("wait_rater", 500, "Number of miliseconds to wait for rater to start and cache") encoding = flag.String("rpc", utils.MetaJSON, "what encoding whould be uused for rpc comunication") ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } @@ -125,24 +123,24 @@ func testAnalyzerSStartEngine(t *testing.T) { // Connect rpc client to rater func testAnalyzerSRPCConn(t *testing.T) { - var err error + srv, err := birpc.NewService(new(smock), utils.SessionSv1, true) + if err != nil { + t.Fatal(err) + } anzRPC, err = newRPCClient(anzCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed if err != nil { t.Fatal(err) } - conn, err := net.Dial(utils.TCP, anzCfg.SessionSCfg().ListenBijson) + anzBiRPC, err = utils.NewBiJSONrpcClient(anzCfg.SessionSCfg().ListenBijson, srv) if err != nil { t.Fatal(err) } - anzBiRPC = rpc2.NewClientWithCodec(jsonrpc2.NewJSONCodec(conn)) - anzBiRPC.Handle(utils.SessionSv1DisconnectPeer, func(clnt *rpc2.Client, args any, rply *string) (err error) { return utils.ErrNotFound }) - go anzBiRPC.Run() } func testAnalyzerSLoadTarrifPlans(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := anzRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := anzRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -200,7 +198,7 @@ func testAnalyzerSChargerSv1ProcessEvent(t *testing.T) { }, } - if err := anzRPC.Call(utils.ChargerSv1ProcessEvent, cgrEv, &result2); err != nil { + if err := anzRPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, cgrEv, &result2); err != nil { t.Fatal(err) } sort.Slice(result2, func(i, j int) bool { @@ -216,7 +214,7 @@ func testAnalyzerSV1Search(t *testing.T) { // need to wait in order for the log gorutine to execute time.Sleep(10 * time.Millisecond) var result []map[string]any - if err := anzRPC.Call(utils.AnalyzerSv1StringQuery, &QueryArgs{HeaderFilters: `+RequestEncoding:\*internal +RequestMethod:AttributeSv1\.ProcessEvent`}, &result); err != nil { + if err := anzRPC.Call(context.Background(), utils.AnalyzerSv1StringQuery, &QueryArgs{HeaderFilters: `+RequestEncoding:\*internal +RequestMethod:AttributeSv1\.ProcessEvent`}, &result); err != nil { t.Error(err) } else if len(result) != 1 { t.Errorf("Unexpected result: %s", utils.ToJSON(result)) @@ -225,7 +223,7 @@ func testAnalyzerSV1Search(t *testing.T) { func testAnalyzerSV1Search2(t *testing.T) { var result []map[string]any - if err := anzRPC.Call(utils.AnalyzerSv1StringQuery, &QueryArgs{HeaderFilters: `+RequestEncoding:\*json +RequestMethod:ChargerSv1\.ProcessEvent`}, &result); err != nil { + if err := anzRPC.Call(context.Background(), utils.AnalyzerSv1StringQuery, &QueryArgs{HeaderFilters: `+RequestEncoding:\*json +RequestMethod:ChargerSv1\.ProcessEvent`}, &result); err != nil { t.Error(err) } else if len(result) != 1 { t.Errorf("Unexpected result: %s", utils.ToJSON(result)) @@ -234,7 +232,7 @@ func testAnalyzerSV1Search2(t *testing.T) { func testAnalyzerSV1SearchWithContentFilters(t *testing.T) { var result []map[string]any - if err := anzRPC.Call(utils.AnalyzerSv1StringQuery, &QueryArgs{ + if err := anzRPC.Call(context.Background(), utils.AnalyzerSv1StringQuery, &QueryArgs{ HeaderFilters: `+RequestEncoding:\*json`, ContentFilters: []string{"*string:~*req.Event.Account:1010"}, }, &result); err != nil { @@ -246,15 +244,15 @@ func testAnalyzerSV1SearchWithContentFilters(t *testing.T) { func testAnalyzerSV1BirPCSession(t *testing.T) { var rply string - anzBiRPC.Call(utils.SessionSv1STIRIdentity, + anzBiRPC.Call(context.Background(), utils.SessionSv1STIRIdentity, &sessions.V1STIRIdentityArgs{}, &rply) // only call to register the birpc - if err := anzRPC.Call(utils.SessionSv1DisconnectPeer, &utils.DPRArgs{}, &rply); err == nil || + if err := anzRPC.Call(context.Background(), utils.SessionSv1DisconnectPeer, &utils.DPRArgs{}, &rply); err == nil || err.Error() != utils.ErrPartiallyExecuted.Error() { t.Fatal(err) } time.Sleep(10 * time.Second) var result []map[string]any - if err := anzRPC.Call(utils.AnalyzerSv1StringQuery, &QueryArgs{HeaderFilters: `+RequestEncoding:\*birpc_json +RequestMethod:"SessionSv1.DisconnectPeer"`}, &result); err != nil { + if err := anzRPC.Call(context.Background(), utils.AnalyzerSv1StringQuery, &QueryArgs{HeaderFilters: `+RequestEncoding:\*birpc_json +RequestMethod:"SessionSv1.DisconnectPeer"`}, &result); err != nil { t.Error(err) } else if len(result) != 1 { t.Errorf("Unexpected result: %s", utils.ToJSON(result)) @@ -268,3 +266,10 @@ func testAnalyzerSKillEngine(t *testing.T) { t.Fatal(err) } } + +type smock struct{} + +func (*smock) DisconnectPeer(ctx *context.Context, + args *utils.AttrDisconnectSession, reply *string) error { + return utils.ErrNotFound +} diff --git a/analyzers/analyzers_test.go b/analyzers/analyzers_test.go index fabe493a6..463ef4bc0 100644 --- a/analyzers/analyzers_test.go +++ b/analyzers/analyzers_test.go @@ -29,6 +29,7 @@ import ( "github.com/blevesearch/bleve" "github.com/blevesearch/bleve/search" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -255,13 +256,19 @@ func TestAnalyzersV1Search(t *testing.T) { t.Fatal(err) } reply := []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: `"` + utils.CoreSv1Ping + `"`}, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: `"` + utils.CoreSv1Ping + `"`, + }, &reply); err != nil { t.Fatal(err) } else if len(reply) != 4 { t.Errorf("Expected 4 hits received: %v", len(reply)) } reply = []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: "RequestMethod:" + `"` + utils.CoreSv1Ping + `"`}, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestMethod:" + `"` + utils.CoreSv1Ping + `"`, + }, &reply); err != nil { t.Fatal(err) } else if len(reply) != 4 { t.Errorf("Expected 4 hits received: %v", len(reply)) @@ -280,57 +287,70 @@ func TestAnalyzersV1Search(t *testing.T) { "ReplyError": nil, }} reply = []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: utils.RequestDuration + ":>=" + strconv.FormatInt(int64(time.Hour), 10)}, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: utils.RequestDuration + ":>=" + strconv.FormatInt(int64(time.Hour), 10), + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) } reply = []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: utils.RequestStartTime + ":<=\"" + t1.Add(-23*time.Hour).UTC().Format(time.RFC3339) + "\""}, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: utils.RequestStartTime + ":<=\"" + t1.Add(-23*time.Hour).UTC().Format(time.RFC3339) + "\"", + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) } reply = []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: "RequestEncoding:*gob"}, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestEncoding:*gob", + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) } reply = []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{ - HeaderFilters: "RequestEncoding:*gob", - ContentFilters: []string{"*string:~*rep:Pong"}, - }, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestEncoding:*gob", + ContentFilters: []string{"*string:~*rep:Pong"}, + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) } reply = []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{ - HeaderFilters: "RequestEncoding:*gob", - ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*attributes"}, - }, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestEncoding:*gob", + ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*attributes"}, + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) } reply = []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{ - HeaderFilters: "RequestEncoding:*gob", - ContentFilters: []string{"*gt:~*hdr.RequestDuration:1m"}, - }, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestEncoding:*gob", + ContentFilters: []string{"*gt:~*hdr.RequestDuration:1m"}, + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) } reply = []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{ - HeaderFilters: "RequestEncoding:*gob", - ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*attributes"}, - }, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestEncoding:*gob", + ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*attributes"}, + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) @@ -348,9 +368,10 @@ func TestAnalyzersV1Search(t *testing.T) { "ReplyError": nil, }} reply = []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{ - ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*ees"}, - }, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*ees"}, + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) @@ -358,35 +379,39 @@ func TestAnalyzersV1Search(t *testing.T) { expRply = []map[string]any{} reply = []map[string]any{} - if err = anz.V1StringQuery(&QueryArgs{ - HeaderFilters: "RequestEncoding:*gob", - ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*cdrs"}, - }, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestEncoding:*gob", + ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*cdrs"}, + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) } - if err = anz.V1StringQuery(&QueryArgs{ - HeaderFilters: "RequestEncoding:*gob", - ContentFilters: []string{"*notstring:~*req.APIOpts.EventSource:*attributes"}, - }, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestEncoding:*gob", + ContentFilters: []string{"*notstring:~*req.APIOpts.EventSource:*attributes"}, + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) } - if err = anz.V1StringQuery(&QueryArgs{ - ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*sessions"}, - }, &reply); err != nil { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + ContentFilters: []string{"*string:~*req.APIOpts.EventSource:*sessions"}, + }, &reply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(expRply, reply) { t.Errorf("Expected %s received: %s", utils.ToJSON(expRply), utils.ToJSON(reply)) } expErr := utils.ErrPrefixNotErrNotImplemented("*type") - if err = anz.V1StringQuery(&QueryArgs{ - HeaderFilters: "RequestEncoding:*gob", - ContentFilters: []string{"*type:~*opts.EventSource:*cdrs"}, - }, &reply); err == nil || err.Error() != expErr.Error() { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestEncoding:*gob", + ContentFilters: []string{"*type:~*opts.EventSource:*cdrs"}, + }, &reply); err == nil || err.Error() != expErr.Error() { t.Errorf("Expected error: %s,received:%v", expErr, err) } @@ -405,10 +430,11 @@ func TestAnalyzersV1Search(t *testing.T) { } expErr = new(json.SyntaxError) - if err = anz.V1StringQuery(&QueryArgs{ - HeaderFilters: "RequestMethod:" + utils.AttributeSv1Ping, - ContentFilters: []string{"*type:~*opts.EventSource:*cdrs"}, - }, &reply); err == nil || err.Error() != expErr.Error() { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestMethod:" + utils.AttributeSv1Ping, + ContentFilters: []string{"*type:~*opts.EventSource:*cdrs"}, + }, &reply); err == nil || err.Error() != expErr.Error() { t.Errorf("Expected error: %s,received:%v", expErr, err) } if err = anz.db.Index(utils.ConcatenatedKey(utils.AttributeSv1Ping, strconv.FormatInt(sTime.Unix(), 10)), @@ -423,17 +449,21 @@ func TestAnalyzersV1Search(t *testing.T) { }); err != nil { t.Fatal(err) } - if err = anz.V1StringQuery(&QueryArgs{ - HeaderFilters: "RequestMethod:" + utils.AttributeSv1Ping, - ContentFilters: []string{"*type:~*opts.EventSource:*cdrs"}, - }, &reply); err == nil || err.Error() != expErr.Error() { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestMethod:" + utils.AttributeSv1Ping, + ContentFilters: []string{"*type:~*opts.EventSource:*cdrs"}, + }, &reply); err == nil || err.Error() != expErr.Error() { t.Errorf("Expected error: %s,received:%v", expErr, err) } if err = anz.db.Close(); err != nil { t.Fatal(err) } - if err = anz.V1StringQuery(&QueryArgs{HeaderFilters: "RequestEncoding:*gob"}, &reply); err != bleve.ErrorIndexClosed { + if err = anz.V1StringQuery(context.Background(), + &QueryArgs{ + HeaderFilters: "RequestEncoding:*gob", + }, &reply); err != bleve.ErrorIndexClosed { t.Errorf("Expected error: %v,received: %+v", bleve.ErrorIndexClosed, err) } if err := os.RemoveAll(cfg.AnalyzerSCfg().DBPath); err != nil { diff --git a/analyzers/codec.go b/analyzers/codec.go index b9caf1f7d..50f6513a0 100644 --- a/analyzers/codec.go +++ b/analyzers/codec.go @@ -19,14 +19,13 @@ along with this program. If not, see package analyzers import ( - "net/rpc" "sync" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" ) -func NewAnalyzerServerCodec(sc rpc.ServerCodec, aS *AnalyzerService, enc, from, to string) rpc.ServerCodec { +func NewAnalyzerServerCodec(sc birpc.ServerCodec, aS *AnalyzerService, enc, from, to string) birpc.ServerCodec { return &AnalyzerServerCodec{ sc: sc, reqs: make(map[uint64]*rpcAPI), @@ -38,7 +37,7 @@ func NewAnalyzerServerCodec(sc rpc.ServerCodec, aS *AnalyzerService, enc, from, } type AnalyzerServerCodec struct { - sc rpc.ServerCodec + sc birpc.ServerCodec // keep the API in memory because the write is async reqs map[uint64]*rpcAPI @@ -50,7 +49,7 @@ type AnalyzerServerCodec struct { to string } -func (c *AnalyzerServerCodec) ReadRequestHeader(r *rpc.Request) (err error) { +func (c *AnalyzerServerCodec) ReadRequestHeader(r *birpc.Request) (err error) { err = c.sc.ReadRequestHeader(r) c.reqsLk.Lock() c.reqIdx = r.Seq @@ -71,7 +70,7 @@ func (c *AnalyzerServerCodec) ReadRequestBody(x any) (err error) { return } -func (c *AnalyzerServerCodec) WriteResponse(r *rpc.Response, x any) error { +func (c *AnalyzerServerCodec) WriteResponse(r *birpc.Response, x any) error { c.reqsLk.Lock() api := c.reqs[r.Seq] delete(c.reqs, r.Seq) @@ -82,7 +81,7 @@ func (c *AnalyzerServerCodec) WriteResponse(r *rpc.Response, x any) error { func (c *AnalyzerServerCodec) Close() error { return c.sc.Close() } -func NewAnalyzerBiRPCCodec(sc rpc2.Codec, aS *AnalyzerService, enc, from, to string) rpc2.Codec { +func NewAnalyzerBiRPCCodec(sc birpc.BirpcCodec, aS *AnalyzerService, enc, from, to string) birpc.BirpcCodec { return &AnalyzerBiRPCCodec{ sc: sc, reqs: make(map[uint64]*rpcAPI), @@ -95,7 +94,7 @@ func NewAnalyzerBiRPCCodec(sc rpc2.Codec, aS *AnalyzerService, enc, from, to str } type AnalyzerBiRPCCodec struct { - sc rpc2.Codec + sc birpc.BirpcCodec // keep the API in memory because the write is async reqs map[uint64]*rpcAPI @@ -113,14 +112,14 @@ type AnalyzerBiRPCCodec struct { // ReadHeader must read a message and populate either the request // or the response by inspecting the incoming message. -func (c *AnalyzerBiRPCCodec) ReadHeader(req *rpc2.Request, resp *rpc2.Response) (err error) { +func (c *AnalyzerBiRPCCodec) ReadHeader(req *birpc.Request, resp *birpc.Response) (err error) { err = c.sc.ReadHeader(req, resp) - if req.Method != "" { + if req.ServiceMethod != "" { c.reqsLk.Lock() c.reqIdx = req.Seq c.reqs[c.reqIdx] = &rpcAPI{ ID: req.Seq, - Method: req.Method, + Method: req.ServiceMethod, StartTime: time.Now(), } c.reqsLk.Unlock() @@ -154,12 +153,12 @@ func (c *AnalyzerBiRPCCodec) ReadResponseBody(x any) (err error) { } // WriteRequest must be safe for concurrent use by multiple goroutines. -func (c *AnalyzerBiRPCCodec) WriteRequest(req *rpc2.Request, x any) error { +func (c *AnalyzerBiRPCCodec) WriteRequest(req *birpc.Request, x any) error { c.repsLk.Lock() c.repIdx = req.Seq c.reps[c.repIdx] = &rpcAPI{ ID: req.Seq, - Method: req.Method, + Method: req.ServiceMethod, StartTime: time.Now(), } c.repsLk.Unlock() @@ -167,7 +166,7 @@ func (c *AnalyzerBiRPCCodec) WriteRequest(req *rpc2.Request, x any) error { } // WriteResponse must be safe for concurrent use by multiple goroutines. -func (c *AnalyzerBiRPCCodec) WriteResponse(r *rpc2.Response, x any) error { +func (c *AnalyzerBiRPCCodec) WriteResponse(r *birpc.Response, x any) error { c.reqsLk.Lock() api := c.reqs[r.Seq] delete(c.reqs, r.Seq) diff --git a/analyzers/codec_test.go b/analyzers/codec_test.go index 478b2aa81..fef50a59b 100644 --- a/analyzers/codec_test.go +++ b/analyzers/codec_test.go @@ -19,14 +19,13 @@ along with this program. If not, see package analyzers import ( - "net/rpc" "os" "reflect" "runtime" "testing" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/rpcclient" @@ -34,7 +33,7 @@ import ( type mockServerCodec struct{} -func (c *mockServerCodec) ReadRequestHeader(r *rpc.Request) (err error) { +func (c *mockServerCodec) ReadRequestHeader(r *birpc.Request) (err error) { r.Seq = 0 r.ServiceMethod = utils.CoreSv1Ping return @@ -43,7 +42,7 @@ func (c *mockServerCodec) ReadRequestHeader(r *rpc.Request) (err error) { func (c *mockServerCodec) ReadRequestBody(x any) (err error) { return } -func (c *mockServerCodec) WriteResponse(r *rpc.Response, x any) error { +func (c *mockServerCodec) WriteResponse(r *birpc.Response, x any) error { return nil } func (c *mockServerCodec) Close() error { return nil } @@ -64,8 +63,8 @@ func TestNewServerCodec(t *testing.T) { } codec := NewAnalyzerServerCodec(new(mockServerCodec), anz, utils.MetaJSON, "127.0.0.1:5565", "127.0.0.1:2012") - r := new(rpc.Request) - expR := &rpc.Request{ + r := new(birpc.Request) + expR := &birpc.Request{ Seq: 0, ServiceMethod: utils.CoreSv1Ping, } @@ -78,10 +77,9 @@ func TestNewServerCodec(t *testing.T) { if err = codec.ReadRequestBody("args"); err != nil { t.Fatal(err) } - if err = codec.WriteResponse(&rpc.Response{ - Error: "error", - Seq: 0, - ServiceMethod: utils.CoreSv1Ping, + if err = codec.WriteResponse(&birpc.Response{ + Error: "error", + Seq: 0, }, "reply"); err != nil { t.Fatal(err) } @@ -102,16 +100,16 @@ func TestNewServerCodec(t *testing.T) { type mockBiRPCCodec struct{} -func (mockBiRPCCodec) ReadHeader(r *rpc2.Request, _ *rpc2.Response) error { +func (mockBiRPCCodec) ReadHeader(r *birpc.Request, _ *birpc.Response) error { r.Seq = 0 - r.Method = utils.CoreSv1Ping + r.ServiceMethod = utils.CoreSv1Ping return nil } -func (mockBiRPCCodec) ReadRequestBody(any) error { return nil } -func (mockBiRPCCodec) ReadResponseBody(any) error { return nil } -func (mockBiRPCCodec) WriteRequest(*rpc2.Request, any) error { return nil } -func (mockBiRPCCodec) WriteResponse(*rpc2.Response, any) error { return nil } -func (mockBiRPCCodec) Close() error { return nil } +func (mockBiRPCCodec) ReadRequestBody(any) error { return nil } +func (mockBiRPCCodec) ReadResponseBody(any) error { return nil } +func (mockBiRPCCodec) WriteRequest(*birpc.Request, any) error { return nil } +func (mockBiRPCCodec) WriteResponse(*birpc.Response, any) error { return nil } +func (mockBiRPCCodec) Close() error { return nil } func TestNewBiRPCCodec(t *testing.T) { cfg := config.NewDefaultCGRConfig() @@ -129,10 +127,10 @@ func TestNewBiRPCCodec(t *testing.T) { } codec := NewAnalyzerBiRPCCodec(new(mockBiRPCCodec), anz, rpcclient.BiRPCJSON, "127.0.0.1:5565", "127.0.0.1:2012") - r := new(rpc2.Request) - expR := &rpc2.Request{ - Seq: 0, - Method: utils.CoreSv1Ping, + r := new(birpc.Request) + expR := &birpc.Request{ + Seq: 0, + ServiceMethod: utils.CoreSv1Ping, } if err = codec.ReadHeader(r, nil); err != nil { t.Fatal(err) @@ -143,7 +141,7 @@ func TestNewBiRPCCodec(t *testing.T) { if err = codec.ReadRequestBody("args"); err != nil { t.Fatal(err) } - if err = codec.WriteResponse(&rpc2.Response{ + if err = codec.WriteResponse(&birpc.Response{ Error: "error", Seq: 0, }, "reply"); err != nil { @@ -166,16 +164,16 @@ func TestNewBiRPCCodec(t *testing.T) { type mockBiRPCCodec2 struct{} -func (mockBiRPCCodec2) ReadHeader(_ *rpc2.Request, r *rpc2.Response) error { +func (mockBiRPCCodec2) ReadHeader(_ *birpc.Request, r *birpc.Response) error { r.Seq = 0 r.Error = "error" return nil } -func (mockBiRPCCodec2) ReadRequestBody(any) error { return nil } -func (mockBiRPCCodec2) ReadResponseBody(any) error { return nil } -func (mockBiRPCCodec2) WriteRequest(*rpc2.Request, any) error { return nil } -func (mockBiRPCCodec2) WriteResponse(*rpc2.Response, any) error { return nil } -func (mockBiRPCCodec2) Close() error { return nil } +func (mockBiRPCCodec2) ReadRequestBody(any) error { return nil } +func (mockBiRPCCodec2) ReadResponseBody(any) error { return nil } +func (mockBiRPCCodec2) WriteRequest(*birpc.Request, any) error { return nil } +func (mockBiRPCCodec2) WriteResponse(*birpc.Response, any) error { return nil } +func (mockBiRPCCodec2) Close() error { return nil } func TestNewBiRPCCodec2(t *testing.T) { cfg := config.NewDefaultCGRConfig() @@ -193,16 +191,16 @@ func TestNewBiRPCCodec2(t *testing.T) { } codec := NewAnalyzerBiRPCCodec(new(mockBiRPCCodec2), anz, rpcclient.BiRPCJSON, "127.0.0.1:5565", "127.0.0.1:2012") - if err = codec.WriteRequest(&rpc2.Request{Seq: 0, Method: utils.CoreSv1Ping}, "args"); err != nil { + if err = codec.WriteRequest(&birpc.Request{Seq: 0, ServiceMethod: utils.CoreSv1Ping}, "args"); err != nil { t.Fatal(err) } - r := new(rpc2.Response) - expR := &rpc2.Response{ + r := new(birpc.Response) + expR := &birpc.Response{ Seq: 0, Error: "error", } - if err = codec.ReadHeader(&rpc2.Request{}, r); err != nil { + if err = codec.ReadHeader(&birpc.Request{}, r); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(r, expR) { t.Errorf("Expected: %v ,received:%v", expR, r) diff --git a/analyzers/connector.go b/analyzers/connector.go index 585749b7f..c9cb3bf7f 100644 --- a/analyzers/connector.go +++ b/analyzers/connector.go @@ -21,10 +21,11 @@ package analyzers import ( "time" - "github.com/cgrates/rpcclient" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" ) -func (aS *AnalyzerService) NewAnalyzerConnector(sc rpcclient.ClientConnector, enc, from, to string) rpcclient.ClientConnector { +func (aS *AnalyzerService) NewAnalyzerConnector(sc birpc.ClientConnector, enc, from, to string) birpc.ClientConnector { return &AnalyzerConnector{ conn: sc, aS: aS, @@ -35,7 +36,7 @@ func (aS *AnalyzerService) NewAnalyzerConnector(sc rpcclient.ClientConnector, en } type AnalyzerConnector struct { - conn rpcclient.ClientConnector + conn birpc.ClientConnector aS *AnalyzerService enc string @@ -43,46 +44,9 @@ type AnalyzerConnector struct { to string } -func (c *AnalyzerConnector) Call(serviceMethod string, args, reply any) (err error) { +func (c *AnalyzerConnector) Call(ctx *context.Context, serviceMethod string, args, reply any) (err error) { sTime := time.Now() - err = c.conn.Call(serviceMethod, args, reply) + err = c.conn.Call(ctx, serviceMethod, args, reply) go c.aS.logTrafic(0, serviceMethod, args, reply, err, c.enc, c.from, c.to, sTime, time.Now()) return } - -func (aS *AnalyzerService) NewAnalyzerBiRPCConnector(sc rpcclient.BiRPCConector, enc, from, to string) rpcclient.BiRPCConector { - return &AnalyzerBiRPCConnector{ - conn: sc, - aS: aS, - enc: enc, - from: from, - to: to, - } -} - -type AnalyzerBiRPCConnector struct { - conn rpcclient.BiRPCConector - - aS *AnalyzerService - enc string - from string - to string -} - -func (c *AnalyzerBiRPCConnector) Call(serviceMethod string, args, reply any) (err error) { - sTime := time.Now() - err = c.conn.Call(serviceMethod, args, reply) - go c.aS.logTrafic(0, serviceMethod, args, reply, err, c.enc, c.from, c.to, sTime, time.Now()) - return -} - -func (c *AnalyzerBiRPCConnector) CallBiRPC(cl rpcclient.ClientConnector, serviceMethod string, args, reply any) (err error) { - sTime := time.Now() - err = c.conn.CallBiRPC(cl, serviceMethod, args, reply) - go c.aS.logTrafic(0, serviceMethod, args, reply, err, c.enc, c.from, c.to, sTime, time.Now()) - return -} - -func (c *AnalyzerBiRPCConnector) Handlers() map[string]any { - return c.conn.Handlers() -} diff --git a/analyzers/connector_test.go b/analyzers/connector_test.go index 6d65dd5db..03b0e1bab 100644 --- a/analyzers/connector_test.go +++ b/analyzers/connector_test.go @@ -21,19 +21,18 @@ package analyzers import ( "errors" "os" - "reflect" "runtime" "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) type mockConnector struct{} -func (c *mockConnector) Call(_ string, _, _ any) (err error) { +func (c *mockConnector) Call(_ *context.Context, _ string, _, _ any) (err error) { return errors.New("error") } func TestNewAnalyzeConnector(t *testing.T) { @@ -51,7 +50,7 @@ func TestNewAnalyzeConnector(t *testing.T) { t.Fatal(err) } rpc := anz.NewAnalyzerConnector(new(mockConnector), utils.MetaJSON, "127.0.0.1:5565", "127.0.0.1:2012") - if err = rpc.Call(utils.CoreSv1Ping, "args", "reply"); err == nil || err.Error() != "error" { + if err = rpc.Call(context.Background(), utils.CoreSv1Ping, "args", "reply"); err == nil || err.Error() != "error" { t.Errorf("Expected 'error' received %v", err) } time.Sleep(100 * time.Millisecond) @@ -65,72 +64,3 @@ func TestNewAnalyzeConnector(t *testing.T) { t.Fatal(err) } } - -func (c *mockConnector) CallBiRPC(cl rpcclient.ClientConnector, serviceMethod string, args, reply any) (err error) { - return c.Call(serviceMethod, args, reply) -} -func (c *mockConnector) Handlers() map[string]any { return make(map[string]any) } -func TestNewAnalyzeBiRPCConnector1(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - - cfg.AnalyzerSCfg().DBPath = "/tmp/analyzers" - if err := os.RemoveAll(cfg.AnalyzerSCfg().DBPath); err != nil { - t.Fatal(err) - } - if err := os.MkdirAll(cfg.AnalyzerSCfg().DBPath, 0700); err != nil { - t.Fatal(err) - } - anz, err := NewAnalyzerService(cfg) - if err != nil { - t.Fatal(err) - } - rpc := anz.NewAnalyzerBiRPCConnector(new(mockConnector), utils.MetaJSON, "127.0.0.1:5565", "127.0.0.1:2012") - if err = rpc.Call(utils.CoreSv1Ping, "args", "reply"); err == nil || err.Error() != "error" { - t.Errorf("Expected 'error' received %v", err) - } - time.Sleep(100 * time.Millisecond) - runtime.Gosched() - if cnt, err := anz.db.DocCount(); err != nil { - t.Fatal(err) - } else if cnt != 1 { - t.Errorf("Expected only one document received:%v", cnt) - } - if err := os.RemoveAll(cfg.AnalyzerSCfg().DBPath); err != nil { - t.Fatal(err) - } -} - -func TestNewAnalyzeBiRPCConnector2(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - - cfg.AnalyzerSCfg().DBPath = "/tmp/analyzers" - if err := os.RemoveAll(cfg.AnalyzerSCfg().DBPath); err != nil { - t.Fatal(err) - } - if err := os.MkdirAll(cfg.AnalyzerSCfg().DBPath, 0700); err != nil { - t.Fatal(err) - } - anz, err := NewAnalyzerService(cfg) - if err != nil { - t.Fatal(err) - } - rpc := anz.NewAnalyzerBiRPCConnector(new(mockConnector), utils.MetaJSON, "127.0.0.1:5565", "127.0.0.1:2012") - if err = rpc.CallBiRPC(nil, utils.CoreSv1Ping, "args", "reply"); err == nil || err.Error() != "error" { - t.Errorf("Expected 'error' received %v", err) - } - time.Sleep(100 * time.Millisecond) - runtime.Gosched() - if cnt, err := anz.db.DocCount(); err != nil { - t.Fatal(err) - } else if cnt != 1 { - t.Errorf("Expected only one document received:%v", cnt) - } - if err := os.RemoveAll(cfg.AnalyzerSCfg().DBPath); err != nil { - t.Fatal(err) - } - - exp := make(map[string]any) - if rply := rpc.Handlers(); !reflect.DeepEqual(rply, exp) { - t.Errorf("Expected: %v ,received:%v", exp, rply) - } -} diff --git a/apier/v1/accounts.go b/apier/v1/accounts.go index f8f647225..34d7d13c8 100644 --- a/apier/v1/accounts.go +++ b/apier/v1/accounts.go @@ -24,6 +24,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/guardian" @@ -37,7 +38,7 @@ type AccountActionTiming struct { NextExecTime time.Time // Next execution time } -func (apierSv1 *APIerSv1) GetAccountActionPlan(attrs *utils.TenantAccount, reply *[]*AccountActionTiming) error { +func (apierSv1 *APIerSv1) GetAccountActionPlan(ctx *context.Context, attrs *utils.TenantAccount, reply *[]*AccountActionTiming) error { if missing := utils.MissingStructFields(attrs, []string{utils.AccountField}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(strings.Join(missing, ","), "") } @@ -88,7 +89,7 @@ type AttrRemoveActionTiming struct { } // Removes an ActionTimings or parts of it depending on filters being set -func (apierSv1 *APIerSv1) RemoveActionTiming(attrs *AttrRemoveActionTiming, reply *string) (err error) { +func (apierSv1 *APIerSv1) RemoveActionTiming(ctx *context.Context, attrs *AttrRemoveActionTiming, reply *string) (err error) { if missing := utils.MissingStructFields(attrs, []string{"ActionPlanId"}); len(missing) != 0 { // Only mandatory ActionPlanId return utils.NewErrMandatoryIeMissing(missing...) } @@ -142,7 +143,7 @@ func (apierSv1 *APIerSv1) RemoveActionTiming(attrs *AttrRemoveActionTiming, repl if err != nil { return err } - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ActionPlanIDs: []string{attrs.ActionPlanId}, }, reply); err != nil { @@ -154,7 +155,7 @@ func (apierSv1 *APIerSv1) RemoveActionTiming(attrs *AttrRemoveActionTiming, repl } } if len(remAcntAPids) != 0 { - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ AccountActionPlanIDs: remAcntAPids, }, reply); err != nil { @@ -178,7 +179,7 @@ func (apierSv1 *APIerSv1) RemoveActionTiming(attrs *AttrRemoveActionTiming, repl } // SetAccount adds a new account into dataDb. If already defined, returns success. -func (apierSv1 *APIerSv1) SetAccount(attr *utils.AttrSetAccount, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetAccount(ctx *context.Context, attr *utils.AttrSetAccount, reply *string) (err error) { if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -255,7 +256,7 @@ func (apierSv1 *APIerSv1) SetAccount(attr *utils.AttrSetAccount, reply *string) if err := apierSv1.DataManager.SetAccountActionPlans(accID, acntAPids, true); err != nil { return err } - return apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + return apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ AccountActionPlanIDs: []string{accID}, ActionPlanIDs: apIDs, @@ -296,7 +297,7 @@ func (apierSv1 *APIerSv1) SetAccount(attr *utils.AttrSetAccount, reply *string) return nil } -func (apierSv1 *APIerSv1) RemoveAccount(attr *utils.AttrRemoveAccount, reply *string) (err error) { +func (apierSv1 *APIerSv1) RemoveAccount(ctx *context.Context, attr *utils.AttrRemoveAccount, reply *string) (err error) { if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -343,7 +344,7 @@ func (apierSv1 *APIerSv1) RemoveAccount(attr *utils.AttrRemoveAccount, reply *st err.Error() != utils.ErrNotFound.Error() { return err } - if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err = apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ AccountActionPlanIDs: []string{accID}, }, reply); err != nil { @@ -353,7 +354,7 @@ func (apierSv1 *APIerSv1) RemoveAccount(attr *utils.AttrRemoveAccount, reply *st return nil } -func (apierSv1 *APIerSv1) GetAccounts(attr *utils.AttrGetAccounts, reply *[]any) error { +func (apierSv1 *APIerSv1) GetAccounts(ctx *context.Context, attr *utils.AttrGetAccounts, reply *[]any) error { tnt := attr.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -401,7 +402,7 @@ func (apierSv1 *APIerSv1) GetAccounts(attr *utils.AttrGetAccounts, reply *[]any) } // GetAccount returns the account -func (apierSv1 *APIerSv1) GetAccount(attr *utils.AttrGetAccount, reply *any) error { +func (apierSv1 *APIerSv1) GetAccount(ctx *context.Context, attr *utils.AttrGetAccount, reply *any) error { tnt := attr.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -427,10 +428,10 @@ type AttrAddBalance struct { Cdrlog bool } -func (apierSv1 *APIerSv1) AddBalance(attr *AttrAddBalance, reply *string) error { +func (apierSv1 *APIerSv1) AddBalance(ctx *context.Context, attr *AttrAddBalance, reply *string) error { return apierSv1.modifyBalance(utils.MetaTopUp, attr, reply) } -func (apierSv1 *APIerSv1) DebitBalance(attr *AttrAddBalance, reply *string) error { +func (apierSv1 *APIerSv1) DebitBalance(ctx *context.Context, attr *AttrAddBalance, reply *string) error { return apierSv1.modifyBalance(utils.MetaDebit, attr, reply) } @@ -511,7 +512,7 @@ func (apierSv1 *APIerSv1) modifyBalance(aType string, attr *AttrAddBalance, repl // SetBalance sets the balance for the given account // if the account is not already created it will create the account also -func (apierSv1 *APIerSv1) SetBalance(attr *utils.AttrSetBalance, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetBalance(ctx *context.Context, attr *utils.AttrSetBalance, reply *string) (err error) { if missing := utils.MissingStructFields(attr, []string{utils.AccountField, utils.BalanceType}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -589,7 +590,7 @@ func (apierSv1 *APIerSv1) SetBalance(attr *utils.AttrSetBalance, reply *string) // SetBalances sets multiple balances for the given account // if the account is not already created it will create the account also -func (apierSv1 *APIerSv1) SetBalances(attr *utils.AttrSetBalances, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetBalances(ctx *context.Context, attr *utils.AttrSetBalances, reply *string) (err error) { if missing := utils.MissingStructFields(attr, []string{utils.AccountField, utils.BalancesFld}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -672,7 +673,7 @@ func (apierSv1 *APIerSv1) SetBalances(attr *utils.AttrSetBalances, reply *string } // RemoveBalances remove the matching balances for the account -func (apierSv1 *APIerSv1) RemoveBalances(attr *utils.AttrSetBalance, reply *string) (err error) { +func (apierSv1 *APIerSv1) RemoveBalances(ctx *context.Context, attr *utils.AttrSetBalance, reply *string) (err error) { if missing := utils.MissingStructFields(attr, []string{utils.AccountField, utils.BalanceType}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -710,7 +711,7 @@ func (apierSv1 *APIerSv1) RemoveBalances(attr *utils.AttrSetBalance, reply *stri return nil } -func (apierSv1 *APIerSv1) GetAccountsCount(attr *utils.TenantWithAPIOpts, reply *int) (err error) { +func (apierSv1 *APIerSv1) GetAccountsCount(ctx *context.Context, attr *utils.TenantWithAPIOpts, reply *int) (err error) { tnt := attr.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant diff --git a/apier/v1/accounts_it_test.go b/apier/v1/accounts_it_test.go index a24cc10f5..4c47a5d55 100644 --- a/apier/v1/accounts_it_test.go +++ b/apier/v1/accounts_it_test.go @@ -21,12 +21,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ var ( accExist bool accCfgPath string accCfg *config.CGRConfig - accRPC *rpc.Client + accRPC *birpc.Client accAcount = "refundAcc" accTenant = "cgrates.org" accBallID = "Balance1" @@ -164,7 +165,7 @@ func testAccountBalance(t *testing.T, sracc, srten, balType string, expected flo Tenant: srten, Account: sracc, } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[balType].GetTotalValue(); rply != expected { t.Errorf("Expecting: %v, received: %v", @@ -178,7 +179,7 @@ func testBalanceIfExists(t *testing.T, acc, ten, balType, balID string) (has boo Tenant: ten, Account: acc, } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) return false } @@ -203,7 +204,7 @@ func testAccITAddVoiceBalance(t *testing.T) { }, } var reply string - if err := accRPC.Call(utils.APIerSv2SetBalance, &attrSetBalance, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2SetBalance, &attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -224,13 +225,13 @@ func testAccITSetBalanceTimingIds(t *testing.T) { Time: "15:00:00Z", } var reply string - if err := accRPC.Call(utils.APIerSv1SetTPTiming, &tpTiming, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetTPTiming, &tpTiming, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } - if err := accRPC.Call(utils.APIerSv1LoadTariffPlanFromStorDb, + if err := accRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromStorDb, &AttrLoadTpFromStorDb{TPid: "TEST_TPID1"}, &reply); err != nil { t.Errorf("Got error on %s: %+v", utils.APIerSv1LoadTariffPlanFromStorDb, err.Error()) } else if reply != utils.OK { @@ -246,7 +247,7 @@ func testAccITSetBalanceTimingIds(t *testing.T) { utils.TimingIDs: "Timing", }, } - if err := accRPC.Call(utils.APIerSv1SetBalance, args, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, args, &reply); err != nil { t.Error("Got error on SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling SetBalance received: %s", reply) @@ -269,7 +270,7 @@ func testAccITSetBalanceTimingIds(t *testing.T) { EndTime: "", }, } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } @@ -287,7 +288,7 @@ func testAccITSetBalanceTimingIds(t *testing.T) { func testAccITDebitBalance(t *testing.T) { time.Sleep(5 * time.Second) var reply string - if err := accRPC.Call(utils.APIerSv1DebitBalance, &AttrAddBalance{ + if err := accRPC.Call(context.Background(), utils.APIerSv1DebitBalance, &AttrAddBalance{ Tenant: accTenant, Account: accAcount, BalanceType: utils.MetaVoice, @@ -309,7 +310,7 @@ func testAccITDebitBalance(t *testing.T) { func testAccITDebitBalanceWithoutTenant(t *testing.T) { var reply string - if err := accRPC.Call(utils.APIerSv1DebitBalance, &AttrAddBalance{ + if err := accRPC.Call(context.Background(), utils.APIerSv1DebitBalance, &AttrAddBalance{ Account: accAcount, BalanceType: utils.MetaVoice, Value: 0, @@ -337,7 +338,7 @@ func testAccITAddBalance(t *testing.T) { Value: 1.5, Cdrlog: true, } - if err := accRPC.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -346,7 +347,7 @@ func testAccITAddBalance(t *testing.T) { // verify the cdr from CdrLog var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}} - if err := accRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -361,7 +362,7 @@ func testAccITAddBalanceWithoutTenant(t *testing.T) { Value: 1.5, Cdrlog: true, } - if err := accRPC.Call(utils.APIerSv1AddBalance, &attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1AddBalance, &attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -370,7 +371,7 @@ func testAccITAddBalanceWithoutTenant(t *testing.T) { // verify the cdr from CdrLog var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}} - if err := accRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 2 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -380,7 +381,7 @@ func testAccITsetBalanceWithUUid(t *testing.T) { var reply string acnt := utils.AttrSetAccount{Tenant: "cgrates.org", Account: "test", ExtraOptions: map[string]bool{utils.Disabled: true}} - if err := accRPC.Call(utils.APIerSv1SetAccount, acnt, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetAccount, acnt, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -393,7 +394,7 @@ func testAccITsetBalanceWithUUid(t *testing.T) { Value: 1, Balance: map[string]any{"UUID": "37b54e1a-e1e6-4df6-a9a5-d97b4552f2f6"}, } - if err := accRPC.Call(utils.APIerSv1SetBalance, attrs, &reply); err == nil || err.Error() != "PARTIALLY_EXECUTED" { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, attrs, &reply); err == nil || err.Error() != "PARTIALLY_EXECUTED" { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) } @@ -407,7 +408,7 @@ func testAccITsetBalanceWithUUid(t *testing.T) { utils.ID: "balance1", }, } - if err := accRPC.Call(utils.APIerSv1SetBalance, attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetBalance received: %s", reply) @@ -418,7 +419,7 @@ func testAccITsetBalanceWithUUid(t *testing.T) { Account: "test", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &account); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &account); err != nil { t.Error(err) } else if account.BalanceMap["*sms"][0].Weight != 20 { t.Error("Balance is not set in account") @@ -433,9 +434,9 @@ func testAccITsetBalanceWithUUid(t *testing.T) { utils.UUID: balUuid, }, } - if err := accRPC.Call(utils.APIerSv1SetBalance, attrs2, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, attrs2, &reply); err != nil { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) - } else if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &account); err != nil { + } else if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &account); err != nil { t.Error(err) } else if account.BalanceMap["*sms"][0].Value != 4 || len(account.BalanceMap["*sms"]) != 1 { t.Error("Balance is not set in account") @@ -454,7 +455,7 @@ func testAccITSetBalance(t *testing.T) { }, Cdrlog: true, } - if err := accRPC.Call(utils.APIerSv1SetBalance, attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetBalance received: %s", reply) @@ -463,7 +464,7 @@ func testAccITSetBalance(t *testing.T) { // verify the cdr from CdrLog var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}} - if err := accRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 3 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -481,7 +482,7 @@ func testAccITSetBalanceWithoutTenant(t *testing.T) { }, Cdrlog: true, } - if err := accRPC.Call(utils.APIerSv1SetBalance, &attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, &attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetBalance received: %s", reply) @@ -490,7 +491,7 @@ func testAccITSetBalanceWithoutTenant(t *testing.T) { // verify the cdr from CdrLog var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}} - if err := accRPC.Call(utils.APIerSv1GetCDRs, &req, &cdrs); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1GetCDRs, &req, &cdrs); err != nil { t.Error(err) } else if len(cdrs) != 4 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -515,7 +516,7 @@ func testAccITSetBalanceWithExtraData(t *testing.T) { Cdrlog: true, ActionExtraData: &extraDataMap, } - if err := accRPC.Call(utils.APIerSv1SetBalance, attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetBalance received: %s", reply) @@ -524,7 +525,7 @@ func testAccITSetBalanceWithExtraData(t *testing.T) { // verify the cdr from CdrLog var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, Accounts: []string{"testAccITSetBalanceWithExtraData"}} - if err := accRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -550,7 +551,7 @@ func testAccITSetBalanceWithExtraData2(t *testing.T) { Cdrlog: true, ActionExtraData: &extraDataMap, } - if err := accRPC.Call(utils.APIerSv1SetBalance, attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetBalance received: %s", reply) @@ -559,7 +560,7 @@ func testAccITSetBalanceWithExtraData2(t *testing.T) { // verify the cdr from CdrLog var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, Accounts: []string{"testAccITSetBalanceWithExtraData2"}} - if err := accRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -577,7 +578,7 @@ func testAccITAddBalanceWithNegative(t *testing.T) { Account: "AddBalanceWithNegative", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err.Error() != utils.ErrNotFound.Error() { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -589,7 +590,7 @@ func testAccITAddBalanceWithNegative(t *testing.T) { BalanceType: utils.MetaMonetary, Value: -3.5, } - if err := accRPC.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -601,13 +602,13 @@ func testAccITAddBalanceWithNegative(t *testing.T) { Tenant: "cgrates.org", Account: "AddBalanceWithNegative", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != 3.5 { t.Errorf("Unexpected balance received : %+v", acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) } - if err := accRPC.Call(utils.APIerSv1DebitBalance, &AttrAddBalance{ + if err := accRPC.Call(context.Background(), utils.APIerSv1DebitBalance, &AttrAddBalance{ Tenant: "cgrates.org", Account: "AddBalanceWithNegative", BalanceType: utils.MetaMonetary, @@ -618,13 +619,13 @@ func testAccITAddBalanceWithNegative(t *testing.T) { t.Errorf("Received: %s", reply) } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != 1.5 { t.Errorf("Unexpected balance received : %+v", acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) } - if err := accRPC.Call(utils.APIerSv1DebitBalance, &AttrAddBalance{ + if err := accRPC.Call(context.Background(), utils.APIerSv1DebitBalance, &AttrAddBalance{ Tenant: "cgrates.org", Account: "AddBalanceWithNegative", BalanceType: utils.MetaMonetary, @@ -635,7 +636,7 @@ func testAccITAddBalanceWithNegative(t *testing.T) { t.Errorf("Received: %s", reply) } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != 0.5 { t.Errorf("Unexpected balance received : %+v", acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -650,7 +651,7 @@ func testAccITGetDisabledAccounts(t *testing.T) { acnt4 := utils.AttrSetAccount{Tenant: "cgrates.org", Account: "account4", ExtraOptions: map[string]bool{utils.Disabled: true}} for _, account := range []utils.AttrSetAccount{acnt1, acnt2, acnt3, acnt4} { - if err := accRPC.Call(utils.APIerSv1SetAccount, account, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetAccount, account, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -658,7 +659,7 @@ func testAccITGetDisabledAccounts(t *testing.T) { } var acnts []*engine.Account - if err := accRPC.Call(utils.APIerSv2GetAccounts, &utils.AttrGetAccounts{Tenant: "cgrates.org", Filter: map[string]bool{utils.Disabled: true}}, + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccounts, &utils.AttrGetAccounts{Tenant: "cgrates.org", Filter: map[string]bool{utils.Disabled: true}}, &acnts); err != nil { t.Error(err) } else if len(acnts) != 4 { @@ -674,7 +675,7 @@ func testAccITGetDisabledAccountsWithoutTenant(t *testing.T) { acnt4 := utils.AttrSetAccount{Account: "account4", ExtraOptions: map[string]bool{utils.Disabled: true}} for _, account := range []utils.AttrSetAccount{acnt1, acnt2, acnt3, acnt4} { - if err := accRPC.Call(utils.APIerSv1SetAccount, account, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetAccount, account, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -682,7 +683,7 @@ func testAccITGetDisabledAccountsWithoutTenant(t *testing.T) { } var acnts []*engine.Account - if err := accRPC.Call(utils.APIerSv2GetAccounts, &utils.AttrGetAccounts{Filter: map[string]bool{utils.Disabled: true}}, + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccounts, &utils.AttrGetAccounts{Filter: map[string]bool{utils.Disabled: true}}, &acnts); err != nil { t.Error(err) } else if len(acnts) != 4 { @@ -693,13 +694,13 @@ func testAccITGetDisabledAccountsWithoutTenant(t *testing.T) { func testAccITRemoveAccountWithoutTenant(t *testing.T) { var reply string acnt1 := utils.AttrSetAccount{Account: "randomAccount"} - if err := accRPC.Call(utils.APIerSv1SetAccount, acnt1, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetAccount, acnt1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) } var result *engine.Account - if err := accRPC.Call(utils.APIerSv2GetAccount, + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Account: "randomAccount"}, &result); err != nil { t.Fatal(err) @@ -707,14 +708,14 @@ func testAccITRemoveAccountWithoutTenant(t *testing.T) { t.Errorf("Expected %+v, received %+v", "cgrates.org:randomAccount", result.ID) } - if err := accRPC.Call(utils.APIerSv1RemoveAccount, + if err := accRPC.Call(context.Background(), utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{Account: "randomAccount"}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.RemoveAccount received: %s", reply) } - if err := accRPC.Call(utils.APIerSv2GetAccount, + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Account: "randomAccount"}, &result); err == nil || utils.ErrNotFound.Error() != err.Error() { t.Error(err) @@ -726,7 +727,7 @@ func testAccITCountAccounts(t *testing.T) { args := &utils.TenantWithAPIOpts{ Tenant: "cgrates.org", } - if err := accRPC.Call(utils.APIerSv1GetAccountsCount, &args, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1GetAccountsCount, &args, &reply); err != nil { t.Error(err) } else if reply != 12 { t.Errorf("Expecting: %v, received: %v", 12, reply) @@ -734,7 +735,7 @@ func testAccITCountAccounts(t *testing.T) { } func testAccITCountAccountsWithoutTenant(t *testing.T) { var reply int - if err := accRPC.Call(utils.APIerSv1GetAccountsCount, + if err := accRPC.Call(context.Background(), utils.APIerSv1GetAccountsCount, &utils.TenantIDWithAPIOpts{}, &reply); err != nil { t.Error(err) @@ -760,7 +761,7 @@ func testAccITSetBalanceWithVaslue0(t *testing.T) { utils.Weight: 10, }, } - if err := accRPC.Call(utils.APIerSv1SetBalance, args, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, args, &reply); err != nil { t.Error("Got error on SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling SetBalance received: %s", reply) @@ -771,7 +772,7 @@ func testAccITSetBalanceWithVaslue0(t *testing.T) { Tenant: accTenant, Account: "testAccSetBalance", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } @@ -801,7 +802,7 @@ func testAccITSetBalanceWithVaslueInMap(t *testing.T) { utils.Value: 2, }, } - if err := accRPC.Call(utils.APIerSv1SetBalance, args, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, args, &reply); err != nil { t.Error("Got error on SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling SetBalance received: %s", reply) @@ -812,7 +813,7 @@ func testAccITSetBalanceWithVaslueInMap(t *testing.T) { Tenant: accTenant, Account: "testAccSetBalance", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } @@ -837,7 +838,7 @@ func testAccITAddBalanceWithValue0(t *testing.T) { Account: "testAccAddBalance", BalanceType: utils.MetaMonetary, } - if err := accRPC.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -848,7 +849,7 @@ func testAccITAddBalanceWithValue0(t *testing.T) { Tenant: accTenant, Account: "testAccAddBalance", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } @@ -873,7 +874,7 @@ func testAccITAddBalanceWithValueInMap(t *testing.T) { utils.Value: 1.5, }, } - if err := accRPC.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -884,7 +885,7 @@ func testAccITAddBalanceWithValueInMap(t *testing.T) { Tenant: accTenant, Account: "testAccAddBalance", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } @@ -904,7 +905,7 @@ func testAccITTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{ FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} var loadInst utils.LoadInstance - if err := accRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := accRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } @@ -924,7 +925,7 @@ func testAccITAddBalanceWithDestinations(t *testing.T) { utils.Value: 2, }, } - if err := accRPC.Call(utils.APIerSv1SetBalance, args, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, args, &reply); err != nil { t.Error("Got error on SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling SetBalance received: %s", reply) @@ -935,7 +936,7 @@ func testAccITAddBalanceWithDestinations(t *testing.T) { Tenant: accTenant, Account: "testAccITAddBalanceWithDestinations", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } @@ -973,7 +974,7 @@ func testAccITAddBalanceWithDestinations(t *testing.T) { }, } var cc engine.CallCost - if err := accRPC.Call(utils.ResponderMaxDebit, cd, &cc); err != nil { + if err := accRPC.Call(context.Background(), utils.ResponderMaxDebit, cd, &cc); err != nil { t.Error("Got error on Responder.Debit: ", err.Error()) } else if cc.GetDuration() != 0 { t.Errorf("Calling Responder.MaxDebit got callcost: %v", utils.ToIJSON(cc)) @@ -992,7 +993,7 @@ func testAccITAddBalanceWithDestinations(t *testing.T) { TimeEnd: tStart.Add(time.Nanosecond), }, } - if err := accRPC.Call(utils.ResponderMaxDebit, cd, &cc); err != nil { + if err := accRPC.Call(context.Background(), utils.ResponderMaxDebit, cd, &cc); err != nil { t.Error("Got error on Responder.Debit: ", err.Error()) } else if cc.GetDuration() != 1 { t.Errorf("Calling Responder.MaxDebit got callcost: %v", utils.ToIJSON(cc)) @@ -1011,7 +1012,7 @@ func testAccITAccountWithTriggers(t *testing.T) { utils.Value: 5, }, } - if err := accRPC.Call(utils.APIerSv1SetBalance, args, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, args, &reply); err != nil { t.Error("Got error on SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling SetBalance received: %s", reply) @@ -1024,7 +1025,7 @@ func testAccITAccountWithTriggers(t *testing.T) { {Identifier: utils.MetaResetTriggers}, }} - if err := accRPC.Call(utils.APIerSv2SetActions, topupAction, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2SetActions, topupAction, &reply); err != nil { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -1036,7 +1037,7 @@ func testAccITAccountWithTriggers(t *testing.T) { BalanceType: utils.MetaMonetary, Units: "5", Weight: 10.0}, }} - if err := accRPC.Call(utils.APIerSv2SetActions, actTrigger, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2SetActions, actTrigger, &reply); err != nil { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -1044,7 +1045,7 @@ func testAccITAccountWithTriggers(t *testing.T) { attrsAddTrigger := &AttrAddActionTrigger{Tenant: "cgrates.org", Account: "testAccITAccountWithTriggers", BalanceType: utils.MetaMonetary, ThresholdType: "*min_balance", ThresholdValue: 2, Weight: 10, ActionsId: "ACT_TRIGGER"} - if err := accRPC.Call(utils.APIerSv1AddTriggeredAction, attrsAddTrigger, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1AddTriggeredAction, attrsAddTrigger, &reply); err != nil { t.Error("Got error on APIerSv1.AddTriggeredAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddTriggeredAction received: %s", reply) @@ -1056,7 +1057,7 @@ func testAccITAccountWithTriggers(t *testing.T) { Account: "testAccITAccountWithTriggers", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } else { for _, value := range acnt.BalanceMap[utils.MetaMonetary] { @@ -1080,7 +1081,7 @@ func testAccITAccountWithTriggers(t *testing.T) { } // Debit balance will trigger the Trigger from the account - if err := accRPC.Call(utils.APIerSv1DebitBalance, &AttrAddBalance{ + if err := accRPC.Call(context.Background(), utils.APIerSv1DebitBalance, &AttrAddBalance{ Tenant: "cgrates.org", Account: "testAccITAccountWithTriggers", BalanceType: utils.MetaMonetary, @@ -1091,7 +1092,7 @@ func testAccITAccountWithTriggers(t *testing.T) { t.Errorf("Received: %s", reply) } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } else { for _, value := range acnt.BalanceMap[utils.MetaMonetary] { @@ -1117,14 +1118,14 @@ func testAccITAccountWithTriggers(t *testing.T) { // execute the action that topup_reset the balance and reset the trigger attrsEA := &utils.AttrExecuteAction{Tenant: "cgrates.org", Account: "testAccITAccountWithTriggers", ActionsId: "TOPUP_WITH_RESET_TRIGGER"} - if err := accRPC.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } acnt = engine.Account{} - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } else { for _, value := range acnt.BalanceMap[utils.MetaMonetary] { @@ -1157,7 +1158,7 @@ func testAccITAccountMonthlyEstimated(t *testing.T) { BalanceType: utils.MetaMonetary, Units: "5", Weight: 10.0}, }} - if err := accRPC.Call(utils.APIerSv2SetActions, topupAction, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2SetActions, topupAction, &reply); err != nil { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -1174,7 +1175,7 @@ func testAccITAccountMonthlyEstimated(t *testing.T) { TimingID: utils.MetaMonthlyEstimated, }}, } - if err := accRPC.Call(utils.APIerSv1SetActionPlan, &atms1, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &atms1, &reply); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply) @@ -1185,7 +1186,7 @@ func testAccITAccountMonthlyEstimated(t *testing.T) { ReloadScheduler: true, ActionPlanID: "ATMS_1", } - if err := accRPC.Call(utils.APIerSv1SetAccount, acnt1, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetAccount, acnt1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -1195,7 +1196,7 @@ func testAccITAccountMonthlyEstimated(t *testing.T) { accIDsStrMp := utils.StringMap{ "cgrates.org:testAccITAccountMonthlyEstimated": true, } - if err := accRPC.Call(utils.APIerSv1GetActionPlan, + if err := accRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err != nil { t.Error(err) } else if len(aps) != 1 { @@ -1246,7 +1247,7 @@ func testAccITMultipleBalance(t *testing.T) { }, } var reply string - if err := accRPC.Call(utils.APIerSv1SetBalances, &attrSetBalance, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalances, &attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -1257,7 +1258,7 @@ func testAccITMultipleBalance(t *testing.T) { Tenant: "cgrates.org", Account: "testAccITMultipleBalance", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaVoice]) != 2 { t.Errorf("Expected %+v, received: %+v", 2, len(acnt.BalanceMap[utils.MetaVoice])) @@ -1301,7 +1302,7 @@ func testAccITMultipleBalanceWithoutTenant(t *testing.T) { }, } var reply string - if err := accRPC.Call(utils.APIerSv1SetBalances, &attrSetBalance, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalances, &attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -1311,7 +1312,7 @@ func testAccITMultipleBalanceWithoutTenant(t *testing.T) { attrs := &utils.AttrGetAccount{ Account: "testAccITMultipleBalance", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaVoice]) != 2 { t.Errorf("Expected %+v, received: %+v", 2, len(acnt.BalanceMap[utils.MetaVoice])) @@ -1326,7 +1327,7 @@ func testAccITMultipleBalanceWithoutTenant(t *testing.T) { func testAccITRemoveBalances(t *testing.T) { var reply string - if err := accRPC.Call(utils.APIerSv1RemoveBalances, + if err := accRPC.Call(context.Background(), utils.APIerSv1RemoveBalances, &utils.AttrSetBalance{Account: "testAccITMultipleBalance", BalanceType: utils.MetaVoice}, &reply); err != nil { t.Error(err) @@ -1339,7 +1340,7 @@ func testAccITRemoveBalances(t *testing.T) { Value: 1.5, Cdrlog: true, } - if err := accRPC.Call(utils.APIerSv1AddBalance, &attrs, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1AddBalance, &attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -1360,7 +1361,7 @@ func testAccITAddVoiceBalanceWithDestinations(t *testing.T) { utils.Value: time.Hour, }, } - if err := accRPC.Call(utils.APIerSv1SetBalance, args, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, args, &reply); err != nil { t.Error("Got error on SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling SetBalance received: %s", reply) @@ -1371,7 +1372,7 @@ func testAccITAddVoiceBalanceWithDestinations(t *testing.T) { Tenant: "cgrates.com", Account: "testAccITAddVoiceBalanceWithDestinations", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } @@ -1411,7 +1412,7 @@ func testAccITAddVoiceBalanceWithDestinations(t *testing.T) { }, } var rply time.Duration - if err := accRPC.Call(utils.ResponderGetMaxSessionTime, cd, &rply); err != nil { + if err := accRPC.Call(context.Background(), utils.ResponderGetMaxSessionTime, cd, &rply); err != nil { t.Error("Got error on Responder.Debit: ", err.Error()) } else if rply != 0 { t.Errorf("Expecting %+v, received: %+v", 0, rply) @@ -1430,7 +1431,7 @@ func testAccITSetBalanceWithTimeSuffix(t *testing.T) { utils.Value: "120ms", }, } - if err := accRPC.Call(utils.APIerSv1SetBalance, args, &reply); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv1SetBalance, args, &reply); err != nil { t.Error("Got error on SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling SetBalance received: %s", reply) @@ -1441,7 +1442,7 @@ func testAccITSetBalanceWithTimeSuffix(t *testing.T) { Tenant: accTenant, Account: "testAccSetBalanceTimeSuffix", } - if err := accRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Fatal(err) } diff --git a/apier/v1/accounts_test.go b/apier/v1/accounts_test.go index 42ac5c3ae..3b874b6a4 100644 --- a/apier/v1/accounts_test.go +++ b/apier/v1/accounts_test.go @@ -21,6 +21,7 @@ package v1 import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -77,31 +78,31 @@ func TestGetAccountIds(t *testing.T) { func TestGetAccounts(t *testing.T) { var accounts []any var attrs utils.AttrGetAccounts - if err := apierAcnts.GetAccounts(&utils.AttrGetAccounts{Tenant: "cgrates.org"}, &accounts); err != nil { + if err := apierAcnts.GetAccounts(context.Background(), &utils.AttrGetAccounts{Tenant: "cgrates.org"}, &accounts); err != nil { t.Error("Unexpected error", err.Error()) } else if len(accounts) != 3 { t.Errorf("Accounts returned: %+v", accounts) } attrs = utils.AttrGetAccounts{Tenant: "itsyscom.com"} - if err := apierAcnts.GetAccounts(&attrs, &accounts); err != nil { + if err := apierAcnts.GetAccounts(context.Background(), &attrs, &accounts); err != nil { t.Error("Unexpected error", err.Error()) } else if len(accounts) != 2 { t.Errorf("Accounts returned: %+v", accounts) } attrs = utils.AttrGetAccounts{Tenant: "cgrates.org", AccountIDs: []string{"account1"}} - if err := apierAcnts.GetAccounts(&attrs, &accounts); err != nil { + if err := apierAcnts.GetAccounts(context.Background(), &attrs, &accounts); err != nil { t.Error("Unexpected error", err.Error()) } else if len(accounts) != 1 { t.Errorf("Accounts returned: %+v", accounts) } attrs = utils.AttrGetAccounts{Tenant: "itsyscom.com", AccountIDs: []string{"INVALID"}} - if err := apierAcnts.GetAccounts(&attrs, &accounts); err != nil { + if err := apierAcnts.GetAccounts(context.Background(), &attrs, &accounts); err != nil { t.Error("Unexpected error", err.Error()) } else if len(accounts) != 0 { t.Errorf("Accounts returned: %+v", accounts) } attrs = utils.AttrGetAccounts{Tenant: "INVALID"} - if err := apierAcnts.GetAccounts(&attrs, &accounts); err != nil { + if err := apierAcnts.GetAccounts(context.Background(), &attrs, &accounts); err != nil { t.Error("Unexpected error", err.Error()) } else if len(accounts) != 0 { t.Errorf("Accounts returned: %+v", accounts) diff --git a/apier/v1/analyzer.go b/apier/v1/analyzer.go index 13da468fb..7b4ab17d5 100644 --- a/apier/v1/analyzer.go +++ b/apier/v1/analyzer.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/analyzers" "github.com/cgrates/cgrates/utils" ) @@ -33,19 +34,19 @@ type AnalyzerSv1 struct { aS *analyzers.AnalyzerService } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (aSv1 *AnalyzerSv1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (aSv1 *AnalyzerSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(aSv1, serviceMethod, args, reply) } // Ping return pong if the service is active -func (aSv1 *AnalyzerSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (aSv1 *AnalyzerSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } // StringQuery returns a list of API that match the query -func (aSv1 *AnalyzerSv1) StringQuery(search *analyzers.QueryArgs, reply *[]map[string]any) error { - return aSv1.aS.V1StringQuery(search, reply) +func (aSv1 *AnalyzerSv1) StringQuery(ctx *context.Context, search *analyzers.QueryArgs, reply *[]map[string]any) error { + return aSv1.aS.V1StringQuery(ctx, search, reply) } diff --git a/apier/v1/api_interfaces.go b/apier/v1/api_interfaces.go index 80481603c..de4d3e720 100644 --- a/apier/v1/api_interfaces.go +++ b/apier/v1/api_interfaces.go @@ -21,6 +21,7 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/engine" @@ -30,235 +31,235 @@ import ( ) type ThresholdSv1Interface interface { - GetThresholdIDs(tenant *utils.TenantWithAPIOpts, tIDs *[]string) error - GetThresholdsForEvent(args *utils.CGREvent, reply *engine.Thresholds) error - GetThreshold(tntID *utils.TenantIDWithAPIOpts, t *engine.Threshold) error - ProcessEvent(args *utils.CGREvent, tIDs *[]string) error - Ping(ign *utils.CGREvent, reply *string) error + GetThresholdIDs(ctx *context.Context, tenant *utils.TenantWithAPIOpts, tIDs *[]string) error + GetThresholdsForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.Thresholds) error + GetThreshold(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, t *engine.Threshold) error + ProcessEvent(ctx *context.Context, args *utils.CGREvent, tIDs *[]string) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type StatSv1Interface interface { - GetQueueIDs(tenant *utils.TenantWithAPIOpts, qIDs *[]string) error - ProcessEvent(args *utils.CGREvent, reply *[]string) error - GetStatQueuesForEvent(args *utils.CGREvent, reply *[]string) (err error) - GetQueueStringMetrics(args *utils.TenantIDWithAPIOpts, reply *map[string]string) (err error) - GetQueueFloatMetrics(args *utils.TenantIDWithAPIOpts, reply *map[string]float64) (err error) - Ping(ign *utils.CGREvent, reply *string) error + GetQueueIDs(ctx *context.Context, tenant *utils.TenantWithAPIOpts, qIDs *[]string) error + ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) error + GetStatQueuesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) + GetQueueStringMetrics(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *map[string]string) (err error) + GetQueueFloatMetrics(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *map[string]float64) (err error) + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type ResourceSv1Interface interface { - GetResourcesForEvent(args *utils.CGREvent, reply *engine.Resources) error - AuthorizeResources(args *utils.CGREvent, reply *string) error - AllocateResources(args *utils.CGREvent, reply *string) error - ReleaseResources(args *utils.CGREvent, reply *string) error - GetResource(args *utils.TenantIDWithAPIOpts, reply *engine.Resource) error - GetResourceWithConfig(args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) error - Ping(ign *utils.CGREvent, reply *string) error + GetResourcesForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.Resources) error + AuthorizeResources(ctx *context.Context, args *utils.CGREvent, reply *string) error + AllocateResources(ctx *context.Context, args *utils.CGREvent, reply *string) error + ReleaseResources(ctx *context.Context, args *utils.CGREvent, reply *string) error + GetResource(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.Resource) error + GetResourceWithConfig(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type RouteSv1Interface interface { - GetRoutes(args *utils.CGREvent, reply *engine.SortedRoutesList) error - GetRouteProfilesForEvent(args *utils.CGREvent, reply *[]*engine.RouteProfile) error - GetRoutesList(args *utils.CGREvent, reply *[]string) error - Ping(ign *utils.CGREvent, reply *string) error + GetRoutes(ctx *context.Context, args *utils.CGREvent, reply *engine.SortedRoutesList) error + GetRouteProfilesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*engine.RouteProfile) error + GetRoutesList(ctx *context.Context, args *utils.CGREvent, reply *[]string) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type AttributeSv1Interface interface { - GetAttributeForEvent(args *utils.CGREvent, reply *engine.AttributeProfile) (err error) - ProcessEvent(args *utils.CGREvent, reply *engine.AttrSProcessEventReply) error - Ping(ign *utils.CGREvent, reply *string) error + GetAttributeForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.AttributeProfile) (err error) + ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.AttrSProcessEventReply) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type ChargerSv1Interface interface { - Ping(ign *utils.CGREvent, reply *string) error - GetChargersForEvent(cgrEv *utils.CGREvent, reply *engine.ChargerProfiles) error - ProcessEvent(args *utils.CGREvent, reply *[]*engine.ChrgSProcessEventReply) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error + GetChargersForEvent(ctx *context.Context, cgrEv *utils.CGREvent, reply *engine.ChargerProfiles) error + ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*engine.ChrgSProcessEventReply) error } type SessionSv1Interface interface { - AuthorizeEvent(args *sessions.V1AuthorizeArgs, rply *sessions.V1AuthorizeReply) error - AuthorizeEventWithDigest(args *sessions.V1AuthorizeArgs, rply *sessions.V1AuthorizeReplyWithDigest) error - InitiateSession(args *sessions.V1InitSessionArgs, rply *sessions.V1InitSessionReply) error - InitiateSessionWithDigest(args *sessions.V1InitSessionArgs, rply *sessions.V1InitReplyWithDigest) error - UpdateSession(args *sessions.V1UpdateSessionArgs, rply *sessions.V1UpdateSessionReply) error - SyncSessions(args *utils.TenantWithAPIOpts, rply *string) error - TerminateSession(args *sessions.V1TerminateSessionArgs, rply *string) error - ProcessCDR(cgrEv *utils.CGREvent, rply *string) error - ProcessMessage(args *sessions.V1ProcessMessageArgs, rply *sessions.V1ProcessMessageReply) error - ProcessEvent(args *sessions.V1ProcessEventArgs, rply *sessions.V1ProcessEventReply) error - GetCost(args *sessions.V1ProcessEventArgs, rply *sessions.V1GetCostReply) error - GetActiveSessions(args *utils.SessionFilter, rply *[]*sessions.ExternalSession) error - GetActiveSessionsCount(args *utils.SessionFilter, rply *int) error - ForceDisconnect(args *utils.SessionFilter, rply *string) error - GetPassiveSessions(args *utils.SessionFilter, rply *[]*sessions.ExternalSession) error - GetPassiveSessionsCount(args *utils.SessionFilter, rply *int) error - Ping(ign *utils.CGREvent, reply *string) error - ReplicateSessions(args *dispatchers.ArgsReplicateSessionsWithAPIOpts, rply *string) error - SetPassiveSession(args *sessions.Session, reply *string) error - ActivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error - DeactivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error + AuthorizeEvent(ctx *context.Context, args *sessions.V1AuthorizeArgs, rply *sessions.V1AuthorizeReply) error + AuthorizeEventWithDigest(ctx *context.Context, args *sessions.V1AuthorizeArgs, rply *sessions.V1AuthorizeReplyWithDigest) error + InitiateSession(ctx *context.Context, args *sessions.V1InitSessionArgs, rply *sessions.V1InitSessionReply) error + InitiateSessionWithDigest(ctx *context.Context, args *sessions.V1InitSessionArgs, rply *sessions.V1InitReplyWithDigest) error + UpdateSession(ctx *context.Context, args *sessions.V1UpdateSessionArgs, rply *sessions.V1UpdateSessionReply) error + SyncSessions(ctx *context.Context, args *utils.TenantWithAPIOpts, rply *string) error + TerminateSession(ctx *context.Context, args *sessions.V1TerminateSessionArgs, rply *string) error + ProcessCDR(ctx *context.Context, cgrEv *utils.CGREvent, rply *string) error + ProcessMessage(ctx *context.Context, args *sessions.V1ProcessMessageArgs, rply *sessions.V1ProcessMessageReply) error + ProcessEvent(ctx *context.Context, args *sessions.V1ProcessEventArgs, rply *sessions.V1ProcessEventReply) error + GetCost(ctx *context.Context, args *sessions.V1ProcessEventArgs, rply *sessions.V1GetCostReply) error + GetActiveSessions(ctx *context.Context, args *utils.SessionFilter, rply *[]*sessions.ExternalSession) error + GetActiveSessionsCount(ctx *context.Context, args *utils.SessionFilter, rply *int) error + ForceDisconnect(ctx *context.Context, args *utils.SessionFilter, rply *string) error + GetPassiveSessions(ctx *context.Context, args *utils.SessionFilter, rply *[]*sessions.ExternalSession) error + GetPassiveSessionsCount(ctx *context.Context, args *utils.SessionFilter, rply *int) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error + ReplicateSessions(ctx *context.Context, args *dispatchers.ArgsReplicateSessionsWithAPIOpts, rply *string) error + SetPassiveSession(ctx *context.Context, args *sessions.Session, reply *string) error + ActivateSessions(ctx *context.Context, args *utils.SessionIDsWithArgsDispatcher, reply *string) error + DeactivateSessions(ctx *context.Context, args *utils.SessionIDsWithArgsDispatcher, reply *string) error - STIRAuthenticate(args *sessions.V1STIRAuthenticateArgs, reply *string) error - STIRIdentity(args *sessions.V1STIRIdentityArgs, reply *string) error + STIRAuthenticate(ctx *context.Context, args *sessions.V1STIRAuthenticateArgs, reply *string) error + STIRIdentity(ctx *context.Context, args *sessions.V1STIRIdentityArgs, reply *string) error } type ResponderInterface interface { - GetCost(arg *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error) - Debit(arg *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error) - MaxDebit(arg *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error) - RefundIncrements(arg *engine.CallDescriptorWithAPIOpts, reply *engine.Account) (err error) - RefundRounding(arg *engine.CallDescriptorWithAPIOpts, reply *engine.Account) (err error) - GetMaxSessionTime(arg *engine.CallDescriptorWithAPIOpts, reply *time.Duration) (err error) - GetCostOnRatingPlans(arg *utils.GetCostOnRatingPlansArgs, reply *map[string]any) (err error) - GetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]any) (err error) - Shutdown(arg *utils.TenantWithAPIOpts, reply *string) (err error) - Ping(ign *utils.CGREvent, reply *string) error + GetCost(ctx *context.Context, arg *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error) + Debit(ctx *context.Context, arg *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error) + MaxDebit(ctx *context.Context, arg *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error) + RefundIncrements(ctx *context.Context, arg *engine.CallDescriptorWithAPIOpts, reply *engine.Account) (err error) + RefundRounding(ctx *context.Context, arg *engine.CallDescriptorWithAPIOpts, reply *engine.Account) (err error) + GetMaxSessionTime(ctx *context.Context, arg *engine.CallDescriptorWithAPIOpts, reply *time.Duration) (err error) + GetCostOnRatingPlans(ctx *context.Context, arg *utils.GetCostOnRatingPlansArgs, reply *map[string]any) (err error) + GetMaxSessionTimeOnAccounts(ctx *context.Context, arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]any) (err error) + Shutdown(ctx *context.Context, arg *utils.TenantWithAPIOpts, reply *string) (err error) + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type CacheSv1Interface interface { - GetItemIDs(args *utils.ArgsGetCacheItemIDsWithAPIOpts, reply *[]string) error - HasItem(args *utils.ArgsGetCacheItemWithAPIOpts, reply *bool) error - GetItemExpiryTime(args *utils.ArgsGetCacheItemWithAPIOpts, reply *time.Time) error - RemoveItem(args *utils.ArgsGetCacheItemWithAPIOpts, reply *string) error - RemoveItems(args *utils.AttrReloadCacheWithAPIOpts, reply *string) error - Clear(cacheIDs *utils.AttrCacheIDsWithAPIOpts, reply *string) error - GetCacheStats(cacheIDs *utils.AttrCacheIDsWithAPIOpts, rply *map[string]*ltcache.CacheStats) error - PrecacheStatus(cacheIDs *utils.AttrCacheIDsWithAPIOpts, rply *map[string]string) error - HasGroup(args *utils.ArgsGetGroupWithAPIOpts, rply *bool) error - GetGroupItemIDs(args *utils.ArgsGetGroupWithAPIOpts, rply *[]string) error - RemoveGroup(args *utils.ArgsGetGroupWithAPIOpts, rply *string) error - ReloadCache(attrs *utils.AttrReloadCacheWithAPIOpts, reply *string) error - LoadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) error - ReplicateSet(args *utils.ArgCacheReplicateSet, reply *string) (err error) - ReplicateRemove(args *utils.ArgCacheReplicateRemove, reply *string) (err error) - Ping(ign *utils.CGREvent, reply *string) error + GetItemIDs(ctx *context.Context, args *utils.ArgsGetCacheItemIDsWithAPIOpts, reply *[]string) error + HasItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *bool) error + GetItemExpiryTime(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *time.Time) error + RemoveItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *string) error + RemoveItems(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) error + Clear(ctx *context.Context, cacheIDs *utils.AttrCacheIDsWithAPIOpts, reply *string) error + GetCacheStats(ctx *context.Context, cacheIDs *utils.AttrCacheIDsWithAPIOpts, rply *map[string]*ltcache.CacheStats) error + PrecacheStatus(ctx *context.Context, cacheIDs *utils.AttrCacheIDsWithAPIOpts, rply *map[string]string) error + HasGroup(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, rply *bool) error + GetGroupItemIDs(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, rply *[]string) error + RemoveGroup(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, rply *string) error + ReloadCache(ctx *context.Context, attrs *utils.AttrReloadCacheWithAPIOpts, reply *string) error + LoadCache(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) error + ReplicateSet(ctx *context.Context, args *utils.ArgCacheReplicateSet, reply *string) (err error) + ReplicateRemove(ctx *context.Context, args *utils.ArgCacheReplicateRemove, reply *string) (err error) + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type GuardianSv1Interface interface { - RemoteLock(attr *dispatchers.AttrRemoteLockWithAPIOpts, reply *string) (err error) - RemoteUnlock(refID *dispatchers.AttrRemoteUnlockWithAPIOpts, reply *[]string) (err error) - Ping(ign *utils.CGREvent, reply *string) error + RemoteLock(ctx *context.Context, attr *dispatchers.AttrRemoteLockWithAPIOpts, reply *string) (err error) + RemoteUnlock(ctx *context.Context, refID *dispatchers.AttrRemoteUnlockWithAPIOpts, reply *[]string) (err error) + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type SchedulerSv1Interface interface { - Reload(arg *utils.CGREvent, reply *string) error - Ping(ign *utils.CGREvent, reply *string) error - ExecuteActions(attr *utils.AttrsExecuteActions, reply *string) error - ExecuteActionPlans(attr *utils.AttrsExecuteActionPlans, reply *string) error + Reload(ctx *context.Context, arg *utils.CGREvent, reply *string) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error + ExecuteActions(ctx *context.Context, attr *utils.AttrsExecuteActions, reply *string) error + ExecuteActionPlans(ctx *context.Context, attr *utils.AttrsExecuteActionPlans, reply *string) error } type CDRsV1Interface interface { - ProcessCDR(cdr *engine.CDRWithAPIOpts, reply *string) error - ProcessEvent(arg *engine.ArgV1ProcessEvent, reply *string) error - ProcessExternalCDR(cdr *engine.ExternalCDRWithAPIOpts, reply *string) error - RateCDRs(arg *engine.ArgRateCDRs, reply *string) error - StoreSessionCost(attr *engine.AttrCDRSStoreSMCost, reply *string) error - GetCDRsCount(args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) error - GetCDRs(args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) error - Ping(ign *utils.CGREvent, reply *string) error + ProcessCDR(ctx *context.Context, cdr *engine.CDRWithAPIOpts, reply *string) error + ProcessEvent(ctx *context.Context, arg *engine.ArgV1ProcessEvent, reply *string) error + ProcessExternalCDR(ctx *context.Context, cdr *engine.ExternalCDRWithAPIOpts, reply *string) error + RateCDRs(ctx *context.Context, arg *engine.ArgRateCDRs, reply *string) error + StoreSessionCost(ctx *context.Context, attr *engine.AttrCDRSStoreSMCost, reply *string) error + GetCDRsCount(ctx *context.Context, args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) error + GetCDRs(ctx *context.Context, args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type ServiceManagerV1Interface interface { - StartService(args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error - StopService(args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error - ServiceStatus(args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error - Ping(ign *utils.CGREvent, reply *string) error + StartService(ctx *context.Context, args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error + StopService(ctx *context.Context, args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error + ServiceStatus(ctx *context.Context, args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type RALsV1Interface interface { - GetRatingPlansCost(arg *utils.RatingPlanCostArg, reply *dispatchers.RatingPlanCost) error - Ping(ign *utils.CGREvent, reply *string) error + GetRatingPlansCost(ctx *context.Context, arg *utils.RatingPlanCostArg, reply *dispatchers.RatingPlanCost) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error } type ConfigSv1Interface interface { - GetConfig(section *config.SectionWithAPIOpts, reply *map[string]any) (err error) - ReloadConfig(section *config.ReloadArgs, reply *string) (err error) - SetConfig(args *config.SetConfigArgs, reply *string) (err error) - SetConfigFromJSON(args *config.SetConfigFromJSONArgs, reply *string) (err error) - GetConfigAsJSON(args *config.SectionWithAPIOpts, reply *string) (err error) + GetConfig(ctx *context.Context, section *config.SectionWithAPIOpts, reply *map[string]any) (err error) + ReloadConfig(ctx *context.Context, section *config.ReloadArgs, reply *string) (err error) + SetConfig(ctx *context.Context, args *config.SetConfigArgs, reply *string) (err error) + SetConfigFromJSON(ctx *context.Context, args *config.SetConfigFromJSONArgs, reply *string) (err error) + GetConfigAsJSON(ctx *context.Context, args *config.SectionWithAPIOpts, reply *string) (err error) } type CoreSv1Interface interface { - Status(arg *utils.TenantWithAPIOpts, reply *map[string]any) error - Ping(ign *utils.CGREvent, reply *string) error - Sleep(arg *utils.DurationArgs, reply *string) error + Status(ctx *context.Context, arg *utils.TenantWithAPIOpts, reply *map[string]any) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error + Sleep(ctx *context.Context, arg *utils.DurationArgs, reply *string) error } type ReplicatorSv1Interface interface { - Ping(ign *utils.CGREvent, reply *string) error - GetAccount(args *utils.StringWithAPIOpts, reply *engine.Account) error - GetDestination(key *utils.StringWithAPIOpts, reply *engine.Destination) error - GetReverseDestination(key *utils.StringWithAPIOpts, reply *[]string) error - GetStatQueue(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) error - GetFilter(tntID *utils.TenantIDWithAPIOpts, reply *engine.Filter) error - GetThreshold(tntID *utils.TenantIDWithAPIOpts, reply *engine.Threshold) error - GetThresholdProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) error - GetStatQueueProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) error - GetTiming(id *utils.StringWithAPIOpts, reply *utils.TPTiming) error - GetResource(tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error - GetResourceProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error - GetActionTriggers(id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error - GetSharedGroup(id *utils.StringWithAPIOpts, reply *engine.SharedGroup) error - GetActions(id *utils.StringWithAPIOpts, reply *engine.Actions) error - GetActionPlan(id *utils.StringWithAPIOpts, reply *engine.ActionPlan) error - GetAllActionPlans(_ *utils.StringWithAPIOpts, reply *map[string]*engine.ActionPlan) error - GetAccountActionPlans(id *utils.StringWithAPIOpts, reply *[]string) error - GetRatingPlan(id *utils.StringWithAPIOpts, reply *engine.RatingPlan) error - GetRatingProfile(id *utils.StringWithAPIOpts, reply *engine.RatingProfile) error - GetRouteProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error - GetAttributeProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) error - GetChargerProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) error - GetDispatcherProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) error - GetDispatcherHost(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) error - GetItemLoadIDs(itemID *utils.StringWithAPIOpts, reply *map[string]int64) error - SetThresholdProfile(th *engine.ThresholdProfileWithAPIOpts, reply *string) error - SetThreshold(th *engine.ThresholdWithAPIOpts, reply *string) error - SetAccount(acc *engine.AccountWithAPIOpts, reply *string) error - SetDestination(dst *engine.DestinationWithAPIOpts, reply *string) error - SetReverseDestination(dst *engine.DestinationWithAPIOpts, reply *string) error - SetStatQueue(ssq *engine.StatQueueWithAPIOpts, reply *string) error - SetFilter(fltr *engine.FilterWithAPIOpts, reply *string) error - SetStatQueueProfile(sq *engine.StatQueueProfileWithAPIOpts, reply *string) error - SetTiming(tm *utils.TPTimingWithAPIOpts, reply *string) error - SetResource(rs *engine.ResourceWithAPIOpts, reply *string) error - SetResourceProfile(rs *engine.ResourceProfileWithAPIOpts, reply *string) error - SetActionTriggers(args *engine.SetActionTriggersArgWithAPIOpts, reply *string) error - SetSharedGroup(shg *engine.SharedGroupWithAPIOpts, reply *string) error - SetActions(args *engine.SetActionsArgsWithAPIOpts, reply *string) error - SetRatingPlan(rp *engine.RatingPlanWithAPIOpts, reply *string) error - SetRatingProfile(rp *engine.RatingProfileWithAPIOpts, reply *string) error - SetRouteProfile(sp *engine.RouteProfileWithAPIOpts, reply *string) error - SetAttributeProfile(ap *engine.AttributeProfileWithAPIOpts, reply *string) error - SetChargerProfile(cp *engine.ChargerProfileWithAPIOpts, reply *string) error - SetDispatcherProfile(dpp *engine.DispatcherProfileWithAPIOpts, reply *string) error - SetActionPlan(args *engine.SetActionPlanArgWithAPIOpts, reply *string) error - SetAccountActionPlans(args *engine.SetAccountActionPlansArgWithAPIOpts, reply *string) error - SetDispatcherHost(dpp *engine.DispatcherHostWithAPIOpts, reply *string) error - RemoveThreshold(args *utils.TenantIDWithAPIOpts, reply *string) error - SetLoadIDs(args *utils.LoadIDsWithAPIOpts, reply *string) error - RemoveDestination(id *utils.StringWithAPIOpts, reply *string) error - RemoveAccount(id *utils.StringWithAPIOpts, reply *string) error - RemoveStatQueue(args *utils.TenantIDWithAPIOpts, reply *string) error - RemoveFilter(args *utils.TenantIDWithAPIOpts, reply *string) error - RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts, reply *string) error - RemoveStatQueueProfile(args *utils.TenantIDWithAPIOpts, reply *string) error - RemoveTiming(id *utils.StringWithAPIOpts, reply *string) error - RemoveResource(args *utils.TenantIDWithAPIOpts, reply *string) error - RemoveResourceProfile(args *utils.TenantIDWithAPIOpts, reply *string) error - RemoveActionTriggers(id *utils.StringWithAPIOpts, reply *string) error - RemoveSharedGroup(id *utils.StringWithAPIOpts, reply *string) error - RemoveActions(id *utils.StringWithAPIOpts, reply *string) error - RemoveActionPlan(id *utils.StringWithAPIOpts, reply *string) error - RemAccountActionPlans(args *engine.RemAccountActionPlansArgsWithAPIOpts, reply *string) error - RemoveRatingPlan(id *utils.StringWithAPIOpts, reply *string) error - RemoveRatingProfile(id *utils.StringWithAPIOpts, reply *string) error - RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) error - RemoveAttributeProfile(args *utils.TenantIDWithAPIOpts, reply *string) error - RemoveChargerProfile(args *utils.TenantIDWithAPIOpts, reply *string) error - RemoveDispatcherProfile(args *utils.TenantIDWithAPIOpts, reply *string) error - RemoveDispatcherHost(args *utils.TenantIDWithAPIOpts, reply *string) error + Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error + GetAccount(ctx *context.Context, args *utils.StringWithAPIOpts, reply *engine.Account) error + GetDestination(ctx *context.Context, key *utils.StringWithAPIOpts, reply *engine.Destination) error + GetReverseDestination(ctx *context.Context, key *utils.StringWithAPIOpts, reply *[]string) error + GetStatQueue(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) error + GetFilter(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.Filter) error + GetThreshold(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.Threshold) error + GetThresholdProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) error + GetStatQueueProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) error + GetTiming(ctx *context.Context, id *utils.StringWithAPIOpts, reply *utils.TPTiming) error + GetResource(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error + GetResourceProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error + GetActionTriggers(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error + GetSharedGroup(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.SharedGroup) error + GetActions(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.Actions) error + GetActionPlan(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.ActionPlan) error + GetAllActionPlans(ctx *context.Context, _ *utils.StringWithAPIOpts, reply *map[string]*engine.ActionPlan) error + GetAccountActionPlans(ctx *context.Context, id *utils.StringWithAPIOpts, reply *[]string) error + GetRatingPlan(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.RatingPlan) error + GetRatingProfile(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.RatingProfile) error + GetRouteProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error + GetAttributeProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) error + GetChargerProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) error + GetDispatcherProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) error + GetDispatcherHost(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) error + GetItemLoadIDs(ctx *context.Context, itemID *utils.StringWithAPIOpts, reply *map[string]int64) error + SetThresholdProfile(ctx *context.Context, th *engine.ThresholdProfileWithAPIOpts, reply *string) error + SetThreshold(ctx *context.Context, th *engine.ThresholdWithAPIOpts, reply *string) error + SetAccount(ctx *context.Context, acc *engine.AccountWithAPIOpts, reply *string) error + SetDestination(ctx *context.Context, dst *engine.DestinationWithAPIOpts, reply *string) error + SetReverseDestination(ctx *context.Context, dst *engine.DestinationWithAPIOpts, reply *string) error + SetStatQueue(ctx *context.Context, ssq *engine.StatQueueWithAPIOpts, reply *string) error + SetFilter(ctx *context.Context, fltr *engine.FilterWithAPIOpts, reply *string) error + SetStatQueueProfile(ctx *context.Context, sq *engine.StatQueueProfileWithAPIOpts, reply *string) error + SetTiming(ctx *context.Context, tm *utils.TPTimingWithAPIOpts, reply *string) error + SetResource(ctx *context.Context, rs *engine.ResourceWithAPIOpts, reply *string) error + SetResourceProfile(ctx *context.Context, rs *engine.ResourceProfileWithAPIOpts, reply *string) error + SetActionTriggers(ctx *context.Context, args *engine.SetActionTriggersArgWithAPIOpts, reply *string) error + SetSharedGroup(ctx *context.Context, shg *engine.SharedGroupWithAPIOpts, reply *string) error + SetActions(ctx *context.Context, args *engine.SetActionsArgsWithAPIOpts, reply *string) error + SetRatingPlan(ctx *context.Context, rp *engine.RatingPlanWithAPIOpts, reply *string) error + SetRatingProfile(ctx *context.Context, rp *engine.RatingProfileWithAPIOpts, reply *string) error + SetRouteProfile(ctx *context.Context, sp *engine.RouteProfileWithAPIOpts, reply *string) error + SetAttributeProfile(ctx *context.Context, ap *engine.AttributeProfileWithAPIOpts, reply *string) error + SetChargerProfile(ctx *context.Context, cp *engine.ChargerProfileWithAPIOpts, reply *string) error + SetDispatcherProfile(ctx *context.Context, dpp *engine.DispatcherProfileWithAPIOpts, reply *string) error + SetActionPlan(ctx *context.Context, args *engine.SetActionPlanArgWithAPIOpts, reply *string) error + SetAccountActionPlans(ctx *context.Context, args *engine.SetAccountActionPlansArgWithAPIOpts, reply *string) error + SetDispatcherHost(ctx *context.Context, dpp *engine.DispatcherHostWithAPIOpts, reply *string) error + RemoveThreshold(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + SetLoadIDs(ctx *context.Context, args *utils.LoadIDsWithAPIOpts, reply *string) error + RemoveDestination(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error + RemoveAccount(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error + RemoveStatQueue(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + RemoveFilter(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + RemoveThresholdProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + RemoveStatQueueProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + RemoveTiming(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error + RemoveResource(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + RemoveResourceProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + RemoveActionTriggers(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error + RemoveSharedGroup(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error + RemoveActions(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error + RemoveActionPlan(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error + RemAccountActionPlans(ctx *context.Context, args *engine.RemAccountActionPlansArgsWithAPIOpts, reply *string) error + RemoveRatingPlan(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error + RemoveRatingProfile(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) error + RemoveRouteProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + RemoveAttributeProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + RemoveChargerProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + RemoveDispatcherProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error + RemoveDispatcherHost(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error - GetIndexes(args *utils.GetIndexesArg, reply *map[string]utils.StringSet) error - SetIndexes(args *utils.SetIndexesArg, reply *string) error - RemoveIndexes(args *utils.GetIndexesArg, reply *string) error + GetIndexes(ctx *context.Context, args *utils.GetIndexesArg, reply *map[string]utils.StringSet) error + SetIndexes(ctx *context.Context, args *utils.SetIndexesArg, reply *string) error + RemoveIndexes(ctx *context.Context, args *utils.GetIndexesArg, reply *string) error } diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 81888491a..f85d05787 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -28,6 +28,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/ees" "github.com/cgrates/cgrates/engine" @@ -55,13 +56,13 @@ type APIerSv1 struct { ResponderChan chan *engine.Responder } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (apierSv1 *APIerSv1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (apierSv1 *APIerSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(apierSv1, serviceMethod, args, reply) } -func (apierSv1 *APIerSv1) GetDestination(dstId *string, reply *engine.Destination) error { +func (apierSv1 *APIerSv1) GetDestination(ctx *context.Context, dstId *string, reply *engine.Destination) error { if dst, err := apierSv1.DataManager.GetDestination(*dstId, true, true, utils.NonTransactional); err != nil { return utils.ErrNotFound } else { @@ -75,7 +76,7 @@ type AttrRemoveDestination struct { Prefixes []string } -func (apierSv1 *APIerSv1) RemoveDestination(attr *AttrRemoveDestination, reply *string) (err error) { +func (apierSv1 *APIerSv1) RemoveDestination(ctx *context.Context, attr *AttrRemoveDestination, reply *string) (err error) { for _, dstID := range attr.DestinationIDs { var oldDst *engine.Destination if oldDst, err = apierSv1.DataManager.GetDestination(dstID, true, true, @@ -100,7 +101,7 @@ func (apierSv1 *APIerSv1) RemoveDestination(attr *AttrRemoveDestination, reply * if err = apierSv1.DataManager.UpdateReverseDestination(oldDst, newDst, utils.NonTransactional); err != nil { return } - if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err = apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ReverseDestinationIDs: oldDst.Prefixes, DestinationIDs: []string{dstID}, @@ -113,7 +114,7 @@ func (apierSv1 *APIerSv1) RemoveDestination(attr *AttrRemoveDestination, reply * if err = apierSv1.DataManager.RemoveDestination(dstID, utils.NonTransactional); err != nil { return } - if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err = apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ReverseDestinationIDs: oldDst.Prefixes, DestinationIDs: []string{dstID}, @@ -126,7 +127,7 @@ func (apierSv1 *APIerSv1) RemoveDestination(attr *AttrRemoveDestination, reply * } // GetReverseDestination retrieves revese destination list for a prefix -func (apierSv1 *APIerSv1) GetReverseDestination(prefix *string, reply *[]string) (err error) { +func (apierSv1 *APIerSv1) GetReverseDestination(ctx *context.Context, prefix *string, reply *[]string) (err error) { if *prefix == utils.EmptyString { return utils.NewErrMandatoryIeMissing("prefix") } @@ -139,7 +140,7 @@ func (apierSv1 *APIerSv1) GetReverseDestination(prefix *string, reply *[]string) } // ComputeReverseDestinations will rebuild complete reverse destinations data -func (apierSv1 *APIerSv1) ComputeReverseDestinations(ignr *string, reply *string) (err error) { +func (apierSv1 *APIerSv1) ComputeReverseDestinations(ctx *context.Context, ignr *string, reply *string) (err error) { if err = apierSv1.DataManager.RebuildReverseForPrefix(utils.ReverseDestinationPrefix); err != nil { return } @@ -148,11 +149,11 @@ func (apierSv1 *APIerSv1) ComputeReverseDestinations(ignr *string, reply *string } // ComputeAccountActionPlans will rebuild complete reverse accountActions data -func (apierSv1 *APIerSv1) ComputeAccountActionPlans(tnt *utils.TenantWithAPIOpts, reply *string) (err error) { +func (apierSv1 *APIerSv1) ComputeAccountActionPlans(ctx *context.Context, tnt *utils.TenantWithAPIOpts, reply *string) (err error) { if err = apierSv1.DataManager.RebuildReverseForPrefix(utils.AccountActionPlansPrefix); err != nil { return } - return apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + return apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ Tenant: tnt.Tenant, CacheIDs: []string{utils.CacheAccountActionPlans}, @@ -160,7 +161,7 @@ func (apierSv1 *APIerSv1) ComputeAccountActionPlans(tnt *utils.TenantWithAPIOpts }, reply) } -func (apierSv1 *APIerSv1) GetSharedGroup(sgId *string, reply *engine.SharedGroup) error { +func (apierSv1 *APIerSv1) GetSharedGroup(ctx *context.Context, sgId *string, reply *engine.SharedGroup) error { if sg, err := apierSv1.DataManager.GetSharedGroup(*sgId, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound { // Not found is not an error here return err } else { @@ -171,7 +172,7 @@ func (apierSv1 *APIerSv1) GetSharedGroup(sgId *string, reply *engine.SharedGroup return nil } -func (apierSv1 *APIerSv1) SetDestination(attrs *utils.AttrSetDestination, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetDestination(ctx *context.Context, attrs *utils.AttrSetDestination, reply *string) (err error) { if missing := utils.MissingStructFields(attrs, []string{"Id", "Prefixes"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -190,7 +191,7 @@ func (apierSv1 *APIerSv1) SetDestination(attrs *utils.AttrSetDestination, reply if err = apierSv1.DataManager.UpdateReverseDestination(oldDest, dest, utils.NonTransactional); err != nil { return } - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ReverseDestinationIDs: dest.Prefixes, DestinationIDs: []string{attrs.Id}, @@ -201,7 +202,7 @@ func (apierSv1 *APIerSv1) SetDestination(attrs *utils.AttrSetDestination, reply return nil } -func (apierSv1 *APIerSv1) GetRatingPlan(rplnId *string, reply *engine.RatingPlan) error { +func (apierSv1 *APIerSv1) GetRatingPlan(ctx *context.Context, rplnId *string, reply *engine.RatingPlan) error { rpln, err := apierSv1.DataManager.GetRatingPlan(*rplnId, false, utils.NonTransactional) if err != nil { if err.Error() == utils.ErrNotFound.Error() { @@ -213,7 +214,7 @@ func (apierSv1 *APIerSv1) GetRatingPlan(rplnId *string, reply *engine.RatingPlan return nil } -func (apierSv1 *APIerSv1) RemoveRatingPlan(ID *string, reply *string) error { +func (apierSv1 *APIerSv1) RemoveRatingPlan(ctx *context.Context, ID *string, reply *string) error { if len(*ID) == 0 { return utils.NewErrMandatoryIeMissing("ID") } @@ -221,7 +222,7 @@ func (apierSv1 *APIerSv1) RemoveRatingPlan(ID *string, reply *string) error { if err != nil { return utils.NewErrServerError(err) } - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ RatingPlanIDs: []string{*ID}, }, reply); err != nil { @@ -235,7 +236,7 @@ func (apierSv1 *APIerSv1) RemoveRatingPlan(ID *string, reply *string) error { return nil } -func (apierSv1 *APIerSv1) ExecuteAction(attr *utils.AttrExecuteAction, reply *string) error { +func (apierSv1 *APIerSv1) ExecuteAction(ctx *context.Context, attr *utils.AttrExecuteAction, reply *string) error { at := &engine.ActionTiming{ ActionsID: attr.ActionsId, } @@ -260,7 +261,7 @@ type AttrLoadDestination struct { } // Load destinations from storDb into dataDb. -func (apierSv1 *APIerSv1) LoadDestination(attrs *AttrLoadDestination, reply *string) error { +func (apierSv1 *APIerSv1) LoadDestination(ctx *context.Context, attrs *AttrLoadDestination, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing("TPid") } @@ -276,7 +277,7 @@ func (apierSv1 *APIerSv1) LoadDestination(attrs *AttrLoadDestination, reply *str } else if !loaded { return utils.ErrNotFound } - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ DestinationIDs: []string{attrs.ID}, }, reply); err != nil { @@ -292,7 +293,7 @@ type AttrLoadRatingPlan struct { } // Process dependencies and load a specific rating plan from storDb into dataDb. -func (apierSv1 *APIerSv1) LoadRatingPlan(attrs *AttrLoadRatingPlan, reply *string) error { +func (apierSv1 *APIerSv1) LoadRatingPlan(ctx *context.Context, attrs *AttrLoadRatingPlan, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing("TPid") } @@ -313,7 +314,7 @@ func (apierSv1 *APIerSv1) LoadRatingPlan(attrs *AttrLoadRatingPlan, reply *strin } // Process dependencies and load a specific rating profile from storDb into dataDb. -func (apierSv1 *APIerSv1) LoadRatingProfile(attrs *utils.TPRatingProfile, reply *string) error { +func (apierSv1 *APIerSv1) LoadRatingProfile(ctx *context.Context, attrs *utils.TPRatingProfile, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing("TPid") } @@ -346,7 +347,7 @@ type AttrLoadSharedGroup struct { } // Load destinations from storDb into dataDb. -func (apierSv1 *APIerSv1) LoadSharedGroup(attrs *AttrLoadSharedGroup, reply *string) error { +func (apierSv1 *APIerSv1) LoadSharedGroup(ctx *context.Context, attrs *AttrLoadSharedGroup, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing("TPid") } @@ -373,7 +374,7 @@ type AttrLoadTpFromStorDb struct { } // Loads complete data in a TP from storDb -func (apierSv1 *APIerSv1) LoadTariffPlanFromStorDb(attrs *AttrLoadTpFromStorDb, reply *string) error { +func (apierSv1 *APIerSv1) LoadTariffPlanFromStorDb(ctx *context.Context, attrs *AttrLoadTpFromStorDb, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing("TPid") } @@ -422,7 +423,7 @@ func (apierSv1 *APIerSv1) LoadTariffPlanFromStorDb(attrs *AttrLoadTpFromStorDb, return nil } -func (apierSv1 *APIerSv1) ImportTariffPlanFromFolder(attrs *utils.AttrImportTPFromFolder, reply *string) error { +func (apierSv1 *APIerSv1) ImportTariffPlanFromFolder(ctx *context.Context, attrs *utils.AttrImportTPFromFolder, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "FolderPath"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -453,7 +454,7 @@ func (apierSv1 *APIerSv1) ImportTariffPlanFromFolder(attrs *utils.AttrImportTPFr } // SetRatingProfile sets a specific rating profile working with data directly in the DataDB without involving storDb -func (apierSv1 *APIerSv1) SetRatingProfile(attrs *utils.AttrSetRatingProfile, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetRatingProfile(ctx *context.Context, attrs *utils.AttrSetRatingProfile, reply *string) (err error) { if missing := utils.MissingStructFields(attrs, []string{"Subject", "RatingPlanActivations"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -512,7 +513,7 @@ func (apierSv1 *APIerSv1) SetRatingProfile(attrs *utils.AttrSetRatingProfile, re } // GetRatingProfileIDs returns list of resourceProfile IDs registered for a tenant -func (apierSv1 *APIerSv1) GetRatingProfileIDs(args *utils.PaginatorWithTenant, rsPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetRatingProfileIDs(ctx *context.Context, args *utils.PaginatorWithTenant, rsPrfIDs *[]string) error { tnt := args.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -533,7 +534,7 @@ func (apierSv1 *APIerSv1) GetRatingProfileIDs(args *utils.PaginatorWithTenant, r return nil } -func (apierSv1 *APIerSv1) GetRatingProfile(attrs *utils.AttrGetRatingProfile, reply *engine.RatingProfile) (err error) { +func (apierSv1 *APIerSv1) GetRatingProfile(ctx *context.Context, attrs *utils.AttrGetRatingProfile, reply *engine.RatingProfile) (err error) { if missing := utils.MissingStructFields(attrs, []string{utils.Category, utils.Subject}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -581,7 +582,7 @@ type V1TPAction struct { Weight float64 // Action's weight } -func (apierSv1 *APIerSv1) SetActions(attrs *V1AttrSetActions, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetActions(ctx *context.Context, attrs *V1AttrSetActions, reply *string) (err error) { if missing := utils.MissingStructFields(attrs, []string{"ActionsId", "Actions"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -648,7 +649,7 @@ func (apierSv1 *APIerSv1) SetActions(attrs *V1AttrSetActions, reply *string) (er return utils.NewErrServerError(err) } //CacheReload - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ActionIDs: []string{attrs.ActionsId}, }, reply); err != nil { @@ -663,7 +664,7 @@ func (apierSv1 *APIerSv1) SetActions(attrs *V1AttrSetActions, reply *string) (er } // Retrieves actions attached to specific ActionsId within cache -func (apierSv1 *APIerSv1) GetActions(actsId *string, reply *[]*utils.TPAction) error { +func (apierSv1 *APIerSv1) GetActions(ctx *context.Context, actsId *string, reply *[]*utils.TPAction) error { if len(*actsId) == 0 { return fmt.Errorf("%s ActionsId: %s", utils.ErrMandatoryIeMissing.Error(), *actsId) } @@ -753,7 +754,7 @@ func (attr *AttrActionPlan) getRITiming(dm *engine.DataManager) (timing *engine. return } -func (apierSv1 *APIerSv1) SetActionPlan(attrs *AttrSetActionPlan, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetActionPlan(ctx *context.Context, attrs *AttrSetActionPlan, reply *string) (err error) { if missing := utils.MissingStructFields(attrs, []string{"Id", "ActionPlan"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -795,7 +796,7 @@ func (apierSv1 *APIerSv1) SetActionPlan(attrs *AttrSetActionPlan, reply *string) if err := apierSv1.DataManager.SetActionPlan(ap.Id, ap, true, utils.NonTransactional); err != nil { return utils.NewErrServerError(err) } - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ActionPlanIDs: []string{ap.Id}, }, reply); err != nil { @@ -807,7 +808,7 @@ func (apierSv1 *APIerSv1) SetActionPlan(attrs *AttrSetActionPlan, reply *string) } } if len(prevAccountIDs) != 0 { - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ AccountActionPlanIDs: prevAccountIDs.Slice(), }, reply); err != nil { @@ -950,7 +951,7 @@ type AttrGetActionPlan struct { ID string } -func (apierSv1 *APIerSv1) GetActionPlan(attr *AttrGetActionPlan, reply *[]*engine.ActionPlan) error { +func (apierSv1 *APIerSv1) GetActionPlan(ctx *context.Context, attr *AttrGetActionPlan, reply *[]*engine.ActionPlan) error { var result []*engine.ActionPlan if attr.ID == "" || attr.ID == "*" { result = make([]*engine.ActionPlan, 0) @@ -972,7 +973,7 @@ func (apierSv1 *APIerSv1) GetActionPlan(attr *AttrGetActionPlan, reply *[]*engin return nil } -func (apierSv1 *APIerSv1) RemoveActionPlan(attr *AttrGetActionPlan, reply *string) (err error) { +func (apierSv1 *APIerSv1) RemoveActionPlan(ctx *context.Context, attr *AttrGetActionPlan, reply *string) (err error) { if missing := utils.MissingStructFields(attr, []string{"ID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -992,7 +993,7 @@ func (apierSv1 *APIerSv1) RemoveActionPlan(attr *AttrGetActionPlan, reply *strin } } if len(prevAccountIDs) != 0 { - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ AccountActionPlanIDs: prevAccountIDs.Slice(), }, reply); err != nil { @@ -1008,7 +1009,7 @@ func (apierSv1 *APIerSv1) RemoveActionPlan(attr *AttrGetActionPlan, reply *strin } // Process dependencies and load a specific AccountActions profile from storDb into dataDb. -func (apierSv1 *APIerSv1) LoadAccountActions(attrs *utils.TPAccountActions, reply *string) error { +func (apierSv1 *APIerSv1) LoadAccountActions(ctx *context.Context, attrs *utils.TPAccountActions, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing("TPid") } @@ -1034,7 +1035,7 @@ func (apierSv1 *APIerSv1) LoadAccountActions(attrs *utils.TPAccountActions, repl return nil } -func (apierSv1 *APIerSv1) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolder, reply *string) error { +func (apierSv1 *APIerSv1) LoadTariffPlanFromFolder(ctx *context.Context, attrs *utils.AttrLoadTpFromFolder, reply *string) error { // verify if FolderPath is present if len(attrs.FolderPath) == 0 { return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "FolderPath") @@ -1106,7 +1107,7 @@ func (apierSv1 *APIerSv1) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFo // RemoveTPFromFolder will load the tarrifplan from folder into TpReader object // and will delete if from database -func (apierSv1 *APIerSv1) RemoveTPFromFolder(attrs *utils.AttrLoadTpFromFolder, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPFromFolder(ctx *context.Context, attrs *utils.AttrLoadTpFromFolder, reply *string) error { // verify if FolderPath is present if len(attrs.FolderPath) == 0 { return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "FolderPath") @@ -1178,7 +1179,7 @@ func (apierSv1 *APIerSv1) RemoveTPFromFolder(attrs *utils.AttrLoadTpFromFolder, // RemoveTPFromStorDB will load the tarrifplan from StorDB into TpReader object // and will delete if from database -func (apierSv1 *APIerSv1) RemoveTPFromStorDB(attrs *AttrLoadTpFromStorDb, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPFromStorDB(ctx *context.Context, attrs *AttrLoadTpFromStorDb, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing("TPid") } @@ -1254,7 +1255,7 @@ func (arrp *AttrRemoveRatingProfile) GetId() (result string) { return } -func (apierSv1 *APIerSv1) RemoveRatingProfile(attr *AttrRemoveRatingProfile, reply *string) error { +func (apierSv1 *APIerSv1) RemoveRatingProfile(ctx *context.Context, attr *AttrRemoveRatingProfile, reply *string) error { if attr.Tenant == utils.EmptyString { attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant } @@ -1281,7 +1282,7 @@ func (apierSv1 *APIerSv1) RemoveRatingProfile(attr *AttrRemoveRatingProfile, rep return nil } -func (apierSv1 *APIerSv1) GetLoadHistory(attrs *utils.Paginator, reply *[]*utils.LoadInstance) error { +func (apierSv1 *APIerSv1) GetLoadHistory(ctx *context.Context, attrs *utils.Paginator, reply *[]*utils.LoadInstance) error { nrItems := -1 offset := 0 if attrs.Offset != nil { // For offset we need full data @@ -1313,7 +1314,7 @@ type AttrRemoveActions struct { ActionIDs []string } -func (apierSv1 *APIerSv1) RemoveActions(attr *AttrRemoveActions, reply *string) error { +func (apierSv1 *APIerSv1) RemoveActions(ctx *context.Context, attr *AttrRemoveActions, reply *string) error { if attr.ActionIDs == nil { err := utils.ErrNotFound *reply = err.Error() @@ -1364,7 +1365,7 @@ func (apierSv1 *APIerSv1) RemoveActions(attr *AttrRemoveActions, reply *string) } } //CacheReload - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ActionIDs: attr.ActionIDs, }, reply); err != nil { @@ -1385,7 +1386,7 @@ type ArgsReplyFailedPosts struct { } // ReplayFailedPosts will repost failed requests found in the FailedRequestsInDir -func (apierSv1 *APIerSv1) ReplayFailedPosts(args *ArgsReplyFailedPosts, reply *string) (err error) { +func (apierSv1 *APIerSv1) ReplayFailedPosts(ctx *context.Context, args *ArgsReplyFailedPosts, reply *string) (err error) { failedReqsInDir := apierSv1.Config.GeneralCfg().FailedPostsDir if args.FailedRequestsInDir != nil && *args.FailedRequestsInDir != "" { failedReqsInDir = *args.FailedRequestsInDir @@ -1434,7 +1435,7 @@ func (apierSv1 *APIerSv1) ReplayFailedPosts(args *ArgsReplyFailedPosts, reply *s return nil } -func (apierSv1 *APIerSv1) GetLoadIDs(args *string, reply *map[string]int64) (err error) { +func (apierSv1 *APIerSv1) GetLoadIDs(ctx *context.Context, args *string, reply *map[string]int64) (err error) { var loadIDs map[string]int64 if loadIDs, err = apierSv1.DataManager.GetItemLoadIDs(*args, false); err != nil { return @@ -1448,7 +1449,7 @@ type LoadTimeArgs struct { Item string } -func (apierSv1 *APIerSv1) GetLoadTimes(args *LoadTimeArgs, reply *map[string]string) (err error) { +func (apierSv1 *APIerSv1) GetLoadTimes(ctx *context.Context, args *LoadTimeArgs, reply *map[string]string) (err error) { if loadIDs, err := apierSv1.DataManager.GetItemLoadIDs(args.Item, false); err != nil { return err } else { @@ -1465,7 +1466,7 @@ func (apierSv1 *APIerSv1) GetLoadTimes(args *LoadTimeArgs, reply *map[string]str return } -func (apierSv1 *APIerSv1) ComputeActionPlanIndexes(_ string, reply *string) (err error) { +func (apierSv1 *APIerSv1) ComputeActionPlanIndexes(ctx *context.Context, _ string, reply *string) (err error) { if err = apierSv1.DataManager.RebuildReverseForPrefix(utils.AccountActionPlansPrefix); err != nil { return err } @@ -1474,7 +1475,7 @@ func (apierSv1 *APIerSv1) ComputeActionPlanIndexes(_ string, reply *string) (err } // GetActionPlanIDs returns list of ActionPlan IDs registered for a tenant -func (apierSv1 *APIerSv1) GetActionPlanIDs(args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetActionPlanIDs(ctx *context.Context, args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error { prfx := utils.ActionPlanPrefix keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(utils.ActionPlanPrefix) if err != nil { @@ -1492,7 +1493,7 @@ func (apierSv1 *APIerSv1) GetActionPlanIDs(args *utils.PaginatorWithTenant, attr } // GetRatingPlanIDs returns list of RatingPlan IDs registered for a tenant -func (apierSv1 *APIerSv1) GetRatingPlanIDs(args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetRatingPlanIDs(ctx *context.Context, args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error { prfx := utils.RatingPlanPrefix keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(utils.RatingPlanPrefix) if err != nil { @@ -1529,13 +1530,13 @@ func (apierSv1 *APIerSv1) ListenAndServe(stopChan chan struct{}) { } // Ping return pong if the service is active -func (apierSv1 *APIerSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (apierSv1 *APIerSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } // ExportToFolder export specific items (or all items if items is empty) from DataDB back to CSV -func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *string) error { +func (apierSv1 *APIerSv1) ExportToFolder(ctx *context.Context, arg *utils.ArgExportToFolder, reply *string) error { // if items is empty we need to export all items if len(arg.Items) == 0 { arg.Items = []string{utils.MetaAttributes, utils.MetaChargers, utils.MetaDispatchers, @@ -1893,7 +1894,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st return nil } -func (apierSv1 *APIerSv1) ExportCDRs(args *utils.ArgExportCDRs, reply *map[string]any) (err error) { +func (apierSv1 *APIerSv1) ExportCDRs(ctx *context.Context, args *utils.ArgExportCDRs, reply *map[string]any) (err error) { if len(apierSv1.Config.ApierCfg().EEsConns) == 0 { return utils.NewErrNotConnected(utils.EEs) } @@ -1917,7 +1918,8 @@ func (apierSv1 *APIerSv1) ExportCDRs(args *utils.ArgExportCDRs, reply *map[strin if args.Verbose { argCdr.CGREvent.APIOpts[utils.OptsEEsVerbose] = struct{}{} } - if err := apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().EEsConns, nil, utils.EeSv1ProcessEvent, + if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().EEsConns, + utils.EeSv1ProcessEvent, argCdr, &rplyCdr); err != nil { utils.Logger.Warning(fmt.Sprintf("<%s> error: <%s> processing event: <%s> with <%s>", utils.ApierS, err.Error(), utils.ToJSON(cdr.AsCGREvent()), utils.EEs)) diff --git a/apier/v1/apier2_it_test.go b/apier/v1/apier2_it_test.go index d95a39725..1ea57ec0e 100644 --- a/apier/v1/apier2_it_test.go +++ b/apier/v1/apier2_it_test.go @@ -22,7 +22,6 @@ along with this program. If not, see package v1 import ( - "net/rpc" "os/exec" "path" "reflect" @@ -30,6 +29,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/scheduler" "github.com/cgrates/cgrates/config" @@ -41,7 +42,7 @@ import ( var ( apierCfgPath string apierCfg *config.CGRConfig - apierRPC *rpc.Client + apierRPC *birpc.Client APIerSv2ConfigDIR string //run tests for specific configuration sTestsAPIer = []func(t *testing.T){ @@ -147,7 +148,7 @@ func testAPIerRPCConn(t *testing.T) { func testAPIerLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := apierRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -187,7 +188,7 @@ func testAPIerVerifyAttributesAfterLoad(t *testing.T) { } eAttrPrf.Compile() var attrReply *engine.AttributeProfile - if err := apierRPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := apierRPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev, &attrReply); err != nil { t.Error(err) } @@ -207,7 +208,7 @@ func testAPIerVerifyAttributesAfterLoad(t *testing.T) { func testAPIerRemoveTPFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := apierRPC.Call(utils.APIerSv1RemoveTPFromFolder, attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1RemoveTPFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -215,13 +216,13 @@ func testAPIerRemoveTPFromFolder(t *testing.T) { func testAPIerAfterDelete(t *testing.T) { var reply *engine.AttributeProfile - if err := apierRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := apierRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) } var replyTh *engine.ThresholdProfile - if err := apierRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := apierRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &replyTh); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -241,7 +242,7 @@ func testAPIerVerifyAttributesAfterDelete(t *testing.T) { }, } var attrReply *engine.AttributeProfile - if err := apierRPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := apierRPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -256,7 +257,7 @@ func testAPIerGetRatingPlanCost(t *testing.T) { Usage: "1h", } var reply dispatchers.RatingPlanCost - if err := apierRPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil { t.Error(err) } else if reply.RatingPlanID != "RP_1001" { t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID) @@ -278,7 +279,7 @@ func testAPIerGetRatingPlanCost2(t *testing.T) { Usage: "1h", } var reply dispatchers.RatingPlanCost - if err := apierRPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil { t.Error(err) } else if reply.RatingPlanID != "RP_1001" { t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID) @@ -297,7 +298,7 @@ func testAPIerGetRatingPlanCost3(t *testing.T) { Usage: "1h", } var reply dispatchers.RatingPlanCost - if err := apierRPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil { t.Error(err) } else if reply.RatingPlanID != "RP_1002" { t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID) @@ -310,7 +311,7 @@ func testAPIerGetRatingPlanCost3(t *testing.T) { func testAPIerGetActionPlanIDs(t *testing.T) { var reply []string - if err := apierRPC.Call(utils.APIerSv1GetActionPlanIDs, + if err := apierRPC.Call(context.Background(), utils.APIerSv1GetActionPlanIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) @@ -324,7 +325,7 @@ func testAPIerGetActionPlanIDs(t *testing.T) { func testAPIerGetRatingPlanIDs(t *testing.T) { var reply []string expected := []string{"RP_1002_LOW", "RP_1003", "RP_1001", "RP_MMS", "RP_SMS", "RP_1002"} - if err := apierRPC.Call(utils.APIerSv1GetRatingPlanIDs, + if err := apierRPC.Call(context.Background(), utils.APIerSv1GetRatingPlanIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) @@ -350,7 +351,7 @@ func testAPIerSetActionPlanDfltTime(t *testing.T) { }, ReloadScheduler: true, } - if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &hourlyAP, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &hourlyAP, &reply1); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply1 != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1) @@ -366,7 +367,7 @@ func testAPIerSetActionPlanDfltTime(t *testing.T) { }, ReloadScheduler: true, } - if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &dailyAP, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &dailyAP, &reply1); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply1 != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1) @@ -382,7 +383,7 @@ func testAPIerSetActionPlanDfltTime(t *testing.T) { }, ReloadScheduler: true, } - if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &weeklyAP, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &weeklyAP, &reply1); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply1 != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1) @@ -398,13 +399,13 @@ func testAPIerSetActionPlanDfltTime(t *testing.T) { }, ReloadScheduler: true, } - if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &monthlyAP, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &monthlyAP, &reply1); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply1 != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1) } var rply []*scheduler.ScheduledAction - if err := apierRPC.Call(utils.APIerSv1GetScheduledActions, + if err := apierRPC.Call(context.Background(), utils.APIerSv1GetScheduledActions, scheduler.ArgsGetScheduledActions{}, &rply); err != nil { t.Error("Unexpected error: ", err) } else { @@ -445,7 +446,7 @@ func testAPIerSetActionPlanDfltTime(t *testing.T) { func testAPIerLoadRatingPlan(t *testing.T) { attrs := utils.AttrSetDestination{Id: "DEST_CUSTOM", Prefixes: []string{"+4986517174963", "+4986517174960"}} var reply string - if err := apierRPC.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetDestination, &attrs, &reply); err != nil { t.Error("Unexpected error", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -454,7 +455,7 @@ func testAPIerLoadRatingPlan(t *testing.T) { rt := &utils.TPRateRALs{TPid: "TP_SAMPLE", ID: "SAMPLE_RATE_ID", RateSlots: []*utils.RateSlot{ {ConnectFee: 0, Rate: 0, RateUnit: "1s", RateIncrement: "1s", GroupIntervalStart: "0s"}, }} - if err := apierRPC.Call(utils.APIerSv1SetTPRate, rt, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetTPRate, rt, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRate: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRate: ", reply) @@ -464,7 +465,7 @@ func testAPIerLoadRatingPlan(t *testing.T) { {DestinationId: "DEST_CUSTOM", RateId: "SAMPLE_RATE_ID", RoundingMethod: "*up", RoundingDecimals: 4}, }} - if err := apierRPC.Call(utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPDestinationRate: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPDestinationRate: ", reply) @@ -476,13 +477,13 @@ func testAPIerLoadRatingPlan(t *testing.T) { Weight: 10}, }} - if err := apierRPC.Call(utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply) } - if err := apierRPC.Call(utils.APIerSv1LoadRatingPlan, &AttrLoadRatingPlan{TPid: "TP_SAMPLE", RatingPlanId: "RPl_SAMPLE_RATING_PLAN"}, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1LoadRatingPlan, &AttrLoadRatingPlan{TPid: "TP_SAMPLE", RatingPlanId: "RPl_SAMPLE_RATING_PLAN"}, &reply); err != nil { t.Error("Got error on APIerSv1.LoadRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.LoadRatingPlan got reply: ", reply) @@ -490,7 +491,7 @@ func testAPIerLoadRatingPlan(t *testing.T) { rpRply := new(engine.RatingPlan) rplnId := "RPl_SAMPLE_RATING_PLAN" - if err := apierRPC.Call(utils.APIerSv1GetRatingPlan, &rplnId, rpRply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1GetRatingPlan, &rplnId, rpRply); err != nil { t.Error("Got error on APIerSv1.GetRatingPlan: ", err.Error()) } @@ -503,7 +504,7 @@ func testAPIerLoadRatingPlan2(t *testing.T) { {DestinationId: "DST_NOT_FOUND", RateId: "SAMPLE_RATE_ID", RoundingMethod: "*up", RoundingDecimals: 4}, }} - if err := apierRPC.Call(utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPDestinationRate: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPDestinationRate: ", reply) @@ -515,13 +516,13 @@ func testAPIerLoadRatingPlan2(t *testing.T) { Weight: 10}, }} - if err := apierRPC.Call(utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply) } - if err := apierRPC.Call(utils.APIerSv1LoadRatingPlan, + if err := apierRPC.Call(context.Background(), utils.APIerSv1LoadRatingPlan, &AttrLoadRatingPlan{TPid: "TP_SAMPLE", RatingPlanId: "RPL_WITH_ERROR"}, &reply); err == nil { t.Error("Expected to get error: ", err) } @@ -543,14 +544,14 @@ func testAPIerLoadRatingProfile(t *testing.T) { }}, } // add a TPRatingProfile - if err := apierRPC.Call(utils.APIerSv1SetTPRatingProfile, rpf, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetTPRatingProfile, rpf, &reply); err != nil { t.Error(err) } // load the TPRatingProfile into dataDB argsRPrf := &utils.TPRatingProfile{ TPid: "TP_SAMPLE", LoadId: "TP_SAMPLE", Tenant: "cgrates.org", Category: "call", Subject: "*any"} - if err := apierRPC.Call(utils.APIerSv1LoadRatingProfile, argsRPrf, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1LoadRatingProfile, argsRPrf, &reply); err != nil { t.Error(err) } @@ -571,7 +572,7 @@ func testAPIerLoadRatingProfile(t *testing.T) { }, }, } - if err := apierRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err) } else if !reflect.DeepEqual(expected, rpl) { t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) @@ -584,13 +585,13 @@ func testAPIerLoadRatingProfile(t *testing.T) { Weight: 10}, }} - if err := apierRPC.Call(utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply) } - if err := apierRPC.Call(utils.APIerSv1LoadRatingPlan, &AttrLoadRatingPlan{TPid: "TP_SAMPLE", RatingPlanId: "RPl_SAMPLE_RATING_PLAN2"}, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1LoadRatingPlan, &AttrLoadRatingPlan{TPid: "TP_SAMPLE", RatingPlanId: "RPl_SAMPLE_RATING_PLAN2"}, &reply); err != nil { t.Error("Got error on APIerSv1.LoadRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.LoadRatingPlan got reply: ", reply) @@ -617,13 +618,13 @@ func testAPIerLoadRatingProfile(t *testing.T) { }, } - if err := apierRPC.Call(utils.APIerSv1SetTPRatingProfile, rpf, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetTPRatingProfile, rpf, &reply); err != nil { t.Error(err) } // load the TPRatingProfile into dataDB // because the RatingProfile exists the RatingPlanActivations will be merged - if err := apierRPC.Call(utils.APIerSv1LoadRatingProfile, argsRPrf, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1LoadRatingProfile, argsRPrf, &reply); err != nil { t.Error(err) } actTime2, err := utils.ParseTimeDetectLayout("2012-02-02T00:00:00Z", utils.EmptyString) @@ -643,7 +644,7 @@ func testAPIerLoadRatingProfile(t *testing.T) { }, }, } - if err := apierRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err) } else if !reflect.DeepEqual(expected, rpl) { t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) @@ -654,12 +655,12 @@ func testAPIerLoadRatingProfile(t *testing.T) { func testAPIerLoadFromFolderAccountAction(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := apierRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) attrs2 := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "account_action_from_tutorial")} - if err := apierRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs2, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs2, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -668,7 +669,7 @@ func testAPIerLoadFromFolderAccountAction(t *testing.T) { Tenant: "cgrates.org", Account: "AccountWithAPFromTutorial", } - if err := apierRPC.Call(utils.APIerSv2GetAccount, attrAcnt, &acnt); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcnt, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != 10.0 { t.Errorf("Expecting: %v, received: %v", @@ -695,7 +696,7 @@ func testApierSetAndRemoveRatingProfileAnySubject(t *testing.T) { Overwrite: true, } var reply string - if err := apierRPC.Call(utils.APIerSv1SetRatingProfile, rpf, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetRatingProfile, rpf, &reply); err != nil { t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply) @@ -713,13 +714,13 @@ func testApierSetAndRemoveRatingProfileAnySubject(t *testing.T) { attrGetRatingPlan := &utils.AttrGetRatingProfile{ Tenant: "cgrates.org", Category: "sms", Subject: utils.MetaAny} var rpl engine.RatingProfile - if err := apierRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err) } else if !reflect.DeepEqual(expected, rpl) { t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) } - if err := apierRPC.Call(utils.APIerSv1RemoveRatingProfile, &AttrRemoveRatingProfile{ + if err := apierRPC.Call(context.Background(), utils.APIerSv1RemoveRatingProfile, &AttrRemoveRatingProfile{ Tenant: "cgrates.org", Category: "sms", Subject: utils.MetaAny, @@ -729,7 +730,7 @@ func testApierSetAndRemoveRatingProfileAnySubject(t *testing.T) { t.Errorf("Expected: %s, received: %s ", utils.OK, reply) } - if err := apierRPC.Call(utils.APIerSv1GetRatingProfile, + if err := apierRPC.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %v, \n but received %v", utils.ErrNotFound, err) } diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go index 3d829a5d4..ba1ea7aac 100644 --- a/apier/v1/apier_it_test.go +++ b/apier/v1/apier_it_test.go @@ -24,7 +24,6 @@ import ( "encoding/json" "fmt" "net/http" - "net/rpc" "net/url" "os" "path" @@ -34,6 +33,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/ees" @@ -63,7 +64,7 @@ README: var ( cfgPath string cfg *config.CGRConfig - rater *rpc.Client + rater *birpc.Client APIerSv1ConfigDIR string apierTests = []func(t *testing.T){ @@ -264,33 +265,33 @@ func testApierTPTiming(t *testing.T) { } var reply string for _, tm := range []*utils.ApierTPTiming{tmAlways, tmAsap, tmAlways2} { - if err := rater.Call(utils.APIerSv1SetTPTiming, &tm, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPTiming, &tm, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPTiming: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPTiming: ", reply) } } // Check second set - if err := rater.Call(utils.APIerSv1SetTPTiming, &tmAlways, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPTiming, &tmAlways, &reply); err != nil { t.Error("Got error on second APIerSv1.SetTPTiming: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetTPTiming got reply: ", reply) } // Check missing params - if err := rater.Call(utils.APIerSv1SetTPTiming, new(utils.ApierTPTiming), &reply); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPTiming, new(utils.ApierTPTiming), &reply); err == nil { t.Error("Calling APIerSv1.SetTPTiming, expected error, received: ", reply) } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID Years Months MonthDays WeekDays Time]" { t.Error("Calling APIerSv1.SetTPTiming got unexpected error: ", err.Error()) } // Test get var rplyTmAlways2 *utils.ApierTPTiming - if err := rater.Call(utils.APIerSv1GetTPTiming, &AttrGetTPTiming{tmAlways2.TPid, tmAlways2.ID}, &rplyTmAlways2); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPTiming, &AttrGetTPTiming{tmAlways2.TPid, tmAlways2.ID}, &rplyTmAlways2); err != nil { t.Error("Calling APIerSv1.GetTPTiming, got error: ", err.Error()) } else if !reflect.DeepEqual(tmAlways2, rplyTmAlways2) { t.Errorf("Calling APIerSv1.GetTPTiming expected: %v, received: %v", tmAlways, rplyTmAlways2) } // Test remove - if err := rater.Call(utils.APIerSv1RemoveTPTiming, AttrGetTPTiming{tmAlways2.TPid, tmAlways2.ID}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveTPTiming, AttrGetTPTiming{tmAlways2.TPid, tmAlways2.ID}, &reply); err != nil { t.Error("Calling APIerSv1.RemoveTPTiming, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.RemoveTPTiming received: ", reply) @@ -298,7 +299,7 @@ func testApierTPTiming(t *testing.T) { // Test getIds var rplyTmIds []string expectedTmIds := []string{"ALWAYS", "ASAP"} - if err := rater.Call(utils.APIerSv1GetTPTimingIds, &AttrGetTPTimingIds{tmAlways.TPid, utils.PaginatorWithSearch{}}, &rplyTmIds); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPTimingIds, &AttrGetTPTimingIds{tmAlways.TPid, utils.PaginatorWithSearch{}}, &rplyTmIds); err != nil { t.Error("Calling APIerSv1.GetTPTimingIds, got error: ", err.Error()) } sort.Strings(expectedTmIds) @@ -318,33 +319,33 @@ func testApierTPDestination(t *testing.T) { *dstDe2 = *dstDe // Data which we use for remove, still keeping the sample data to check proper loading dstDe2.ID = "GERMANY2" for _, dst := range []*utils.TPDestination{dstDe, dstDeMobile, dstFs, dstDe2} { - if err := rater.Call(utils.APIerSv1SetTPDestination, dst, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPDestination, dst, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPDestination: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPDestination: ", reply) } } // Check second set - if err := rater.Call(utils.APIerSv1SetTPDestination, dstDe2, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPDestination, dstDe2, &reply); err != nil { t.Error("Got error on second APIerSv1.SetTPDestination: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetTPDestination got reply: ", reply) } // Check missing params - if err := rater.Call(utils.APIerSv1SetTPDestination, new(utils.TPDestination), &reply); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPDestination, new(utils.TPDestination), &reply); err == nil { t.Error("Calling APIerSv1.SetTPDestination, expected error, received: ", reply) } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID Prefixes]" { t.Error("Calling APIerSv1.SetTPDestination got unexpected error: ", err.Error()) } // Test get var rplyDstDe2 *utils.TPDestination - if err := rater.Call(utils.APIerSv1GetTPDestination, &AttrGetTPDestination{dstDe2.TPid, dstDe2.ID}, &rplyDstDe2); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPDestination, &AttrGetTPDestination{dstDe2.TPid, dstDe2.ID}, &rplyDstDe2); err != nil { t.Error("Calling APIerSv1.GetTPDestination, got error: ", err.Error()) } else if !reflect.DeepEqual(dstDe2, rplyDstDe2) { t.Errorf("Calling APIerSv1.GetTPDestination expected: %v, received: %v", dstDe2, rplyDstDe2) } // Test remove - if err := rater.Call(utils.APIerSv1RemoveTPDestination, &AttrGetTPDestination{dstDe2.TPid, dstDe2.ID}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveTPDestination, &AttrGetTPDestination{dstDe2.TPid, dstDe2.ID}, &reply); err != nil { t.Error("Calling APIerSv1.RemoveTPTiming, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.RemoveTPTiming received: ", reply) @@ -352,7 +353,7 @@ func testApierTPDestination(t *testing.T) { // Test getIds var rplyDstIds []string expectedDstIds := []string{"FS_USERS", "GERMANY", "GERMANY_MOBILE"} - if err := rater.Call(utils.APIerSv1GetTPDestinationIDs, &AttrGetTPDestinationIds{TPid: dstDe.TPid}, &rplyDstIds); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPDestinationIDs, &AttrGetTPDestinationIds{TPid: dstDe.TPid}, &rplyDstIds); err != nil { t.Error("Calling APIerSv1.GetTPDestinationIDs, got error: ", err.Error()) } sort.Strings(expectedDstIds) @@ -372,33 +373,33 @@ func testApierTPRate(t *testing.T) { *rt2 = *rt rt2.ID = "RT_FS_USERS2" for _, r := range []*utils.TPRateRALs{rt, rt2} { - if err := rater.Call(utils.APIerSv1SetTPRate, r, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPRate, r, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRate: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRate: ", reply) } } // Check second set - if err := rater.Call(utils.APIerSv1SetTPRate, rt2, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPRate, rt2, &reply); err != nil { t.Error("Got error on second APIerSv1.SetTPRate: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetTPRate got reply: ", reply) } // Check missing params - if err := rater.Call(utils.APIerSv1SetTPRate, new(utils.TPRateRALs), &reply); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPRate, new(utils.TPRateRALs), &reply); err == nil { t.Error("Calling APIerSv1.SetTPDestination, expected error, received: ", reply) } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID RateSlots]" { t.Error("Calling APIerSv1.SetTPRate got unexpected error: ", err.Error()) } // Test get var rplyRt2 *utils.TPRateRALs - if err := rater.Call(utils.APIerSv1GetTPRate, &AttrGetTPRate{rt2.TPid, rt2.ID}, &rplyRt2); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPRate, &AttrGetTPRate{rt2.TPid, rt2.ID}, &rplyRt2); err != nil { t.Error("Calling APIerSv1.GetTPRate, got error: ", err.Error()) } else if !reflect.DeepEqual(rt2, rplyRt2) { t.Errorf("Calling APIerSv1.GetTPRate expected: %+v, received: %+v", rt2, rplyRt2) } // Test remove - if err := rater.Call(utils.APIerSv1RemoveTPRate, &AttrGetTPRate{rt2.TPid, rt2.ID}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveTPRate, &AttrGetTPRate{rt2.TPid, rt2.ID}, &reply); err != nil { t.Error("Calling APIerSv1.RemoveTPRate, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.RemoveTPRate received: ", reply) @@ -406,7 +407,7 @@ func testApierTPRate(t *testing.T) { // Test getIds var rplyRtIds []string expectedRtIds := []string{"RT_FS_USERS"} - if err := rater.Call(utils.APIerSv1GetTPRateIds, &AttrGetTPRateIds{rt.TPid, utils.PaginatorWithSearch{}}, &rplyRtIds); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPRateIds, &AttrGetTPRateIds{rt.TPid, utils.PaginatorWithSearch{}}, &rplyRtIds); err != nil { t.Error("Calling APIerSv1.GetTPRateIds, got error: ", err.Error()) } else if !reflect.DeepEqual(expectedRtIds, rplyRtIds) { t.Errorf("Calling APIerSv1.GetTPDestinationIDs expected: %v, received: %v", expectedRtIds, rplyRtIds) @@ -426,33 +427,33 @@ func testApierTPDestinationRate(t *testing.T) { *dr2 = *dr dr2.ID = utils.TestSQL for _, d := range []*utils.TPDestinationRate{dr, dr2, drDe} { - if err := rater.Call(utils.APIerSv1SetTPDestinationRate, d, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPDestinationRate, d, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPDestinationRate: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPDestinationRate: ", reply) } } // Check second set - if err := rater.Call(utils.APIerSv1SetTPDestinationRate, dr2, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPDestinationRate, dr2, &reply); err != nil { t.Error("Got error on second APIerSv1.SetTPDestinationRate: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetTPDestinationRate got reply: ", reply) } // Check missing params - if err := rater.Call(utils.APIerSv1SetTPDestinationRate, new(utils.TPDestinationRate), &reply); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPDestinationRate, new(utils.TPDestinationRate), &reply); err == nil { t.Error("Calling APIerSv1.SetTPDestination, expected error, received: ", reply) } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID DestinationRates]" { t.Error("Calling APIerSv1.SetTPDestinationRate got unexpected error: ", err.Error()) } // Test get var rplyDr2 *utils.TPDestinationRate - if err := rater.Call(utils.APIerSv1GetTPDestinationRate, &AttrGetTPDestinationRate{dr2.TPid, dr2.ID, utils.Paginator{}}, &rplyDr2); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPDestinationRate, &AttrGetTPDestinationRate{dr2.TPid, dr2.ID, utils.Paginator{}}, &rplyDr2); err != nil { t.Error("Calling APIerSv1.GetTPDestinationRate, got error: ", err.Error()) } else if !reflect.DeepEqual(dr2, rplyDr2) { t.Errorf("Calling APIerSv1.GetTPDestinationRate expected: %v, received: %v", dr2, rplyDr2) } // Test remove - if err := rater.Call(utils.APIerSv1RemoveTPDestinationRate, &AttrGetTPDestinationRate{dr2.TPid, dr2.ID, utils.Paginator{}}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveTPDestinationRate, &AttrGetTPDestinationRate{dr2.TPid, dr2.ID, utils.Paginator{}}, &reply); err != nil { t.Error("Calling APIerSv1.RemoveTPRate, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.RemoveTPRate received: ", reply) @@ -460,7 +461,7 @@ func testApierTPDestinationRate(t *testing.T) { // Test getIds var rplyDrIds []string expectedDrIds := []string{"DR_FREESWITCH_USERS"} - if err := rater.Call(utils.APIerSv1GetTPDestinationRateIds, &AttrTPDestinationRateIds{dr.TPid, utils.PaginatorWithSearch{}}, &rplyDrIds); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPDestinationRateIds, &AttrTPDestinationRateIds{dr.TPid, utils.PaginatorWithSearch{}}, &rplyDrIds); err != nil { t.Error("Calling APIerSv1.GetTPDestinationRateIds, got error: ", err.Error()) } else if !reflect.DeepEqual(expectedDrIds, rplyDrIds) { t.Errorf("Calling APIerSv1.GetTPDestinationRateIds expected: %v, received: %v", expectedDrIds, rplyDrIds) @@ -477,33 +478,33 @@ func testApierTPRatingPlan(t *testing.T) { *rpTst = *rp rpTst.ID = utils.TestSQL for _, rpl := range []*utils.TPRatingPlan{rp, rpTst} { - if err := rater.Call(utils.APIerSv1SetTPRatingPlan, rpl, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPRatingPlan, rpl, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply) } } // Check second set - if err := rater.Call(utils.APIerSv1SetTPRatingPlan, rpTst, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPRatingPlan, rpTst, &reply); err != nil { t.Error("Got error on second APIerSv1.SetTPRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetTPRatingPlan got reply: ", reply) } // Check missing params - if err := rater.Call(utils.APIerSv1SetTPRatingPlan, new(utils.TPRatingPlan), &reply); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPRatingPlan, new(utils.TPRatingPlan), &reply); err == nil { t.Error("Calling APIerSv1.SetTPRatingPlan, expected error, received: ", reply) } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID RatingPlanBindings]" { t.Error("Calling APIerSv1.SetTPRatingPlan got unexpected error: ", err.Error()) } // Test get var rplyRpTst *utils.TPRatingPlan - if err := rater.Call(utils.APIerSv1GetTPRatingPlan, &AttrGetTPRatingPlan{TPid: rpTst.TPid, ID: rpTst.ID}, &rplyRpTst); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPRatingPlan, &AttrGetTPRatingPlan{TPid: rpTst.TPid, ID: rpTst.ID}, &rplyRpTst); err != nil { t.Error("Calling APIerSv1.GetTPRatingPlan, got error: ", err.Error()) } else if !reflect.DeepEqual(rpTst, rplyRpTst) { t.Errorf("Calling APIerSv1.GetTPRatingPlan expected: %v, received: %v", rpTst, rplyRpTst) } // Test remove - if err := rater.Call(utils.APIerSv1RemoveTPRatingPlan, &AttrGetTPRatingPlan{TPid: rpTst.TPid, ID: rpTst.ID}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveTPRatingPlan, &AttrGetTPRatingPlan{TPid: rpTst.TPid, ID: rpTst.ID}, &reply); err != nil { t.Error("Calling APIerSv1.RemoveTPRatingPlan, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.RemoveTPRatingPlan received: ", reply) @@ -511,7 +512,7 @@ func testApierTPRatingPlan(t *testing.T) { // Test getIds var rplyRpIds []string expectedRpIds := []string{"RETAIL1"} - if err := rater.Call(utils.APIerSv1GetTPRatingPlanIds, &AttrGetTPRatingPlanIds{rp.TPid, utils.PaginatorWithSearch{}}, &rplyRpIds); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPRatingPlanIds, &AttrGetTPRatingPlanIds{rp.TPid, utils.PaginatorWithSearch{}}, &rplyRpIds); err != nil { t.Error("Calling APIerSv1.GetTPRatingPlanIds, got error: ", err.Error()) } else if !reflect.DeepEqual(expectedRpIds, rplyRpIds) { t.Errorf("Calling APIerSv1.GetTPRatingPlanIds expected: %v, received: %v", expectedRpIds, rplyRpIds) @@ -537,33 +538,33 @@ func testApierTPRatingProfile(t *testing.T) { *rpfTst = *rpf rpfTst.Subject = utils.TestSQL for _, rp := range []*utils.TPRatingProfile{rpf, rpfTst} { - if err := rater.Call(utils.APIerSv1SetTPRatingProfile, rp, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPRatingProfile, rp, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingProfile: ", reply) } } // Check second set - if err := rater.Call(utils.APIerSv1SetTPRatingProfile, rpfTst, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPRatingProfile, rpfTst, &reply); err != nil { t.Error("Got error on second APIerSv1.SetTPRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetTPRatingProfile got reply: ", reply) } // Check missing params - if err := rater.Call(utils.APIerSv1SetTPRatingProfile, new(utils.TPRatingProfile), &reply); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPRatingProfile, new(utils.TPRatingProfile), &reply); err == nil { t.Error("Calling APIerSv1.SetTPRatingProfile, expected error, received: ", reply) } else if err.Error() != "MANDATORY_IE_MISSING: [TPid LoadId Category Subject RatingPlanActivations]" { t.Error("Calling APIerSv1.SetTPRatingProfile got unexpected error: ", err.Error()) } // Test get var rplyRpf *utils.TPRatingProfile - if err := rater.Call(utils.APIerSv1GetTPRatingProfile, &AttrGetTPRatingProfile{TPid: rpfTst.TPid, RatingProfileID: utils.ConcatenatedKey(rpfTst.LoadId, rpfTst.Tenant, rpfTst.Category, rpfTst.Subject)}, &rplyRpf); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPRatingProfile, &AttrGetTPRatingProfile{TPid: rpfTst.TPid, RatingProfileID: utils.ConcatenatedKey(rpfTst.LoadId, rpfTst.Tenant, rpfTst.Category, rpfTst.Subject)}, &rplyRpf); err != nil { t.Error("Calling APIerSv1.GetTPRatingProfiles, got error: ", err.Error()) } else if !reflect.DeepEqual(rpfTst, rplyRpf) { t.Errorf("Calling APIerSv1.GetTPRatingProfiles expected: %v, received: %v", rpfTst, rplyRpf) } // Test remove - if err := rater.Call(utils.APIerSv1RemoveTPRatingProfile, &AttrGetTPRatingProfile{TPid: rpfTst.TPid, RatingProfileID: utils.ConcatenatedKey(rpfTst.LoadId, rpfTst.Tenant, rpfTst.Category, rpfTst.Subject)}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveTPRatingProfile, &AttrGetTPRatingProfile{TPid: rpfTst.TPid, RatingProfileID: utils.ConcatenatedKey(rpfTst.LoadId, rpfTst.Tenant, rpfTst.Category, rpfTst.Subject)}, &reply); err != nil { t.Error("Calling APIerSv1.RemoveTPRatingProfile, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.RemoveTPRatingProfile received: ", reply) @@ -571,7 +572,7 @@ func testApierTPRatingProfile(t *testing.T) { // Test getLoadIds var rplyRpIds []string expectedRpIds := []string{utils.TestSQL} - if err := rater.Call(utils.APIerSv1GetTPRatingProfileLoadIds, &utils.AttrTPRatingProfileIds{TPid: rpf.TPid}, &rplyRpIds); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPRatingProfileLoadIds, &utils.AttrTPRatingProfileIds{TPid: rpf.TPid}, &rplyRpIds); err != nil { t.Error("Calling APIerSv1.GetTPRatingProfileLoadIds, got error: ", err.Error()) } else if !reflect.DeepEqual(expectedRpIds, rplyRpIds) { t.Errorf("Calling APIerSv1.GetTPRatingProfileLoadIds expected: %v, received: %v", expectedRpIds, rplyRpIds) @@ -596,33 +597,33 @@ func testApierTPActions(t *testing.T) { *actTst = *act actTst.ID = utils.TestSQL for _, ac := range []*utils.TPActions{act, actWarn, actTst, actLog} { - if err := rater.Call(utils.APIerSv1SetTPActions, ac, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPActions, ac, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPActions: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPActions: ", reply) } } // Check second set - if err := rater.Call(utils.APIerSv1SetTPActions, actTst, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPActions, actTst, &reply); err != nil { t.Error("Got error on second APIerSv1.SetTPActions: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetTPActions got reply: ", reply) } // Check missing params - if err := rater.Call(utils.APIerSv1SetTPActions, new(utils.TPActions), &reply); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPActions, new(utils.TPActions), &reply); err == nil { t.Error("Calling APIerSv1.SetTPActions, expected error, received: ", reply) } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID Actions]" { t.Error("Calling APIerSv1.SetTPActions got unexpected error: ", err.Error()) } // Test get var rplyActs *utils.TPActions - if err := rater.Call(utils.APIerSv1GetTPActions, &AttrGetTPActions{TPid: actTst.TPid, ID: actTst.ID}, &rplyActs); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPActions, &AttrGetTPActions{TPid: actTst.TPid, ID: actTst.ID}, &rplyActs); err != nil { t.Error("Calling APIerSv1.GetTPActions, got error: ", err.Error()) } else if !reflect.DeepEqual(actTst, rplyActs) { t.Errorf("Calling APIerSv1.GetTPActions expected: %v, received: %v", actTst, rplyActs) } // Test remove - if err := rater.Call(utils.APIerSv1RemoveTPActions, &AttrGetTPActions{TPid: actTst.TPid, ID: actTst.ID}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveTPActions, &AttrGetTPActions{TPid: actTst.TPid, ID: actTst.ID}, &reply); err != nil { t.Error("Calling APIerSv1.RemoveTPActions, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.RemoveTPActions received: ", reply) @@ -630,7 +631,7 @@ func testApierTPActions(t *testing.T) { // Test getIds var rplyIds []string expectedIds := []string{"LOG_BALANCE", "PREPAID_10", "WARN_VIA_HTTP"} - if err := rater.Call(utils.APIerSv1GetTPActionIds, &AttrGetTPActionIds{TPid: actTst.TPid}, &rplyIds); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPActionIds, &AttrGetTPActionIds{TPid: actTst.TPid}, &rplyIds); err != nil { t.Error("Calling APIerSv1.GetTPActionIds, got error: ", err.Error()) } sort.Strings(expectedIds) @@ -649,33 +650,33 @@ func testApierTPActionPlan(t *testing.T) { *atTst = *at atTst.ID = utils.TestSQL for _, act := range []*utils.TPActionPlan{at, atTst} { - if err := rater.Call(utils.APIerSv1SetTPActionPlan, act, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPActionPlan, act, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPActionPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPActionPlan: ", reply) } } // Check second set - if err := rater.Call(utils.APIerSv1SetTPActionPlan, atTst, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPActionPlan, atTst, &reply); err != nil { t.Error("Got error on second APIerSv1.SetTPActionPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetTPActionPlan got reply: ", reply) } // Check missing params - if err := rater.Call(utils.APIerSv1SetTPActionPlan, new(utils.TPActionPlan), &reply); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPActionPlan, new(utils.TPActionPlan), &reply); err == nil { t.Error("Calling APIerSv1.SetTPActionPlan, expected error, received: ", reply) } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID ActionPlan]" { t.Error("Calling APIerSv1.SetTPActionPlan got unexpected error: ", err.Error()) } // Test get var rplyActs *utils.TPActionPlan - if err := rater.Call(utils.APIerSv1GetTPActionPlan, &AttrGetTPActionPlan{TPid: atTst.TPid, ID: atTst.ID}, &rplyActs); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPActionPlan, &AttrGetTPActionPlan{TPid: atTst.TPid, ID: atTst.ID}, &rplyActs); err != nil { t.Error("Calling APIerSv1.GetTPActionPlan, got error: ", err.Error()) } else if !reflect.DeepEqual(atTst, rplyActs) { t.Errorf("Calling APIerSv1.GetTPActionPlan expected: %v, received: %v", atTst, rplyActs) } // Test remove - if err := rater.Call(utils.APIerSv1RemoveTPActionPlan, &AttrGetTPActionPlan{TPid: atTst.TPid, ID: atTst.ID}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveTPActionPlan, &AttrGetTPActionPlan{TPid: atTst.TPid, ID: atTst.ID}, &reply); err != nil { t.Error("Calling APIerSv1.RemoveTPActionPlan, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.RemoveTPActionPlan received: ", reply) @@ -683,7 +684,7 @@ func testApierTPActionPlan(t *testing.T) { // Test getIds var rplyIds []string expectedIds := []string{"PREPAID_10"} - if err := rater.Call(utils.APIerSv1GetTPActionPlanIds, &AttrGetTPActionPlanIds{TPid: atTst.TPid}, &rplyIds); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPActionPlanIds, &AttrGetTPActionPlanIds{TPid: atTst.TPid}, &rplyIds); err != nil { t.Error("Calling APIerSv1.GetTPActionPlanIds, got error: ", err.Error()) } else if !reflect.DeepEqual(expectedIds, rplyIds) { t.Errorf("Calling APIerSv1.GetTPActionPlanIds expected: %v, received: %v", expectedIds, rplyIds) @@ -710,33 +711,33 @@ func testApierTPActionTriggers(t *testing.T) { atTst.ID = utils.TestSQL atTst.ActionTriggers[0].Id = utils.TestSQL for _, act := range []*utils.TPActionTriggers{at, atTst} { - if err := rater.Call(utils.APIerSv1SetTPActionTriggers, act, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPActionTriggers, act, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPActionTriggers: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPActionTriggers: ", reply) } } // Check second set - if err := rater.Call(utils.APIerSv1SetTPActionTriggers, atTst, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPActionTriggers, atTst, &reply); err != nil { t.Error("Got error on second APIerSv1.SetTPActionTriggers: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetTPActionTriggers got reply: ", reply) } // Check missing params - if err := rater.Call(utils.APIerSv1SetTPActionTriggers, new(utils.TPActionTriggers), &reply); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPActionTriggers, new(utils.TPActionTriggers), &reply); err == nil { t.Error("Calling APIerSv1.SetTPActionTriggers, expected error, received: ", reply) } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID]" { t.Error("Calling APIerSv1.SetTPActionTriggers got unexpected error: ", err.Error()) } // Test get var rplyActs *utils.TPActionTriggers - if err := rater.Call(utils.APIerSv1GetTPActionTriggers, &AttrGetTPActionTriggers{TPid: atTst.TPid, ID: atTst.ID}, &rplyActs); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPActionTriggers, &AttrGetTPActionTriggers{TPid: atTst.TPid, ID: atTst.ID}, &rplyActs); err != nil { t.Errorf("Calling APIerSv1.GetTPActionTriggers %s, got error: %s", atTst.ID, err.Error()) } else if !reflect.DeepEqual(atTst, rplyActs) { t.Errorf("Calling APIerSv1.GetTPActionTriggers expected: %+v, received: %+v", utils.ToJSON(atTst), utils.ToJSON(rplyActs)) } // Test remove - if err := rater.Call(utils.APIerSv1RemoveTPActionTriggers, &AttrGetTPActionTriggers{TPid: atTst.TPid, ID: atTst.ID}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveTPActionTriggers, &AttrGetTPActionTriggers{TPid: atTst.TPid, ID: atTst.ID}, &reply); err != nil { t.Error("Calling APIerSv1.RemoveTPActionTriggers, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.RemoveTPActionTriggers received: ", reply) @@ -744,7 +745,7 @@ func testApierTPActionTriggers(t *testing.T) { // Test getIds var rplyIds []string expectedIds := []string{"STANDARD_TRIGGERS"} - if err := rater.Call(utils.APIerSv1GetTPActionTriggerIds, &AttrGetTPActionTriggerIds{TPid: atTst.TPid}, &rplyIds); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPActionTriggerIds, &AttrGetTPActionTriggerIds{TPid: atTst.TPid}, &rplyIds); err != nil { t.Error("Calling APIerSv1.GetTPActionTriggerIds, got error: ", err.Error()) } else if !reflect.DeepEqual(expectedIds, rplyIds) { t.Errorf("Calling APIerSv1.GetTPActionTriggerIds expected: %v, received: %v", expectedIds, rplyIds) @@ -768,33 +769,33 @@ func testApierTPAccountActions(t *testing.T) { *aaTst = *aa1 aaTst.Account = utils.TestSQL for _, aact := range []*utils.TPAccountActions{aa1, aa2, aa3, aa4, aa5, aaTst} { - if err := rater.Call(utils.APIerSv1SetTPAccountActions, aact, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPAccountActions, aact, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPAccountActions: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPAccountActions: ", reply) } } // Check second set - if err := rater.Call(utils.APIerSv1SetTPAccountActions, aaTst, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPAccountActions, aaTst, &reply); err != nil { t.Error("Got error on second APIerSv1.SetTPAccountActions: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetTPAccountActions got reply: ", reply) } // Check missing params - if err := rater.Call(utils.APIerSv1SetTPAccountActions, new(utils.TPAccountActions), &reply); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetTPAccountActions, new(utils.TPAccountActions), &reply); err == nil { t.Error("Calling APIerSv1.SetTPAccountActions, expected error, received: ", reply) } else if err.Error() != "MANDATORY_IE_MISSING: [TPid LoadId Account ActionPlanId]" { t.Error("Calling APIerSv1.SetTPAccountActions got unexpected error: ", err.Error()) } // Test get var rplyaa *utils.TPAccountActions - if err := rater.Call(utils.APIerSv1GetTPAccountActions, &AttrGetTPAccountActions{TPid: aaTst.TPid, AccountActionsId: aaTst.GetId()}, &rplyaa); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPAccountActions, &AttrGetTPAccountActions{TPid: aaTst.TPid, AccountActionsId: aaTst.GetId()}, &rplyaa); err != nil { t.Error("Calling APIerSv1.GetTPAccountActions, got error: ", err.Error()) } else if !reflect.DeepEqual(aaTst, rplyaa) { t.Errorf("Calling APIerSv1.GetTPAccountActions expected: %v, received: %v", aaTst, rplyaa) } // Test remove - if err := rater.Call(utils.APIerSv1RemoveTPAccountActions, &AttrGetTPAccountActions{TPid: aaTst.TPid, AccountActionsId: aaTst.GetId()}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveTPAccountActions, &AttrGetTPAccountActions{TPid: aaTst.TPid, AccountActionsId: aaTst.GetId()}, &reply); err != nil { t.Error("Calling APIerSv1.RemoveTPAccountActions, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.RemoveTPAccountActions received: ", reply) @@ -802,7 +803,7 @@ func testApierTPAccountActions(t *testing.T) { // Test getLoadIds var rplyRpIds []string expectedRpIds := []string{utils.TestSQL} - if err := rater.Call(utils.APIerSv1GetTPAccountActionLoadIds, &AttrGetTPAccountActionIds{TPid: aaTst.TPid}, &rplyRpIds); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetTPAccountActionLoadIds, &AttrGetTPAccountActionIds{TPid: aaTst.TPid}, &rplyRpIds); err != nil { t.Error("Calling APIerSv1.GetTPAccountActionLoadIds, got error: ", err.Error()) } else if !reflect.DeepEqual(expectedRpIds, rplyRpIds) { t.Errorf("Calling APIerSv1.GetTPAccountActionLoadIds expected: %v, received: %v", expectedRpIds, rplyRpIds) @@ -812,7 +813,7 @@ func testApierTPAccountActions(t *testing.T) { // Test here LoadRatingPlan func testApierLoadRatingPlan(t *testing.T) { var reply string - if err := rater.Call(utils.APIerSv1LoadRatingPlan, &AttrLoadRatingPlan{TPid: utils.TestSQL, RatingPlanId: "RETAIL1"}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1LoadRatingPlan, &AttrLoadRatingPlan{TPid: utils.TestSQL, RatingPlanId: "RETAIL1"}, &reply); err != nil { t.Error("Got error on APIerSv1.LoadRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.LoadRatingPlan got reply: ", reply) @@ -825,7 +826,7 @@ func testApierLoadRatingProfile(t *testing.T) { rpf := &utils.TPRatingProfile{ TPid: utils.TestSQL, LoadId: utils.TestSQL, Tenant: "cgrates.org", Category: "call", Subject: "*any"} - if err := rater.Call(utils.APIerSv1LoadRatingProfile, &rpf, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1LoadRatingProfile, &rpf, &reply); err != nil { t.Error("Got error on APIerSv1.LoadRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.LoadRatingProfile got reply: ", reply) @@ -837,7 +838,7 @@ func testApierLoadRatingProfileWithoutTenant(t *testing.T) { rpf := &utils.TPRatingProfile{ TPid: utils.TestSQL, LoadId: utils.TestSQL, Category: "call", Subject: "*any"} - if err := rater.Call(utils.APIerSv1LoadRatingProfile, &rpf, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1LoadRatingProfile, &rpf, &reply); err != nil { t.Error("Got error on APIerSv1.LoadRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.LoadRatingProfile got reply: ", reply) @@ -850,14 +851,14 @@ func testApierLoadAccountActions(t *testing.T) { expectedStats := engine.GetDefaultEmptyCacheStats() // Make sure nothing in cache so far expectedStats[utils.CacheLoadIDs].Items = 2 // we loaded the ratingprofiles expectedStats[utils.CacheRPCConnections].Items = 1 - if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { t.Errorf("Calling CacheSv1.GetCacheStats expected: %+v,\n received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats)) } var reply string aa1 := &utils.TPAccountActions{TPid: utils.TestSQL, LoadId: utils.TestSQL, Tenant: "cgrates.org", Account: "1001"} - if err := rater.Call(utils.APIerSv1LoadAccountActions, aa1, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1LoadAccountActions, aa1, &reply); err != nil { t.Error("Got error on APIerSv1.LoadAccountActions: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.LoadAccountActions got reply: ", reply) @@ -868,7 +869,7 @@ func testApierLoadAccountActions(t *testing.T) { expectedStats[utils.CacheActions].Items = 1 expectedStats[utils.CacheLoadIDs].Items = 6 expectedStats[utils.CacheRPCConnections].Items = 1 - if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { t.Errorf("Calling CacheSv1.GetCacheStats expected: %+v, \n received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats)) @@ -879,7 +880,7 @@ func testApierLoadAccountActions(t *testing.T) { func testApierReloadScheduler(t *testing.T) { var reply string // Simple test that command is executed without errors - if err := rater.Call(utils.SchedulerSv1Reload, utils.StringWithAPIOpts{}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.SchedulerSv1Reload, utils.StringWithAPIOpts{}, &reply); err != nil { t.Error("Got error on SchedulerSv1.Reload: ", err.Error()) } else if reply != utils.OK { t.Error("Calling SchedulerSv1.Reload got reply: ", reply) @@ -892,7 +893,7 @@ func testApierSetRatingProfile(t *testing.T) { rpa := &utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1", FallbackSubjects: "dan2"} rpf := &utils.AttrSetRatingProfile{Tenant: "cgrates.org", Category: "call", Subject: "dan", RatingPlanActivations: []*utils.TPRatingActivation{rpa}} - if err := rater.Call(utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply) @@ -905,13 +906,13 @@ func testApierSetRatingProfile(t *testing.T) { expectedStats[utils.CacheRatingProfiles].Items = 1 expectedStats[utils.CacheRPCConnections].Items = 1 expectedStats[utils.CacheLoadIDs].Items = 6 - if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { t.Errorf("Calling CacheSv1.GetCacheStats expected: %+v, received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats)) } // Calling the second time should not raise EXISTS - if err := rater.Call(utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { t.Error("Unexpected result on duplication: ", err.Error()) } // Make sure rates were loaded for account dan @@ -932,14 +933,14 @@ func testApierSetRatingProfile(t *testing.T) { } var cc engine.CallCost // Simple test that command is executed without errors - if err := rater.Call(utils.ResponderGetCost, cd, &cc); err != nil { + if err := rater.Call(context.Background(), utils.ResponderGetCost, cd, &cc); err != nil { t.Error("Got error on Responder.GetCost: ", err.Error()) } else if cc.Cost != 0 { t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost) } expectedStats[utils.CacheRatingPlans].Items = 1 expectedStats[utils.CacheReverseDestinations].Items = 10 - if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { t.Errorf("Calling CacheSv1.GetCacheStats expected: %+v, received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats)) @@ -969,24 +970,24 @@ func testAPIerSv1GetRatingProfile(t *testing.T) { }, }, } - if err := rater.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err) } else if !reflect.DeepEqual(expected, rpl) { t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) } attrGetRatingPlan.Subject = utils.EmptyString - if err := rater.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err == nil { t.Errorf("Expected error on APIerSv1.GetRatingProfile, received : %+v", rpl) } attrGetRatingPlan.Subject = "dan" attrGetRatingPlan.Tenant = "other_tenant" - if err := rater.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err.Error() != utils.ErrNotFound.Error() { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error on APIerSv1.GetRatingProfile, received : %+v", err) } expectedIds := []string{"call:dan", "call:*any"} var result []string - if err := rater.Call(utils.APIerSv1GetRatingProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { t.Error(err) } else if len(expectedIds) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) @@ -996,7 +997,7 @@ func testAPIerSv1GetRatingProfile(t *testing.T) { func testAPIerSv1GetRatingProfileIDsWithoutTenant(t *testing.T) { expectedIds := []string{"call:dan", "call:*any"} var result []string - if err := rater.Call(utils.APIerSv1GetRatingProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil { t.Error(err) } else { sort.Strings(expectedIds) @@ -1030,7 +1031,7 @@ func testAPIerSv1GetRatingProfileWithoutTenant(t *testing.T) { }, }, } - if err := rater.Call(utils.APIerSv1GetRatingProfile, &attrGetRatingPlan, &rpl); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfile, &attrGetRatingPlan, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rpl) { t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v \n, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) @@ -1040,14 +1041,14 @@ func testAPIerSv1GetRatingProfileWithoutTenant(t *testing.T) { func testApierGetActionTrigger(t *testing.T) { //nothing to get from database var atrs *engine.ActionTriggers - if err := rater.Call(utils.APIerSv1GetActionTriggers, + if err := rater.Call(context.Background(), utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TEST_ID1"}}, &atrs); err.Error() != utils.ErrNotFound.Error() { t.Error(err) } //set an ActionTrigger in database var reply string - if err := rater.Call(utils.APIerSv1SetActionTrigger, + if err := rater.Call(context.Background(), utils.APIerSv1SetActionTrigger, AttrSetActionTrigger{ GroupID: "TEST_ID1", UniqueID: "TEST_ID2", @@ -1063,7 +1064,7 @@ func testApierGetActionTrigger(t *testing.T) { Balance: &engine.BalanceFilter{}, }, } - if err := rater.Call(utils.APIerSv1GetActionTriggers, + if err := rater.Call(context.Background(), utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TEST_ID1"}}, &atrs); err != nil { t.Error(err) } else if !reflect.DeepEqual(newActTrg, atrs) { @@ -1071,7 +1072,7 @@ func testApierGetActionTrigger(t *testing.T) { } //remove the ActionTrigger from dataBase - if err := rater.Call(utils.APIerSv1RemoveActionTrigger, + if err := rater.Call(context.Background(), utils.APIerSv1RemoveActionTrigger, &AttrRemoveActionTrigger{GroupID: "TEST_ID1"}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -1079,7 +1080,7 @@ func testApierGetActionTrigger(t *testing.T) { } //nothing to get from dataBase - if err := rater.Call(utils.APIerSv1GetActionTriggers, + if err := rater.Call(context.Background(), utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TEST_ID1"}}, &atrs); err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -1090,7 +1091,7 @@ func testApierReloadCache(t *testing.T) { var reply string arc := new(utils.AttrReloadCacheWithAPIOpts) // Simple test that command is executed without errors - if err := rater.Call(utils.CacheSv1ReloadCache, arc, &reply); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1ReloadCache, arc, &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Error("Calling CacheSv1.ReloadCache got reply: ", reply) @@ -1105,7 +1106,7 @@ func testApierReloadCache(t *testing.T) { expectedStats[utils.CacheReverseDestinations].Items = 10 expectedStats[utils.CacheLoadIDs].Items = 6 expectedStats[utils.CacheRPCConnections].Items = 1 - if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { t.Errorf("Calling CacheSv1.GetCacheStats expected: %+v,\n received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats)) @@ -1117,7 +1118,7 @@ func testApierGetDestination(t *testing.T) { reply := new(engine.Destination) dstId := "GERMANY_MOBILE" expectedReply := &engine.Destination{Id: dstId, Prefixes: []string{"+4915", "+4916", "+4917"}} - if err := rater.Call(utils.APIerSv1GetDestination, &dstId, reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetDestination, &dstId, reply); err != nil { t.Error("Got error on APIerSv1.GetDestination: ", err.Error()) } else if !reflect.DeepEqual(expectedReply, reply) { t.Errorf("Calling APIerSv1.GetDestination expected: %v, received: %v", expectedReply, reply) @@ -1128,7 +1129,7 @@ func testApierGetDestination(t *testing.T) { func testApierGetRatingPlan(t *testing.T) { reply := new(engine.RatingPlan) rplnId := "RETAIL1" - if err := rater.Call(utils.APIerSv1GetRatingPlan, &rplnId, reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingPlan, &rplnId, reply); err != nil { t.Error("Got error on APIerSv1.GetRatingPlan: ", err.Error()) } // Check parts of info received since a full one is not possible due to unique map keys inside reply @@ -1154,7 +1155,7 @@ func testApierRemoveRatingPlan(t *testing.T) { rplnId := "RETAIL1" var reply string - err := rater.Call(utils.APIerSv1RemoveRatingPlan, &rplnId, &reply) + err := rater.Call(context.Background(), utils.APIerSv1RemoveRatingPlan, &rplnId, &reply) if err != nil { t.Error(err) } @@ -1163,7 +1164,7 @@ func testApierRemoveRatingPlan(t *testing.T) { } //get rating plan (the one that was removed. should return 'err not found') var ratingPlan *engine.RatingPlan - err = rater.Call(utils.APIerSv1GetRatingPlan, &rplnId, ratingPlan) + err = rater.Call(context.Background(), utils.APIerSv1GetRatingPlan, &rplnId, ratingPlan) if err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting error: %s, received: %v", utils.ErrNotFound, err) } @@ -1173,43 +1174,43 @@ func testApierRemoveRatingPlan(t *testing.T) { func testApierAddBalance(t *testing.T) { var reply string attrs := &AttrAddBalance{Tenant: "cgrates.org", Account: "1001", BalanceType: utils.MetaMonetary, Value: 1.5} - if err := rater.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) } attrs = &AttrAddBalance{Tenant: "cgrates.org", Account: "dan", BalanceType: utils.MetaMonetary, Value: 1.5} - if err := rater.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) } attrs = &AttrAddBalance{Tenant: "cgrates.org", Account: "dan2", BalanceType: utils.MetaMonetary, Value: 1.5} - if err := rater.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) } attrs = &AttrAddBalance{Tenant: "cgrates.org", Account: "dan3", BalanceType: utils.MetaMonetary, Value: 1.5} - if err := rater.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) } attrs = &AttrAddBalance{Tenant: "cgrates.org", Account: "dan3", BalanceType: utils.MetaMonetary, Value: 2.1} - if err := rater.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) } attrs = &AttrAddBalance{Tenant: "cgrates.org", Account: "dan6", BalanceType: utils.MetaMonetary, Value: 2.1} - if err := rater.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) } attrs = &AttrAddBalance{Tenant: "cgrates.org", Account: "dan6", BalanceType: utils.MetaMonetary, Value: 1, Overwrite: true} - if err := rater.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -1222,7 +1223,7 @@ func testApierExecuteAction(t *testing.T) { var reply string // Add balance to a previously known account attrs := utils.AttrExecuteAction{Tenant: "cgrates.org", Account: "dan2", ActionsId: "PREPAID_10"} - if err := rater.Call(utils.APIerSv1ExecuteAction, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1ExecuteAction, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) @@ -1230,7 +1231,7 @@ func testApierExecuteAction(t *testing.T) { reply2 := utils.EmptyString // Add balance to an account which does n exist attrs = utils.AttrExecuteAction{Tenant: "cgrates.org", Account: "dan2", ActionsId: "DUMMY_ACTION"} - if err := rater.Call(utils.APIerSv1ExecuteAction, attrs, &reply2); err == nil || reply2 == utils.OK { + if err := rater.Call(context.Background(), utils.APIerSv1ExecuteAction, attrs, &reply2); err == nil || reply2 == utils.OK { t.Error("Expecting error on APIerSv1.ExecuteAction.", err, reply2) } } @@ -1239,7 +1240,7 @@ func testApierExecuteActionWithoutTenant(t *testing.T) { var reply string // Add balance to a previously known account attrs := utils.AttrExecuteAction{Account: "dan2", ActionsId: "PREPAID_10"} - if err := rater.Call(utils.APIerSv1ExecuteAction, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1ExecuteAction, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) @@ -1247,7 +1248,7 @@ func testApierExecuteActionWithoutTenant(t *testing.T) { reply2 := utils.EmptyString // Add balance to an account which does n exist attrs = utils.AttrExecuteAction{Account: "dan2", ActionsId: "DUMMY_ACTION"} - if err := rater.Call(utils.APIerSv1ExecuteAction, attrs, &reply2); err == nil || reply2 == utils.OK { + if err := rater.Call(context.Background(), utils.APIerSv1ExecuteAction, attrs, &reply2); err == nil || reply2 == utils.OK { t.Error("Expecting error on APIerSv1.ExecuteAction.", err, reply2) } } @@ -1256,13 +1257,13 @@ func testApierSetActions(t *testing.T) { act1 := &V1TPAction{Identifier: utils.MetaTopUpReset, BalanceType: utils.MetaMonetary, Units: 75.0, ExpiryTime: utils.MetaUnlimited, Weight: 20.0} attrs1 := &V1AttrSetActions{ActionsId: "ACTS_1", Actions: []*V1TPAction{act1}} reply1 := utils.EmptyString - if err := rater.Call(utils.APIerSv1SetActions, &attrs1, &reply1); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetActions, &attrs1, &reply1); err != nil { t.Error("Got error on APIerSv1.SetActions: ", err.Error()) } else if reply1 != utils.OK { t.Errorf("Calling APIerSv1.SetActions received: %s", reply1) } // Calling the second time should raise EXISTS - if err := rater.Call(utils.APIerSv1SetActions, &attrs1, &reply1); err == nil || err.Error() != "EXISTS" { + if err := rater.Call(context.Background(), utils.APIerSv1SetActions, &attrs1, &reply1); err == nil || err.Error() != "EXISTS" { t.Error("Unexpected result on duplication: ", err.Error()) } } @@ -1274,7 +1275,7 @@ func testApierGetActions(t *testing.T) { BalanceDisabled: "false", ExpiryTime: utils.MetaUnlimited, Weight: 20.0}} var reply []*utils.TPAction - if err := rater.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply); err != nil { t.Error("Got error on APIerSv1.GetActions: ", err.Error()) } else if !reflect.DeepEqual(expectActs, reply) { t.Errorf("Expected: %v, received: %v", utils.ToJSON(expectActs), utils.ToJSON(reply)) @@ -1285,13 +1286,13 @@ func testApierSetActionPlan(t *testing.T) { atm1 := &AttrActionPlan{ActionsId: "ACTS_1", MonthDays: "1", Time: "00:00:00", Weight: 20.0} atms1 := &AttrSetActionPlan{Id: "ATMS_1", ActionPlan: []*AttrActionPlan{atm1}} reply1 := utils.EmptyString - if err := rater.Call(utils.APIerSv1SetActionPlan, &atms1, &reply1); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetActionPlan, &atms1, &reply1); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply1 != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1) } // Calling the second time should raise EXISTS - if err := rater.Call(utils.APIerSv1SetActionPlan, &atms1, &reply1); err == nil || err.Error() != "EXISTS" { + if err := rater.Call(context.Background(), utils.APIerSv1SetActionPlan, &atms1, &reply1); err == nil || err.Error() != "EXISTS" { t.Error("Unexpected result on duplication: ", err.Error()) } } @@ -1300,7 +1301,7 @@ func testApierSetActionPlan(t *testing.T) { func testApierAddTriggeredAction(t *testing.T) { var reply string attrs := &AttrAddBalance{Tenant: "cgrates.org", Account: "dan32", BalanceType: utils.MetaMonetary, Value: 1.5} - if err := rater.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -1308,7 +1309,7 @@ func testApierAddTriggeredAction(t *testing.T) { // Add balance to a previously known account attrsAddTrigger := &AttrAddActionTrigger{Tenant: "cgrates.org", Account: "dan32", BalanceType: utils.MetaMonetary, ThresholdType: "*min_balance", ThresholdValue: 2, BalanceDestinationIds: utils.MetaAny, Weight: 10, ActionsId: "WARN_VIA_HTTP"} - if err := rater.Call(utils.APIerSv1AddTriggeredAction, attrsAddTrigger, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddTriggeredAction, attrsAddTrigger, &reply); err != nil { t.Error("Got error on APIerSv1.AddTriggeredAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddTriggeredAction received: %s", reply) @@ -1318,7 +1319,7 @@ func testApierAddTriggeredAction(t *testing.T) { *attrs2 = *attrsAddTrigger attrs2.Account = "dan10" // Does not exist so it should error when adding triggers on it // Add trigger to an account which does n exist - if err := rater.Call(utils.APIerSv1AddTriggeredAction, attrs2, &reply2); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddTriggeredAction, attrs2, &reply2); err == nil { t.Error("Expecting error on APIerSv1.AddTriggeredAction.", err, reply2) } } @@ -1327,7 +1328,7 @@ func testApierAddTriggeredAction(t *testing.T) { func testApierGetAccountActionTriggers(t *testing.T) { var reply engine.ActionTriggers req := utils.TenantAccount{Tenant: "cgrates.org", Account: "dan32"} - if err := rater.Call(utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccountActionTimings: ", err.Error()) } else if len(reply) != 1 || reply[0].ActionsID != "WARN_VIA_HTTP" { t.Errorf("Unexpected action triggers received %v", reply) @@ -1338,7 +1339,7 @@ func testApierAddTriggeredAction2(t *testing.T) { var reply string // Add balance to a previously known account attrs := &AttrAddAccountActionTriggers{ActionTriggerIDs: []string{"STANDARD_TRIGGERS"}, Tenant: "cgrates.org", Account: "dan2"} - if err := rater.Call(utils.APIerSv1AddAccountActionTriggers, &attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddAccountActionTriggers, &attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddAccountActionTriggers: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddAccountActionTriggers received: %s", reply) @@ -1348,7 +1349,7 @@ func testApierAddTriggeredAction2(t *testing.T) { *attrs2 = *attrs attrs2.Account = "dan10" // Does not exist so it should error when adding triggers on it // Add trigger to an account which does n exist - if err := rater.Call(utils.APIerSv1AddAccountActionTriggers, &attrs2, &reply2); err == nil || reply2 == utils.OK { + if err := rater.Call(context.Background(), utils.APIerSv1AddAccountActionTriggers, &attrs2, &reply2); err == nil || reply2 == utils.OK { t.Error("Expecting error on APIerSv1.AddAccountActionTriggers.", err, reply2) } } @@ -1357,7 +1358,7 @@ func testApierAddTriggeredAction2(t *testing.T) { func testApierGetAccountActionTriggers2(t *testing.T) { var reply engine.ActionTriggers req := utils.TenantAccount{Tenant: "cgrates.org", Account: "dan2"} - if err := rater.Call(utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccountActionTimings: ", err.Error()) } else if len(reply) != 1 || reply[0].ActionsID != "LOG_BALANCE" { t.Errorf("Unexpected action triggers received %v", reply) @@ -1369,7 +1370,7 @@ func testApierSetAccountActionTriggers(t *testing.T) { // Test first get so we can steal the id which we need to remove var reply engine.ActionTriggers req := utils.TenantAccount{Tenant: "cgrates.org", Account: "dan2"} - if err := rater.Call(utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccountActionTimings: ", err.Error()) } else if len(reply) != 1 || reply[0].ActionsID != "LOG_BALANCE" { for _, atr := range reply { @@ -1388,17 +1389,17 @@ func testApierSetAccountActionTriggers(t *testing.T) { }, }, } - if err := rater.Call(utils.APIerSv1ResetAccountActionTriggers, setReq, &setReply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1ResetAccountActionTriggers, setReq, &setReply); err != nil { t.Error("Got error on APIerSv1.ResetActionTiming: ", err.Error()) } else if setReply != utils.OK { t.Error("Unexpected answer received", setReply) } - if err := rater.Call(utils.APIerSv1SetAccountActionTriggers, setReq, &setReply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetAccountActionTriggers, setReq, &setReply); err != nil { t.Error("Got error on APIerSv1.RemoveActionTiming: ", err.Error()) } else if setReply != utils.OK { t.Error("Unexpected answer received", setReply) } - if err := rater.Call(utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccountActionTriggers: ", err.Error()) } else if len(reply) != 1 || reply[0].ActivationDate != time.Date(2016, 2, 5, 18, 0, 0, 0, time.UTC) { t.Errorf("Unexpected action triggers received %+v", reply[0]) @@ -1410,7 +1411,7 @@ func testApierRemAccountActionTriggers(t *testing.T) { // Test first get so we can steal the id which we need to remove var reply engine.ActionTriggers req := utils.TenantAccount{Tenant: "cgrates.org", Account: "dan2"} - if err := rater.Call(utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccountActionTimings: ", err.Error()) } else if len(reply) != 1 || reply[0].ActionsID != "LOG_BALANCE" { for _, atr := range reply { @@ -1420,17 +1421,17 @@ func testApierRemAccountActionTriggers(t *testing.T) { } var rmReply string rmReq := AttrRemoveAccountActionTriggers{Tenant: "cgrates.org", Account: "dan2", UniqueID: reply[0].UniqueID} - if err := rater.Call(utils.APIerSv1ResetAccountActionTriggers, rmReq, &rmReply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1ResetAccountActionTriggers, rmReq, &rmReply); err != nil { t.Error("Got error on APIerSv1.ResetActionTiming: ", err.Error()) } else if rmReply != utils.OK { t.Error("Unexpected answer received", rmReply) } - if err := rater.Call(utils.APIerSv1RemoveAccountActionTriggers, rmReq, &rmReply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveAccountActionTriggers, rmReq, &rmReply); err != nil { t.Error("Got error on APIerSv1.RemoveActionTiming: ", err.Error()) } else if rmReply != utils.OK { t.Error("Unexpected answer received", rmReply) } - if err := rater.Call(utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetAccountActionTriggers, &req, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccountActionTriggers: ", err.Error()) } else if len(reply) != 0 { t.Errorf("Unexpected action triggers received %+v", reply[0]) @@ -1441,7 +1442,7 @@ func testApierRemAccountActionTriggers(t *testing.T) { func testApierSetAccount(t *testing.T) { var reply string attrs := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "dan7", ActionPlanID: "ATMS_1", ReloadScheduler: true} - if err := rater.Call(utils.APIerSv1SetAccount, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetAccount, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -1451,7 +1452,7 @@ func testApierSetAccount(t *testing.T) { *attrs2 = *attrs attrs2.ActionPlanID = "DUMMY_DATA" // Does not exist so it should error when adding triggers on it // Add account with actions timing which does not exist - if err := rater.Call(utils.APIerSv1SetAccount, attrs2, &reply2); err == nil || reply2 == utils.OK { // OK is not welcomed + if err := rater.Call(context.Background(), utils.APIerSv1SetAccount, attrs2, &reply2); err == nil || reply2 == utils.OK { // OK is not welcomed t.Error("Expecting error on APIerSv1.SetAccount.", err, reply2) } } @@ -1460,7 +1461,7 @@ func testApierSetAccount(t *testing.T) { func testApierGetAccountActionPlan(t *testing.T) { var reply []*AccountActionTiming req := utils.TenantAccount{Tenant: "cgrates.org", Account: "dan7"} - if err := rater.Call(utils.APIerSv1GetAccountActionPlan, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetAccountActionPlan, &req, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccountActionPlan: ", err.Error()) } else if len(reply) != 1 { t.Error("Unexpected action plan received: ", utils.ToJSON(reply)) @@ -1474,7 +1475,7 @@ func testApierGetAccountActionPlan(t *testing.T) { func testApierGetAccountActionPlanWithoutTenant(t *testing.T) { var reply []*AccountActionTiming req := utils.TenantAccount{Account: "dan7"} - if err := rater.Call(utils.APIerSv1GetAccountActionPlan, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetAccountActionPlan, &req, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccountActionPlan: ", err.Error()) } else if len(reply) != 1 { t.Error("Unexpected action plan received: ", utils.ToJSON(reply)) @@ -1488,7 +1489,7 @@ func testApierGetAccountActionPlanWithoutTenant(t *testing.T) { // Make sure we have scheduled actions func testApierITGetScheduledActionsForAccount(t *testing.T) { var rply []*scheduler.ScheduledAction - if err := rater.Call(utils.APIerSv1GetScheduledActions, + if err := rater.Call(context.Background(), utils.APIerSv1GetScheduledActions, scheduler.ArgsGetScheduledActions{ Tenant: utils.StringPointer("cgrates.org"), Account: utils.StringPointer("dan7")}, &rply); err != nil { @@ -1502,14 +1503,14 @@ func testApierITGetScheduledActionsForAccount(t *testing.T) { func testApierRemUniqueIDActionTiming(t *testing.T) { var rmReply string rmReq := AttrRemoveActionTiming{ActionPlanId: "ATMS_1", Tenant: "cgrates.org", Account: "dan4"} - if err := rater.Call(utils.APIerSv1RemoveActionTiming, &rmReq, &rmReply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveActionTiming, &rmReq, &rmReply); err != nil { t.Error("Got error on APIerSv1.RemoveActionTiming: ", err.Error()) } else if rmReply != utils.OK { t.Error("Unexpected answer received", rmReply) } var reply []*AccountActionTiming req := utils.TenantAccount{Tenant: "cgrates.org", Account: "dan4"} - if err := rater.Call(utils.APIerSv1GetAccountActionPlan, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetAccountActionPlan, &req, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccountActionPlan: ", err.Error()) } else if len(reply) != 0 { t.Error("Action timings was not removed") @@ -1519,14 +1520,14 @@ func testApierRemUniqueIDActionTiming(t *testing.T) { func testApierRemUniqueIDActionTimingWithoutTenant(t *testing.T) { var rmReply string rmReq := AttrRemoveActionTiming{ActionPlanId: "ATMS_1", Account: "dan4"} - if err := rater.Call(utils.APIerSv1RemoveActionTiming, &rmReq, &rmReply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1RemoveActionTiming, &rmReq, &rmReply); err != nil { t.Error("Got error on APIerSv1.RemoveActionTiming: ", err.Error()) } else if rmReply != utils.OK { t.Error("Unexpected answer received", rmReply) } var reply []*AccountActionTiming req := utils.TenantAccount{Account: "dan4"} - if err := rater.Call(utils.APIerSv1GetAccountActionPlan, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetAccountActionPlan, &req, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccountActionPlan: ", err.Error()) } else if len(reply) != 0 { t.Error("Action timings was not removed") @@ -1537,32 +1538,32 @@ func testApierRemUniqueIDActionTimingWithoutTenant(t *testing.T) { func testApierGetAccount(t *testing.T) { var reply *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := rater.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() != 11.5 { // We expect 11.5 since we have added in the previous test 1.5 t.Errorf("Calling APIerSv1.GetBalance expected: 11.5, received: %f", reply.BalanceMap[utils.MetaMonetary].GetTotalValue()) } attrs = &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"} - if err := rater.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() != 1.5 { t.Errorf("Calling APIerSv1.GetAccount expected: 1.5, received: %f", reply.BalanceMap[utils.MetaMonetary].GetTotalValue()) } // The one we have topped up though executeAction attrs = &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan2"} - if err := rater.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() != 11.5 { t.Errorf("Calling APIerSv1.GetAccount expected: 10, received: %f", reply.BalanceMap[utils.MetaMonetary].GetTotalValue()) } attrs = &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan3"} - if err := rater.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() != 3.6 { t.Errorf("Calling APIerSv1.GetAccount expected: 3.6, received: %f", reply.BalanceMap[utils.MetaMonetary].GetTotalValue()) } attrs = &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan6"} - if err := rater.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() != 1 { t.Errorf("Calling APIerSv1.GetAccount expected: 1, received: %f", reply.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -1573,13 +1574,13 @@ func testApierGetAccount(t *testing.T) { func testApierTriggersExecute(t *testing.T) { var reply string attrs := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "dan8", ReloadScheduler: true} - if err := rater.Call(utils.APIerSv1SetAccount, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetAccount, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) } attrAddBlnc := &AttrAddBalance{Tenant: "cgrates.org", Account: "1008", BalanceType: utils.MetaMonetary, Value: 2} - if err := rater.Call(utils.APIerSv1AddBalance, attrAddBlnc, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1AddBalance, attrAddBlnc, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -1591,7 +1592,7 @@ func testApierResetDataBeforeLoadFromFolder(t *testing.T) { testApierInitDataDb(t) var reply string // Simple test that command is executed without errors - if err := rater.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := rater.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ CacheIDs: nil, }, &reply); err != nil { t.Error(err) @@ -1600,7 +1601,7 @@ func testApierResetDataBeforeLoadFromFolder(t *testing.T) { } var rcvStats map[string]*ltcache.CacheStats expectedStats := engine.GetDefaultEmptyCacheStats() - err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats) + err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats) if err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(rcvStats, expectedStats) { @@ -1612,16 +1613,16 @@ func testApierResetDataBeforeLoadFromFolder(t *testing.T) { func testApierLoadTariffPlanFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: utils.EmptyString} - if err := rater.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err == nil || !strings.HasPrefix(err.Error(), utils.ErrMandatoryIeMissing.Error()) { + if err := rater.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err == nil || !strings.HasPrefix(err.Error(), utils.ErrMandatoryIeMissing.Error()) { t.Error(err) } attrs = &utils.AttrLoadTpFromFolder{FolderPath: "/INVALID/"} - if err := rater.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err == nil || err.Error() != utils.ErrInvalidPath.Error() { + if err := rater.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err == nil || err.Error() != utils.ErrInvalidPath.Error() { t.Error(err) } // Simple test that command is executed without errors attrs = &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testtp")} - if err := rater.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.LoadTariffPlanFromFolder: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.LoadTariffPlanFromFolder got reply: ", reply) @@ -1632,12 +1633,12 @@ func testApierLoadTariffPlanFromFolder(t *testing.T) { // For now just test that they execute without errors func testApierComputeReverse(t *testing.T) { var reply string - if err := rater.Call(utils.APIerSv1ComputeReverseDestinations, utils.EmptyString, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1ComputeReverseDestinations, utils.EmptyString, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Received: ", reply) } - if err := rater.Call(utils.APIerSv1ComputeAccountActionPlans, new(utils.TenantWithAPIOpts), &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1ComputeAccountActionPlans, new(utils.TenantWithAPIOpts), &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Received: ", reply) @@ -1654,14 +1655,14 @@ func testApierResetDataAfterLoadFromFolder(t *testing.T) { expStats[utils.CacheDestinations].Items = 3 expStats[utils.CacheLoadIDs].Items = 18 expStats[utils.CacheRPCConnections].Items = 2 - if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expStats, rcvStats) { t.Errorf("Expecting: %+v,\n received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats)) } var reply string // Simple test that command is executed without errors - if err := rater.Call(utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(reply) @@ -1697,7 +1698,7 @@ func testApierResetDataAfterLoadFromFolder(t *testing.T) { expStats[utils.CacheReverseFilterIndexes].Items = 10 expStats[utils.CacheReverseFilterIndexes].Groups = 7 - if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { t.Error(err) } else if !reflect.DeepEqual(expStats, rcvStats) { t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats)) @@ -1716,7 +1717,7 @@ func testApierSetChargerS(t *testing.T) { }, } var result string - if err := rater.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1728,7 +1729,7 @@ func testApierSetChargerS(t *testing.T) { func testApierGetAccountAfterLoad(t *testing.T) { var reply *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := rater.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() != 13 { t.Errorf("Calling APIerSv1.GetBalance expected: 13, received: %v \n\n for:%s", reply.BalanceMap[utils.MetaMonetary].GetTotalValue(), utils.ToJSON(reply)) @@ -1753,7 +1754,7 @@ func testApierResponderGetCost(t *testing.T) { } var cc engine.CallCost // Simple test that command is executed without errors - if err := rater.Call(utils.ResponderGetCost, cd, &cc); err != nil { + if err := rater.Call(context.Background(), utils.ResponderGetCost, cd, &cc); err != nil { t.Error("Got error on Responder.GetCost: ", err.Error()) } else if cc.Cost != 90.0 { t.Errorf("Calling Responder.GetCost got callcost: %v", cc) @@ -1773,10 +1774,10 @@ func testApierMaxDebitInexistentAcnt(t *testing.T) { TimeEnd: time.Date(2014, 3, 27, 10, 42, 26, 0, time.UTC).Add(10 * time.Second), }, } - if err := rater.Call(utils.ResponderMaxDebit, cd, cc); err == nil { + if err := rater.Call(context.Background(), utils.ResponderMaxDebit, cd, cc); err == nil { t.Error(err.Error()) } - if err := rater.Call(utils.ResponderDebit, cd, cc); err == nil { + if err := rater.Call(context.Background(), utils.ResponderDebit, cd, cc); err == nil { t.Error(err.Error()) } } @@ -1803,7 +1804,7 @@ func testApierCdrServer(t *testing.T) { func testApierITGetCdrs(t *testing.T) { var reply []*engine.ExternalCDR req := utils.AttrGetCdrs{MediationRunIds: []string{utils.MetaDefault}} - if err := rater.Call(utils.APIerSv1GetCDRs, &req, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetCDRs, &req, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 2 { t.Error("Unexpected number of CDRs returned: ", len(reply)) @@ -1820,14 +1821,14 @@ func testApierITProcessCdr(t *testing.T) { Usage: 10 * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01, }, } - if err := rater.Call(utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { + if err := rater.Call(context.Background(), utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } var cdrs []*engine.ExternalCDR req := utils.AttrGetCdrs{MediationRunIds: []string{utils.MetaDefault}} - if err := rater.Call(utils.APIerSv1GetCDRs, &req, &cdrs); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 3 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -1839,12 +1840,12 @@ func testApierGetCallCostLog(t *testing.T) { var cc engine.EventCost var attrs utils.AttrGetCallCost // Simple test that command is executed without errors - if err := rater.Call(utils.APIerSv1GetEventCost, &attrs, &cc); err == nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetEventCost, &attrs, &cc); err == nil { t.Error("Failed to detect missing fields in APIerSv1.GetCallCostLog") } attrs.CgrId = "dummyid" attrs.RunId = "default" - if err := rater.Call(utils.APIerSv1GetEventCost, &attrs, &cc); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := rater.Call(context.Background(), utils.APIerSv1GetEventCost, &attrs, &cc); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error("APIerSv1.GetCallCostLog: should return NOT_FOUND, got:", err) } tm := time.Now().Truncate(time.Millisecond).UTC() @@ -1871,7 +1872,7 @@ func testApierGetCallCostLog(t *testing.T) { }, } var reply string - if err := rater.Call(utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { + if err := rater.Call(context.Background(), utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -1901,7 +1902,7 @@ func testApierGetCallCostLog(t *testing.T) { } attrs.CgrId = "Cdr1" attrs.RunId = utils.EmptyString - if err := rater.Call(utils.APIerSv1GetEventCost, &attrs, &cc); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetEventCost, &attrs, &cc); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, cc) { t.Errorf("Expecting %s ,received %s", utils.ToJSON(expected), utils.ToJSON(cc)) @@ -1911,30 +1912,30 @@ func testApierGetCallCostLog(t *testing.T) { func testApierITSetDestination(t *testing.T) { attrs := utils.AttrSetDestination{Id: "TEST_SET_DESTINATION", Prefixes: []string{"+4986517174963", "+4986517174960"}} var reply string - if err := rater.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetDestination, &attrs, &reply); err != nil { t.Error("Unexpected error", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } - if err := rater.Call(utils.APIerSv1SetDestination, &attrs, &reply); err == nil || err.Error() != "EXISTS" { // Second time without overwrite should generate error + if err := rater.Call(context.Background(), utils.APIerSv1SetDestination, &attrs, &reply); err == nil || err.Error() != "EXISTS" { // Second time without overwrite should generate error t.Error("Unexpected error", err.Error()) } attrs = utils.AttrSetDestination{Id: "TEST_SET_DESTINATION", Prefixes: []string{"+4986517174963", "+4986517174964"}, Overwrite: true} - if err := rater.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetDestination, &attrs, &reply); err != nil { t.Error("Unexpected error", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } eDestination := engine.Destination{Id: attrs.Id, Prefixes: attrs.Prefixes} var rcvDestination engine.Destination - if err := rater.Call(utils.APIerSv1GetDestination, &attrs.Id, &rcvDestination); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetDestination, &attrs.Id, &rcvDestination); err != nil { t.Error("Unexpected error", err.Error()) } else if !reflect.DeepEqual(eDestination, rcvDestination) { t.Errorf("Expecting: %+v, received: %+v", eDestination, rcvDestination) } eRcvIDs := []string{attrs.Id} var rcvIDs []string - if err := rater.Call(utils.APIerSv1GetReverseDestination, &attrs.Prefixes[0], &rcvIDs); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetReverseDestination, &attrs.Prefixes[0], &rcvIDs); err != nil { t.Error("Unexpected error", err.Error()) } else if !reflect.DeepEqual(eRcvIDs, rcvIDs) { t.Errorf("Expecting: %+v, received: %+v", eRcvIDs, rcvIDs) @@ -1943,7 +1944,7 @@ func testApierITSetDestination(t *testing.T) { func testApierITGetScheduledActions(t *testing.T) { var rply []*scheduler.ScheduledAction - if err := rater.Call(utils.APIerSv1GetScheduledActions, scheduler.ArgsGetScheduledActions{}, &rply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetScheduledActions, scheduler.ArgsGetScheduledActions{}, &rply); err != nil { t.Error("Unexpected error: ", err) } } @@ -1952,7 +1953,7 @@ func testApierITGetDataCost(t *testing.T) { attrs := AttrGetDataCost{Category: "data", Tenant: "cgrates.org", Subject: "1001", AnswerTime: utils.MetaNow, Usage: 640113} var rply *engine.DataCost - if err := rater.Call(utils.APIerSv1GetDataCost, &attrs, &rply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetDataCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if rply.Cost != 128.0240 { t.Errorf("Unexpected cost received: %f", rply.Cost) @@ -1963,7 +1964,7 @@ func testApierITGetCost(t *testing.T) { attrs := AttrGetCost{Category: "data", Tenant: "cgrates.org", Subject: "1001", AnswerTime: utils.MetaNow, Usage: "640113"} var rply *engine.EventCost - if err := rater.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 128.0240 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -1986,7 +1987,7 @@ func testApierInitStorDb2(t *testing.T) { func testApierReloadCache2(t *testing.T) { var reply string // Simple test that command is executed without errors - if err := rater.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := rater.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ CacheIDs: nil, }, &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) @@ -1998,7 +1999,7 @@ func testApierReloadCache2(t *testing.T) { func testApierReloadScheduler2(t *testing.T) { var reply string // Simple test that command is executed without errors - if err := rater.Call(utils.SchedulerSv1Reload, utils.StringWithAPIOpts{}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.SchedulerSv1Reload, utils.StringWithAPIOpts{}, &reply); err != nil { t.Error("Got error on SchedulerSv1.Reload: ", err.Error()) } else if reply != utils.OK { t.Error("Calling SchedulerSv1.Reload got reply: ", reply) @@ -2007,7 +2008,7 @@ func testApierReloadScheduler2(t *testing.T) { func testApierImportTPFromFolderPath(t *testing.T) { var reply string - if err := rater.Call(utils.APIerSv1ImportTariffPlanFromFolder, + if err := rater.Call(context.Background(), utils.APIerSv1ImportTariffPlanFromFolder, utils.AttrImportTPFromFolder{TPid: "TEST_TPID2", FolderPath: "/usr/share/cgrates/tariffplans/oldtutorial"}, &reply); err != nil { t.Error("Got error on APIerSv1.ImportTarrifPlanFromFolder: ", err.Error()) @@ -2019,7 +2020,7 @@ func testApierImportTPFromFolderPath(t *testing.T) { func testApierLoadTariffPlanFromStorDbDryRun(t *testing.T) { var reply string - if err := rater.Call(utils.APIerSv1LoadTariffPlanFromStorDb, + if err := rater.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromStorDb, &AttrLoadTpFromStorDb{TPid: "TEST_TPID2", DryRun: true}, &reply); err != nil { t.Error("Got error on APIerSv1.LoadTariffPlanFromStorDb: ", err.Error()) } else if reply != utils.OK { @@ -2030,7 +2031,7 @@ func testApierLoadTariffPlanFromStorDbDryRun(t *testing.T) { func testApierGetCacheStats2(t *testing.T) { var rcvStats map[string]*ltcache.CacheStats expectedStats := engine.GetDefaultEmptyCacheStats() - err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats) + err := rater.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats) if err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { @@ -2040,7 +2041,7 @@ func testApierGetCacheStats2(t *testing.T) { func testApierLoadTariffPlanFromStorDb(t *testing.T) { var reply string - if err := rater.Call(utils.APIerSv1LoadTariffPlanFromStorDb, + if err := rater.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromStorDb, &AttrLoadTpFromStorDb{TPid: "TEST_TPID2"}, &reply); err != nil { t.Error("Got error on APIerSv1.LoadTariffPlanFromStorDb: ", err.Error()) } else if reply != utils.OK { @@ -2050,41 +2051,41 @@ func testApierLoadTariffPlanFromStorDb(t *testing.T) { func testApierStartStopServiceStatus(t *testing.T) { var reply string - if err := rater.Call(utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}}, + if err := rater.Call(context.Background(), utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}}, &reply); err != nil { t.Error(err) } else if reply != utils.RunningCaps { t.Errorf("Received: <%s>", reply) } - if err := rater.Call(utils.ServiceManagerV1StopService, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: "INVALID"}}, + if err := rater.Call(context.Background(), utils.ServiceManagerV1StopService, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: "INVALID"}}, &reply); err == nil || err.Error() != utils.UnsupportedServiceIDCaps { t.Error(err) } - if err := rater.Call(utils.ServiceManagerV1StopService, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}}, + if err := rater.Call(context.Background(), utils.ServiceManagerV1StopService, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: <%s>", reply) } - if err := rater.Call(utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}}, + if err := rater.Call(context.Background(), utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}}, &reply); err != nil { t.Error(err) } else if reply != utils.StoppedCaps { t.Errorf("Received: <%s>", reply) } - if err := rater.Call(utils.ServiceManagerV1StartService, &dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}}, + if err := rater.Call(context.Background(), utils.ServiceManagerV1StartService, &dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: <%s>", reply) } - if err := rater.Call(utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}}, + if err := rater.Call(context.Background(), utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}}, &reply); err != nil { t.Error(err) } else if reply != utils.RunningCaps { t.Errorf("Received: <%s>", reply) } - if err := rater.Call(utils.SchedulerSv1Reload, utils.StringWithAPIOpts{}, &reply); err != nil { + if err := rater.Call(context.Background(), utils.SchedulerSv1Reload, utils.StringWithAPIOpts{}, &reply); err != nil { t.Error("Got error on SchedulerSv1.Reload: ", err.Error()) } else if reply != utils.OK { t.Error("Calling SchedulerSv1.Reload got reply: ", reply) @@ -2095,14 +2096,14 @@ func testApierSetRatingProfileWithoutTenant(t *testing.T) { var reply string rpa := &utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1", FallbackSubjects: "dan4"} rpf := &utils.AttrSetRatingProfile{Category: utils.Call, Subject: "dan3", RatingPlanActivations: []*utils.TPRatingActivation{rpa}} - if err := rater.Call(utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply) } expectedID := utils.ConcatenatedKey(utils.MetaOut, "cgrates.org", utils.Call, "dan3") var result *engine.RatingProfile - if err := rater.Call(utils.APIerSv1GetRatingProfile, + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfile, &utils.AttrGetRatingProfile{Category: utils.Call, Subject: "dan3"}, &result); err != nil { t.Error(err) @@ -2113,7 +2114,7 @@ func testApierSetRatingProfileWithoutTenant(t *testing.T) { func testApierRemoveRatingProfilesWithoutTenant(t *testing.T) { var reply string - if err := rater.Call(utils.APIerSv1RemoveRatingProfile, &AttrRemoveRatingProfile{ + if err := rater.Call(context.Background(), utils.APIerSv1RemoveRatingProfile, &AttrRemoveRatingProfile{ Category: utils.Call, Subject: "dan3", }, &reply); err != nil { @@ -2122,7 +2123,7 @@ func testApierRemoveRatingProfilesWithoutTenant(t *testing.T) { t.Errorf("Expected: %s, received: %s ", utils.OK, reply) } var result *engine.RatingProfile - if err := rater.Call(utils.APIerSv1GetRatingProfile, + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfile, &utils.AttrGetRatingProfile{Category: utils.Call, Subject: "dan3"}, &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -2155,7 +2156,7 @@ func testApierReplayFldPosts(t *testing.T) { t.Error(err) } var reply string - if err := rater.Call(utils.APIerSv1ReplayFailedPosts, &args, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1ReplayFailedPosts, &args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply: ", reply) @@ -2183,7 +2184,7 @@ func testApierReplayFldPosts(t *testing.T) { if err != nil { t.Error(err) } - if err := rater.Call(utils.APIerSv1ReplayFailedPosts, &args, &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1ReplayFailedPosts, &args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply: ", reply) @@ -2234,7 +2235,7 @@ func testApierReplayFldPosts(t *testing.T) { func testApierGetDataDBVesions(t *testing.T) { var reply *engine.Versions - if err := rater.Call(utils.APIerSv1GetDataDBVersions, utils.StringPointer(utils.EmptyString), &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetDataDBVersions, utils.StringPointer(utils.EmptyString), &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(engine.CurrentDataDBVersions(), *reply) { t.Errorf("Expecting : %+v, received: %+v", engine.CurrentDataDBVersions(), *reply) @@ -2243,7 +2244,7 @@ func testApierGetDataDBVesions(t *testing.T) { func testApierGetStorDBVesions(t *testing.T) { var reply *engine.Versions - if err := rater.Call(utils.APIerSv1GetStorDBVersions, utils.StringPointer(utils.EmptyString), &reply); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetStorDBVersions, utils.StringPointer(utils.EmptyString), &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(engine.CurrentStorDBVersions(), *reply) { t.Errorf("Expecting : %+v, received: %+v", engine.CurrentStorDBVersions(), *reply) @@ -2252,7 +2253,7 @@ func testApierGetStorDBVesions(t *testing.T) { func testApierBackwardsCompatible(t *testing.T) { var reply string - if err := rater.Call("ApierV1.Ping", new(utils.CGREvent), &reply); err != nil { + if err := rater.Call(context.Background(), "ApierV1.Ping", new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Expecting : %+v, received: %+v", utils.Pong, reply) @@ -2283,7 +2284,7 @@ func testRatingProfileCachingMetaNone(t *testing.T) { } // set the profile var result string - if err := rater.Call(utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -2293,7 +2294,7 @@ func testRatingProfileCachingMetaNone(t *testing.T) { CacheID: utils.CacheRatingProfiles, ItemID: "*out:cgrates.org:call:dan", } - if err := rater.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: false, received:%v", reply) @@ -2303,7 +2304,7 @@ func testRatingProfileCachingMetaNone(t *testing.T) { argsCache2 := utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheRatingProfiles, } - if err := rater.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || + if err := rater.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err.Error(), rcvKeys) @@ -2312,7 +2313,7 @@ func testRatingProfileCachingMetaNone(t *testing.T) { //check in dataManager expected := []string{"call:dan"} var rcvIDs []string - if err := rater.Call(utils.APIerSv1GetRatingProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rcvIDs) { t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs) @@ -2334,7 +2335,7 @@ func testRatingProfileCachingMetaLoad(t *testing.T) { } // set the profile var result string - if err := rater.Call(utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -2344,7 +2345,7 @@ func testRatingProfileCachingMetaLoad(t *testing.T) { CacheID: utils.CacheRatingProfiles, ItemID: "*out:cgrates.org:call:dan", } - if err := rater.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: true, received:%v", reply) @@ -2355,7 +2356,7 @@ func testRatingProfileCachingMetaLoad(t *testing.T) { argsCache2 := utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheRatingProfiles, } - if err := rater.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(rcvKeys, expectedIDs) { t.Errorf("Expecting : %+v, received: %+v", expectedIDs, rcvKeys) @@ -2364,14 +2365,14 @@ func testRatingProfileCachingMetaLoad(t *testing.T) { //check in dataManager expected := []string{"call:dan"} var rcvIDs []string - if err := rater.Call(utils.APIerSv1GetRatingProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rcvIDs) { t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs) } //remove from cache and DataManager the profile var resp string - if err := rater.Call(utils.APIerSv1RemoveRatingProfile, + if err := rater.Call(context.Background(), utils.APIerSv1RemoveRatingProfile, AttrRemoveRatingProfile{ Tenant: rpf.Tenant, Category: rpf.Category, @@ -2386,20 +2387,20 @@ func testRatingProfileCachingMetaLoad(t *testing.T) { CacheID: utils.CacheRatingProfiles, ItemID: "*out:cgrates.org:call:dan", } - if err := rater.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: false, received:%v", reply) } - if err := rater.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || + if err := rater.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err, rcvKeys) } //check in dataManager - if err := rater.Call(utils.APIerSv1GetRatingProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err == nil || + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err, rcvIDs) @@ -2422,7 +2423,7 @@ func testRatingProfileCachingMetaReload1(t *testing.T) { } // set the profile var result string - if err := rater.Call(utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -2432,7 +2433,7 @@ func testRatingProfileCachingMetaReload1(t *testing.T) { CacheID: utils.CacheRatingProfiles, ItemID: "*out:cgrates.org:call:dan", } - if err := rater.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: false, received:%v", reply) @@ -2442,7 +2443,7 @@ func testRatingProfileCachingMetaReload1(t *testing.T) { argsCache2 := utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheRatingProfiles, } - if err := rater.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || + if err := rater.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err, rcvKeys) @@ -2451,7 +2452,7 @@ func testRatingProfileCachingMetaReload1(t *testing.T) { //check in dataManager expected := []string{"call:dan"} var rcvIDs []string - if err := rater.Call(utils.APIerSv1GetRatingProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rcvIDs) { t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs) @@ -2482,14 +2483,14 @@ func testRatingProfileCachingMetaReload2(t *testing.T) { } // set the profile var result string - if err := rater.Call(utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.RatingProfile - if err := rater.Call(utils.APIerSv1GetRatingProfile, &utils.AttrGetRatingProfile{ + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfile, &utils.AttrGetRatingProfile{ Tenant: "cgrates.org", Category: "call", Subject: "dan"}, &reply); err != nil { t.Fatal(err) } @@ -2502,13 +2503,13 @@ func testRatingProfileCachingMetaReload2(t *testing.T) { rpf.RatingPlanActivations[0].FallbackSubjects = "dan3" expected.RatingPlanActivations[0].FallbackKeys[0] = "*out:cgrates.org:call:dan3" // set the profile - if err := rater.Call(utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := rater.Call(utils.APIerSv1GetRatingProfile, &utils.AttrGetRatingProfile{ + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfile, &utils.AttrGetRatingProfile{ Tenant: "cgrates.org", Category: "call", Subject: "dan"}, &reply); err != nil { t.Fatal(err) } @@ -2532,7 +2533,7 @@ func testRatingProfileCachingMetaRemove(t *testing.T) { } // set the profile var result string - if err := rater.Call(utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -2542,7 +2543,7 @@ func testRatingProfileCachingMetaRemove(t *testing.T) { CacheID: utils.CacheRatingProfiles, ItemID: "*out:cgrates.org:call:dan", } - if err := rater.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: true, received:%v", reply) @@ -2553,7 +2554,7 @@ func testRatingProfileCachingMetaRemove(t *testing.T) { argsCache2 := utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheRatingProfiles, } - if err := rater.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(rcvKeys, expectedIDs) { t.Errorf("Expecting : %+v, received: %+v", expectedIDs, rcvKeys) @@ -2573,19 +2574,19 @@ func testRatingProfileCachingMetaRemove(t *testing.T) { APIOpts: map[string]any{utils.CacheOpt: utils.MetaRemove}, } // set the profile - if err := rater.Call(utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1SetRatingProfile, rpf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := rater.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := rater.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: false, received:%v", reply) } - if err := rater.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || + if err := rater.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err.Error(), rcvKeys) @@ -2594,7 +2595,7 @@ func testRatingProfileCachingMetaRemove(t *testing.T) { //check in dataManager expected := []string{"call:dan"} var rcvIDs []string - if err := rater.Call(utils.APIerSv1GetRatingProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { + if err := rater.Call(context.Background(), utils.APIerSv1GetRatingProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rcvIDs) { t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs) diff --git a/apier/v1/attributes.go b/apier/v1/attributes.go index d95ce6b6e..f7927c06c 100644 --- a/apier/v1/attributes.go +++ b/apier/v1/attributes.go @@ -21,12 +21,13 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // GetAttributeProfile returns an Attribute Profile -func (apierSv1 *APIerSv1) GetAttributeProfile(arg *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) (err error) { +func (apierSv1 *APIerSv1) GetAttributeProfile(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) (err error) { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -46,7 +47,7 @@ func (apierSv1 *APIerSv1) GetAttributeProfile(arg *utils.TenantIDWithAPIOpts, re } // GetAttributeProfileIDs returns list of attributeProfile IDs registered for a tenant -func (apierSv1 *APIerSv1) GetAttributeProfileIDs(args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetAttributeProfileIDs(ctx *context.Context, args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error { tnt := args.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -69,7 +70,7 @@ func (apierSv1 *APIerSv1) GetAttributeProfileIDs(args *utils.PaginatorWithTenant // GetAttributeProfileCount sets in reply var the total number of AttributeProfileIDs registered for a tenant // returns ErrNotFound in case of 0 AttributeProfileIDs -func (apierSv1 *APIerSv1) GetAttributeProfileCount(args *utils.TenantWithAPIOpts, reply *int) (err error) { +func (apierSv1 *APIerSv1) GetAttributeProfileCount(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *int) (err error) { tnt := args.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -87,7 +88,7 @@ func (apierSv1 *APIerSv1) GetAttributeProfileCount(args *utils.TenantWithAPIOpts } // SetAttributeProfile add/update a new Attribute Profile -func (apierSv1 *APIerSv1) SetAttributeProfile(alsWrp *engine.AttributeProfileWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) SetAttributeProfile(ctx *context.Context, alsWrp *engine.AttributeProfileWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(alsWrp.AttributeProfile, []string{utils.ID, utils.Attributes}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -124,7 +125,7 @@ func (apierSv1 *APIerSv1) SetAttributeProfile(alsWrp *engine.AttributeProfileWit } // RemoveAttributeProfile remove a specific Attribute Profile -func (apierSv1 *APIerSv1) RemoveAttributeProfile(arg *utils.TenantIDWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) RemoveAttributeProfile(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -157,26 +158,26 @@ type AttributeSv1 struct { attrS *engine.AttributeService } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (alSv1 *AttributeSv1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (alSv1 *AttributeSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(alSv1, serviceMethod, args, reply) } // GetAttributeForEvent returns matching AttributeProfile for Event -func (alSv1 *AttributeSv1) GetAttributeForEvent(args *utils.CGREvent, +func (alSv1 *AttributeSv1) GetAttributeForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.AttributeProfile) (err error) { - return alSv1.attrS.V1GetAttributeForEvent(args, reply) + return alSv1.attrS.V1GetAttributeForEvent(ctx, args, reply) } // ProcessEvent will replace event fields with the ones in matching AttributeProfile -func (alSv1 *AttributeSv1) ProcessEvent(args *utils.CGREvent, +func (alSv1 *AttributeSv1) ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.AttrSProcessEventReply) error { - return alSv1.attrS.V1ProcessEvent(args, reply) + return alSv1.attrS.V1ProcessEvent(ctx, args, reply) } // Ping return pong if the service is active -func (alSv1 *AttributeSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (alSv1 *AttributeSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index 80674b86b..7ae859337 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( alsPrfCfgPath string alsPrfCfg *config.CGRConfig - attrSRPC *rpc.Client + attrSRPC *birpc.Client alsPrf *engine.AttributeProfileWithAPIOpts alsPrfConfigDIR string //run tests for specific configuration @@ -166,7 +167,7 @@ func testAttributeSRPCConn(t *testing.T) { func testAttributeSGetAlsPrfBeforeSet(t *testing.T) { var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -176,7 +177,7 @@ func testAttributeSGetAlsPrfBeforeSet(t *testing.T) { func testAttributeSLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} - if err := attrSRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -224,7 +225,7 @@ func testAttributeSGetAttributeForEvent(t *testing.T) { } eAttrPrf.Compile() var attrReply *engine.AttributeProfile - if err := attrSRPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev, &attrReply); err != nil { t.Fatal(err) } @@ -236,7 +237,7 @@ func testAttributeSGetAttributeForEvent(t *testing.T) { ev.Tenant = utils.EmptyString ev.ID = "randomID" - if err := attrSRPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev, &attrReply); err != nil { t.Fatal(err) } @@ -278,13 +279,13 @@ func testAttributeSGetAttributeForEventNotFound(t *testing.T) { } eAttrPrf2.Compile() var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, eAttrPrf2, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, eAttrPrf2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_3"}}, &reply); err != nil { t.Fatal(err) } @@ -293,7 +294,7 @@ func testAttributeSGetAttributeForEventNotFound(t *testing.T) { t.Errorf("Expecting : %+v, received: %+v", eAttrPrf2, reply) } var attrReply *engine.AttributeProfile - if err := attrSRPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -330,13 +331,13 @@ func testAttributeSGetAttributeForEventWithMetaAnyContext(t *testing.T) { } eAttrPrf2.Compile() var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, eAttrPrf2, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, eAttrPrf2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_2"}}, &reply); err != nil { t.Fatal(err) } @@ -345,7 +346,7 @@ func testAttributeSGetAttributeForEventWithMetaAnyContext(t *testing.T) { t.Errorf("Expecting : %+v, received: %+v", eAttrPrf2.AttributeProfile, reply) } var attrReply *engine.AttributeProfile - if err := attrSRPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev, &attrReply); err != nil { t.Fatal(err) } @@ -385,7 +386,7 @@ func testAttributeSProcessEvent(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } else { @@ -400,7 +401,7 @@ func testAttributeSProcessEvent(t *testing.T) { ev.Tenant = "" ev.ID = "randomID" eRply.ID = "randomID" - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } else { @@ -426,7 +427,7 @@ func testAttributeSProcessEventNotFound(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -447,7 +448,7 @@ func testAttributeSProcessEventMissing(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err == nil || err.Error() != "MANDATORY_IE_MISSING: [Category]" { t.Error(err) @@ -492,7 +493,7 @@ func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) { } alsPrf.Compile() var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -515,7 +516,7 @@ func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) { } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } @@ -564,7 +565,7 @@ func testAttributeSProcessEventWithNoneSubstitute2(t *testing.T) { }, } var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -601,7 +602,7 @@ func testAttributeSProcessEventWithNoneSubstitute2(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRply, &rplyEv) && @@ -650,7 +651,7 @@ func testAttributeSProcessEventWithNoneSubstitute3(t *testing.T) { }, } var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -672,7 +673,7 @@ func testAttributeSProcessEventWithNoneSubstitute3(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRply, &rplyEv) { @@ -702,7 +703,7 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { }, } var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -735,7 +736,7 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, attrArgs, &rplyEv); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRply, &rplyEv) { @@ -766,7 +767,7 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { // }, // } // var result string -// if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { +// if err := attrSRPC.Call(context.Background(),utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { // t.Error(err) // } else if result != utils.OK { // t.Error("Unexpected reply returned", result) @@ -791,14 +792,14 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { // Weight: 5, // }, // } -// if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil { +// if err := attrSRPC.Call(context.Background(),utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil { // t.Error(err) // } else if result != utils.OK { // t.Error("Unexpected reply returned", result) // } // var reply *engine.AttributeProfile -// if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, +// if err := attrSRPC.Call(context.Background(),utils.APIerSv1GetAttributeProfile, // utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_SENTRY_IP"}}, &reply); err != nil { // t.Fatal(err) // } @@ -807,7 +808,7 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { // t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply) // } -// if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, +// if err := attrSRPC.Call(context.Background(),utils.APIerSv1GetAttributeProfile, // utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_SENTRY_NUMBER"}}, &reply); err != nil { // t.Fatal(err) // } @@ -845,7 +846,7 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { // }, // } // var rplyEv engine.AttrSProcessEventReply -// if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, +// if err := attrSRPC.Call(context.Background(),utils.AttributeSv1ProcessEvent, // attrArgs, &rplyEv); err != nil { // t.Error(err) // } else if !reflect.DeepEqual(eRply, &rplyEv) { @@ -857,17 +858,17 @@ func testAttributeSProcessEventWithHeader(t *testing.T) { func testAttributeSGetAttPrfIDs(t *testing.T) { expected := []string{"ATTR_2", "ATTR_PASS", "ATTR_1", "ATTR_3", "ATTR_Header", "AttributeWithNonSubstitute"} var result []string - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{ + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{ Tenant: "cgrates.org", Paginator: utils.Paginator{Limit: utils.IntPointer(10)}, }, &result); err != nil { @@ -899,11 +900,11 @@ func testAttributeSSetAlsPrfBrokenReference(t *testing.T) { } var result string expErr := "SERVER_ERROR: broken reference to filter: for item with ID: cgrates.org:ApierTest" - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err == nil || err.Error() != expErr { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err == nil || err.Error() != expErr { t.Fatalf("Expected error: %q, received: %q", expErr, err) } var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -932,13 +933,13 @@ func testAttributeSSetAlsPrf(t *testing.T) { } alsPrf.Compile() var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}}, &reply); err != nil { t.Fatal(err) } @@ -961,13 +962,13 @@ func testAttributeSUpdateAlsPrf(t *testing.T) { } alsPrf.Compile() var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}}, &reply); err != nil { t.Fatal(err) } @@ -983,7 +984,7 @@ func testAttributeSUpdateAlsPrf(t *testing.T) { func testAttributeSRemAlsPrf(t *testing.T) { var resp string - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -993,14 +994,14 @@ func testAttributeSRemAlsPrf(t *testing.T) { return } var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } // remove twice shoud return not found resp = "" - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &resp); err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err) } @@ -1033,13 +1034,13 @@ func testAttributeSSetAlsPrf2(t *testing.T) { } alsPrf.Compile() var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "golant", ID: "ATTR_972587832508_SESSIONAUTH"}}, &reply); err != nil { t.Fatal(err) } @@ -1075,7 +1076,7 @@ func testAttributeSSetAlsPrf3(t *testing.T) { }, } var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err == nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err == nil { t.Error(err) } } @@ -1104,14 +1105,14 @@ func testAttributeSSetAlsPrf4(t *testing.T) { }, } var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err == nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err == nil { t.Error(err) } } func testAttributeSPing(t *testing.T) { var resp string - if err := attrSRPC.Call(utils.AttributeSv1Ping, new(utils.CGREvent), &resp); err != nil { + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1Ping, new(utils.CGREvent), &resp); err != nil { t.Error(err) } else if resp != utils.Pong { t.Error("Unexpected reply returned", resp) @@ -1139,7 +1140,7 @@ func testAttributeSProcessEventWithSearchAndReplace(t *testing.T) { }, } var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1171,7 +1172,7 @@ func testAttributeSProcessEventWithSearchAndReplace(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, attrArgs, &rplyEv); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRply, &rplyEv) { @@ -1237,17 +1238,17 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { } // Add attribute in DM var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf3, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf3, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1281,7 +1282,7 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, attrArgs, &rplyEv); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(eRply.MatchedProfiles, rplyEv.MatchedProfiles) { @@ -1352,17 +1353,17 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { } // Add attributeProfiles var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf3, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf3, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1397,7 +1398,7 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, attrArgs, &rplyEv); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(eRply.MatchedProfiles, rplyEv.MatchedProfiles) { @@ -1413,20 +1414,20 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { func testAttributeSGetAttributeProfileIDsCount(t *testing.T) { var reply int - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileCount, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileCount, &utils.TenantWithAPIOpts{}, &reply); err != nil { t.Error(err) } else if reply != 7 { t.Errorf("Expecting: 7, received: %+v", reply) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileCount, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileCount, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) } else if reply != 7 { t.Errorf("Expecting: 7, received: %+v", reply) } var resp string - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: "cgrates.org", ID: "ATTR_1", @@ -1438,13 +1439,13 @@ func testAttributeSGetAttributeProfileIDsCount(t *testing.T) { } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileCount, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileCount, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) } else if reply != 6 { t.Errorf("Expecting: 6, received: %+v", reply) } - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: "cgrates.org", ID: "ATTR_2", @@ -1456,13 +1457,13 @@ func testAttributeSGetAttributeProfileIDsCount(t *testing.T) { } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileCount, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileCount, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) } else if reply != 5 { t.Errorf("Expecting: 5, received: %+v", reply) } - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: "cgrates.org", ID: "ATTR_3", @@ -1474,13 +1475,13 @@ func testAttributeSGetAttributeProfileIDsCount(t *testing.T) { } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileCount, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileCount, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) } else if reply != 4 { t.Errorf("Expecting: 4, received: %+v", reply) } - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: "cgrates.org", ID: "ATTR_Header", @@ -1492,13 +1493,13 @@ func testAttributeSGetAttributeProfileIDsCount(t *testing.T) { } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileCount, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileCount, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) } else if reply != 3 { t.Errorf("Expecting: 3, received: %+v", reply) } - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: "cgrates.org", ID: "ATTR_PASS", @@ -1510,13 +1511,13 @@ func testAttributeSGetAttributeProfileIDsCount(t *testing.T) { } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileCount, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileCount, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) } else if reply != 2 { t.Errorf("Expecting: 2, received: %+v", reply) } - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: "cgrates.org", ID: "ATTR_Search_and_replace", @@ -1529,13 +1530,13 @@ func testAttributeSGetAttributeProfileIDsCount(t *testing.T) { } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileCount, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileCount, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) } else if reply != 1 { t.Errorf("Expecting: 1, received: %+v", reply) } - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: "cgrates.org", ID: "AttributeWithNonSubstitute", @@ -1548,7 +1549,7 @@ func testAttributeSGetAttributeProfileIDsCount(t *testing.T) { } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileCount, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileCount, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -1586,7 +1587,7 @@ func testAttributeSCachingMetaNone(t *testing.T) { } // set the profile var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1596,7 +1597,7 @@ func testAttributeSCachingMetaNone(t *testing.T) { CacheID: utils.CacheAttributeProfiles, ItemID: "cgrates.org:ATTR_1", } - if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := attrSRPC.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: false, received:%v", reply) @@ -1606,7 +1607,7 @@ func testAttributeSCachingMetaNone(t *testing.T) { argsCache2 := utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheAttributeProfiles, } - if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || + if err := attrSRPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err.Error(), rcvKeys) @@ -1615,7 +1616,7 @@ func testAttributeSCachingMetaNone(t *testing.T) { //check in dataManager expected := []string{"ATTR_1"} var rcvIDs []string - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rcvIDs) { t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs) @@ -1647,7 +1648,7 @@ func testAttributeSCachingMetaLoad(t *testing.T) { } // set the profile var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1657,7 +1658,7 @@ func testAttributeSCachingMetaLoad(t *testing.T) { CacheID: utils.CacheAttributeProfiles, ItemID: "cgrates.org:ATTR_1", } - if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := attrSRPC.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: true, received:%v", reply) @@ -1668,7 +1669,7 @@ func testAttributeSCachingMetaLoad(t *testing.T) { argsCache2 := utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheAttributeProfiles, } - if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil { + if err := attrSRPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(rcvKeys, expectedIDs) { t.Errorf("Expecting : %+v, received: %+v", expectedIDs, rcvKeys) @@ -1679,7 +1680,7 @@ func testAttributeSCachingMetaLoad(t *testing.T) { CacheID: utils.CacheAttributeFilterIndexes, } expectedIDs = []string{"cgrates.org:*sessions:*string:*req.InitialField:InitialValue"} - if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil { + if err := attrSRPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(rcvKeys, expectedIDs) { t.Errorf("Expecting : %+v, received: %+v", expectedIDs, rcvKeys) @@ -1688,14 +1689,14 @@ func testAttributeSCachingMetaLoad(t *testing.T) { //check in dataManager expected := []string{"ATTR_1"} var rcvIDs []string - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rcvIDs) { t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs) } //remove from cache and DataManager the profile var resp string - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: attrPrf1.Tenant, ID: attrPrf1.ID}, APIOpts: map[string]any{ utils.CacheOpt: utils.MetaRemove, @@ -1709,20 +1710,20 @@ func testAttributeSCachingMetaLoad(t *testing.T) { CacheID: utils.CacheAttributeProfiles, ItemID: "cgrates.org:ATTR_1", } - if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := attrSRPC.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: false, received:%v", reply) } - if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || + if err := attrSRPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err, rcvKeys) } //check in dataManager - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err == nil || + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err, rcvIDs) @@ -1754,7 +1755,7 @@ func testAttributeSCachingMetaReload1(t *testing.T) { } // set the profile var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1764,7 +1765,7 @@ func testAttributeSCachingMetaReload1(t *testing.T) { CacheID: utils.CacheAttributeProfiles, ItemID: "cgrates.org:ATTR_1", } - if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := attrSRPC.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: false, received:%v", reply) @@ -1774,7 +1775,7 @@ func testAttributeSCachingMetaReload1(t *testing.T) { argsCache2 := utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheAttributeProfiles, } - if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || + if err := attrSRPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err, rcvKeys) @@ -1783,7 +1784,7 @@ func testAttributeSCachingMetaReload1(t *testing.T) { //check in dataManager expected := []string{"ATTR_1"} var rcvIDs []string - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rcvIDs) { t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs) @@ -1815,14 +1816,14 @@ func testAttributeSCachingMetaReload2(t *testing.T) { } // set the profile var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1"}}, &reply); err != nil { t.Fatal(err) } @@ -1856,13 +1857,13 @@ func testAttributeSCachingMetaReload2(t *testing.T) { }, } // set the profile - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1"}}, &reply); err != nil { t.Fatal(err) } @@ -1898,7 +1899,7 @@ func testAttributeSCachingMetaRemove(t *testing.T) { } // set the profile var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1908,7 +1909,7 @@ func testAttributeSCachingMetaRemove(t *testing.T) { CacheID: utils.CacheAttributeProfiles, ItemID: "cgrates.org:ATTR_1", } - if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := attrSRPC.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: true, received:%v", reply) @@ -1919,7 +1920,7 @@ func testAttributeSCachingMetaRemove(t *testing.T) { argsCache2 := utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheAttributeProfiles, } - if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil { + if err := attrSRPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(rcvKeys, expectedIDs) { t.Errorf("Expecting : %+v, received: %+v", expectedIDs, rcvKeys) @@ -1949,19 +1950,19 @@ func testAttributeSCachingMetaRemove(t *testing.T) { }, } // set the profile - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil { + if err := attrSRPC.Call(context.Background(), utils.CacheSv1HasItem, argsCache, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: false, received:%v", reply) } - if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || + if err := attrSRPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err.Error(), rcvKeys) @@ -1970,7 +1971,7 @@ func testAttributeSCachingMetaRemove(t *testing.T) { //check in dataManager expected := []string{"ATTR_1"} var rcvIDs []string - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rcvIDs) { t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs) @@ -1996,7 +1997,7 @@ func testAttributeSSetAttributeWithEmptyPath(t *testing.T) { }, } var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, eAttrPrf2, &result); err == nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, eAttrPrf2, &result); err == nil { t.Errorf("Expected error received nil") } } @@ -2026,7 +2027,7 @@ func testAttributeSCacheOpts(t *testing.T) { } // set the profile var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -2054,14 +2055,14 @@ func testAttributeSSetAlsPrfWithoutTenant(t *testing.T) { }, } alsPrf.Compile() - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &reply); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } alsPrf.AttributeProfile.Tenant = "cgrates.org" var result *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "ApierTest1"}}, &result); err != nil { t.Error(err) @@ -2072,7 +2073,7 @@ func testAttributeSSetAlsPrfWithoutTenant(t *testing.T) { func testAttributeSRmvAlsPrfWithoutTenant(t *testing.T) { var reply string - if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "ApierTest1"}}, &reply); err != nil { t.Error(err) @@ -2080,7 +2081,7 @@ func testAttributeSRmvAlsPrfWithoutTenant(t *testing.T) { t.Error("Unexpected reply returned", reply) } var result *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "ApierTest1"}}, &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -2100,7 +2101,7 @@ func testAttributeSCacheTestProcessEventNotFound(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -2119,7 +2120,7 @@ func testAttributeSCacheTestProcessEventFound(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrSRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } @@ -2146,7 +2147,7 @@ func testAttributeSCacheTestSetProfile(t *testing.T) { } // set the profile var result string - if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -2159,7 +2160,7 @@ func testAttributeSCacheTestReload(t *testing.T) { AttributeProfileIDs: []string{"cgrates.org:ATTR_CACHE"}, } var reply string - if err := attrSRPC.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil { + if err := attrSRPC.Call(context.Background(), utils.CacheSv1ReloadCache, cache, &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Error("Calling CacheSv1.ReloadCache got reply: ", reply) diff --git a/apier/v1/auth.go b/apier/v1/auth.go index c2d4a86ee..15c3f6f61 100644 --- a/apier/v1/auth.go +++ b/apier/v1/auth.go @@ -22,12 +22,13 @@ import ( "strconv" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // Returns MaxUsage (for calls in seconds), -1 for no limit -func (apierSv1 *APIerSv1) GetMaxUsage(usageRecord *engine.UsageRecordWithAPIOpts, maxUsage *int64) error { +func (apierSv1 *APIerSv1) GetMaxUsage(ctx *context.Context, usageRecord *engine.UsageRecordWithAPIOpts, maxUsage *int64) error { if apierSv1.Responder == nil { return utils.NewErrNotConnected(utils.RALService) } @@ -58,10 +59,11 @@ func (apierSv1 *APIerSv1) GetMaxUsage(usageRecord *engine.UsageRecordWithAPIOpts return utils.NewErrServerError(err) } var maxDur time.Duration - if err := apierSv1.Responder.GetMaxSessionTime(&engine.CallDescriptorWithAPIOpts{ - CallDescriptor: cd, - APIOpts: usageRecord.APIOpts, - }, &maxDur); err != nil { + if err := apierSv1.Responder.GetMaxSessionTime(ctx, + &engine.CallDescriptorWithAPIOpts{ + CallDescriptor: cd, + APIOpts: usageRecord.APIOpts, + }, &maxDur); err != nil { return err } if maxDur == time.Duration(-1) { diff --git a/apier/v1/cache_replication_it_test.go b/apier/v1/cache_replication_it_test.go index 397c025f5..2069a0be0 100644 --- a/apier/v1/cache_replication_it_test.go +++ b/apier/v1/cache_replication_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,10 +38,10 @@ import ( var ( engine1Cfg *config.CGRConfig - engine1RPC *rpc.Client + engine1RPC *birpc.Client engine1CfgPath string engine2Cfg *config.CGRConfig - engine2RPC *rpc.Client + engine2RPC *birpc.Client engine2CfgPath string sTestsCacheSReplicate = []func(t *testing.T){ @@ -117,7 +118,7 @@ func testCacheSReplicateRpcConn(t *testing.T) { func testCacheSReplicateLoadTariffPlanFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := engine2RPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := engine2RPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) @@ -150,7 +151,7 @@ func testCacheSReplicateProcessAttributes(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := engine1RPC.Call(utils.AttributeSv1ProcessEvent, + if err := engine1RPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } else { @@ -161,7 +162,7 @@ func testCacheSReplicateProcessAttributes(t *testing.T) { utils.ToJSON(eRply), utils.ToJSON(rplyEv)) } } - if err := engine2RPC.Call(utils.AttributeSv1ProcessEvent, + if err := engine2RPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } else { diff --git a/apier/v1/caches.go b/apier/v1/caches.go index 1202e98b8..5cab6d0c7 100644 --- a/apier/v1/caches.go +++ b/apier/v1/caches.go @@ -21,6 +21,7 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" @@ -36,110 +37,110 @@ type CacheSv1 struct { } // GetItemIDs returns the IDs for cacheID with given prefix -func (chSv1 *CacheSv1) GetItemIDs(args *utils.ArgsGetCacheItemIDsWithAPIOpts, +func (chSv1 *CacheSv1) GetItemIDs(ctx *context.Context, args *utils.ArgsGetCacheItemIDsWithAPIOpts, reply *[]string) error { - return chSv1.cacheS.V1GetItemIDs(args, reply) + return chSv1.cacheS.V1GetItemIDs(ctx, args, reply) } // HasItem verifies the existence of an Item in cache -func (chSv1 *CacheSv1) HasItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (chSv1 *CacheSv1) HasItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *bool) error { - return chSv1.cacheS.V1HasItem(args, reply) + return chSv1.cacheS.V1HasItem(ctx, args, reply) } // GetItem returns an Item from the cache -func (chSv1 *CacheSv1) GetItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (chSv1 *CacheSv1) GetItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *any) error { - return chSv1.cacheS.V1GetItem(args, reply) + return chSv1.cacheS.V1GetItem(ctx, args, reply) } // GetItemWithRemote returns an Item from local or remote cache -func (chSv1 *CacheSv1) GetItemWithRemote(args *utils.ArgsGetCacheItemWithAPIOpts, +func (chSv1 *CacheSv1) GetItemWithRemote(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *any) error { - return chSv1.cacheS.V1GetItemWithRemote(args, reply) + return chSv1.cacheS.V1GetItemWithRemote(ctx, args, reply) } // GetItemExpiryTime returns the expiryTime for an item -func (chSv1 *CacheSv1) GetItemExpiryTime(args *utils.ArgsGetCacheItemWithAPIOpts, +func (chSv1 *CacheSv1) GetItemExpiryTime(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *time.Time) error { - return chSv1.cacheS.V1GetItemExpiryTime(args, reply) + return chSv1.cacheS.V1GetItemExpiryTime(ctx, args, reply) } // RemoveItem removes the Item with ID from cache -func (chSv1 *CacheSv1) RemoveItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (chSv1 *CacheSv1) RemoveItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *string) error { - return chSv1.cacheS.V1RemoveItem(args, reply) + return chSv1.cacheS.V1RemoveItem(ctx, args, reply) } // RemoveItems removes the Items with ID from cache -func (chSv1 *CacheSv1) RemoveItems(args *utils.AttrReloadCacheWithAPIOpts, +func (chSv1 *CacheSv1) RemoveItems(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) error { - return chSv1.cacheS.V1RemoveItems(args, reply) + return chSv1.cacheS.V1RemoveItems(ctx, args, reply) } // Clear will clear partitions in the cache (nil fol all, empty slice for none) -func (chSv1 *CacheSv1) Clear(args *utils.AttrCacheIDsWithAPIOpts, +func (chSv1 *CacheSv1) Clear(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, reply *string) error { - return chSv1.cacheS.V1Clear(args, reply) + return chSv1.cacheS.V1Clear(ctx, args, reply) } // GetCacheStats returns CacheStats filtered by cacheIDs -func (chSv1 *CacheSv1) GetCacheStats(args *utils.AttrCacheIDsWithAPIOpts, +func (chSv1 *CacheSv1) GetCacheStats(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, rply *map[string]*ltcache.CacheStats) error { - return chSv1.cacheS.V1GetCacheStats(args, rply) + return chSv1.cacheS.V1GetCacheStats(ctx, args, rply) } // PrecacheStatus checks status of active precache processes -func (chSv1 *CacheSv1) PrecacheStatus(args *utils.AttrCacheIDsWithAPIOpts, rply *map[string]string) error { - return chSv1.cacheS.V1PrecacheStatus(args, rply) +func (chSv1 *CacheSv1) PrecacheStatus(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, rply *map[string]string) error { + return chSv1.cacheS.V1PrecacheStatus(ctx, args, rply) } // HasGroup checks existence of a group in cache -func (chSv1 *CacheSv1) HasGroup(args *utils.ArgsGetGroupWithAPIOpts, +func (chSv1 *CacheSv1) HasGroup(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, rply *bool) (err error) { - return chSv1.cacheS.V1HasGroup(args, rply) + return chSv1.cacheS.V1HasGroup(ctx, args, rply) } // GetGroupItemIDs returns a list of itemIDs in a cache group -func (chSv1 *CacheSv1) GetGroupItemIDs(args *utils.ArgsGetGroupWithAPIOpts, +func (chSv1 *CacheSv1) GetGroupItemIDs(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, rply *[]string) (err error) { - return chSv1.cacheS.V1GetGroupItemIDs(args, rply) + return chSv1.cacheS.V1GetGroupItemIDs(ctx, args, rply) } // RemoveGroup will remove a group and all items belonging to it from cache -func (chSv1 *CacheSv1) RemoveGroup(args *utils.ArgsGetGroupWithAPIOpts, +func (chSv1 *CacheSv1) RemoveGroup(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, rply *string) (err error) { - return chSv1.cacheS.V1RemoveGroup(args, rply) + return chSv1.cacheS.V1RemoveGroup(ctx, args, rply) } // ReloadCache reloads cache from DB for a prefix or completely -func (chSv1 *CacheSv1) ReloadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { - return chSv1.cacheS.V1ReloadCache(args, reply) +func (chSv1 *CacheSv1) ReloadCache(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { + return chSv1.cacheS.V1ReloadCache(ctx, args, reply) } // LoadCache loads cache from DB for a prefix or completely -func (chSv1 *CacheSv1) LoadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { - return chSv1.cacheS.V1LoadCache(args, reply) +func (chSv1 *CacheSv1) LoadCache(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { + return chSv1.cacheS.V1LoadCache(ctx, args, reply) } // Ping used to determinate if component is active -func (chSv1 *CacheSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (chSv1 *CacheSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } // ReplicateSet replicate an item -func (chSv1 *CacheSv1) ReplicateSet(args *utils.ArgCacheReplicateSet, reply *string) (err error) { - return chSv1.cacheS.V1ReplicateSet(args, reply) +func (chSv1 *CacheSv1) ReplicateSet(ctx *context.Context, args *utils.ArgCacheReplicateSet, reply *string) (err error) { + return chSv1.cacheS.V1ReplicateSet(ctx, args, reply) } // ReplicateRemove remove an item -func (chSv1 *CacheSv1) ReplicateRemove(args *utils.ArgCacheReplicateRemove, reply *string) (err error) { - return chSv1.cacheS.V1ReplicateRemove(args, reply) +func (chSv1 *CacheSv1) ReplicateRemove(ctx *context.Context, args *utils.ArgCacheReplicateRemove, reply *string) (err error) { + return chSv1.cacheS.V1ReplicateRemove(ctx, args, reply) } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (chSv1 *CacheSv1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (chSv1 *CacheSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(chSv1, serviceMethod, args, reply) } diff --git a/apier/v1/caches_it_test.go b/apier/v1/caches_it_test.go index 96bd8ae13..5cdb00ae5 100644 --- a/apier/v1/caches_it_test.go +++ b/apier/v1/caches_it_test.go @@ -21,12 +21,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -35,7 +36,7 @@ import ( var ( chcCfg *config.CGRConfig - chcRPC *rpc.Client + chcRPC *birpc.Client chcCfgPath string cacheConfigDIR string @@ -121,7 +122,7 @@ func testCacheSRpcConn(t *testing.T) { func testCacheSLoadTariffPlanFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testtp")} - if err := chcRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) @@ -134,14 +135,14 @@ func testCacheSAfterLoadFromFolder(t *testing.T) { expStats[utils.CacheDestinations].Items = 3 expStats[utils.CacheLoadIDs].Items = 18 expStats[utils.CacheRPCConnections].Items = 2 - if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expStats, rcvStats) { t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats)) } reply := "" // Simple test that command is executed without errors - if err := chcRPC.Call(utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(reply) @@ -177,7 +178,7 @@ func testCacheSAfterLoadFromFolder(t *testing.T) { expStats[utils.CacheReverseFilterIndexes].Items = 10 expStats[utils.CacheReverseFilterIndexes].Groups = 7 - if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { t.Error(err) } else if !reflect.DeepEqual(expStats, rcvStats) { t.Errorf("Expecting: %+v,\n received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats)) @@ -186,7 +187,7 @@ func testCacheSAfterLoadFromFolder(t *testing.T) { func testCacheSFlush(t *testing.T) { reply := "" - if err := chcRPC.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := chcRPC.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ CacheIDs: nil, }, &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) @@ -195,7 +196,7 @@ func testCacheSFlush(t *testing.T) { } var rcvStats map[string]*ltcache.CacheStats expStats := engine.GetDefaultEmptyCacheStats() - if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expStats, rcvStats) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats)) @@ -207,7 +208,7 @@ func testCacheSReload(t *testing.T) { expStats := engine.GetDefaultEmptyCacheStats() reply := "" // Simple test that command is executed without errors - if err := chcRPC.Call(utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(reply) @@ -245,7 +246,7 @@ func testCacheSReload(t *testing.T) { expStats[utils.CacheReverseFilterIndexes].Items = 10 expStats[utils.CacheReverseFilterIndexes].Groups = 7 - if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { t.Error(err) } rcvStats[utils.MetaAPIBan].Items = 0 @@ -261,7 +262,7 @@ func testCacheSGetItemIDs(t *testing.T) { CacheID: utils.CacheThresholdProfiles, ItemIDPrefix: "NotExistent", } - if err := chcRPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := chcRPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err.Error(), rcvKeys) } @@ -269,7 +270,7 @@ func testCacheSGetItemIDs(t *testing.T) { argsAPI = utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheThresholdProfiles, } - if err := chcRPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Fatalf("Got error on APIerSv1.GetCacheStats: %s ", err.Error()) } if !reflect.DeepEqual(expKeys, rcvKeys) { @@ -284,7 +285,7 @@ func testCacheSHasItem(t *testing.T) { CacheID: utils.CacheThresholdProfiles, ItemID: "NotExistent", } - if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: %v , received:%v", expected, reply) @@ -295,7 +296,7 @@ func testCacheSHasItem(t *testing.T) { CacheID: utils.CacheThresholdProfiles, ItemID: "cgrates.org:Threshold1", } - if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: %v , received:%v", expected, reply) @@ -309,7 +310,7 @@ func testCacheSGetItemExpiryTime(t *testing.T) { CacheID: utils.CacheThresholdProfiles, ItemID: "NotExistent", } - if err := chcRPC.Call(utils.CacheSv1GetItemExpiryTime, argsAPI, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := chcRPC.Call(context.Background(), utils.CacheSv1GetItemExpiryTime, argsAPI, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err.Error(), reply) } @@ -318,7 +319,7 @@ func testCacheSGetItemExpiryTime(t *testing.T) { CacheID: utils.CacheThresholdProfiles, ItemID: "cgrates.org:Threshold1", } - if err := chcRPC.Call(utils.CacheSv1GetItemExpiryTime, argsAPI, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1GetItemExpiryTime, argsAPI, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, reply) { t.Errorf("Expected: %v , received:%v", expected, reply) @@ -327,7 +328,7 @@ func testCacheSGetItemExpiryTime(t *testing.T) { func testCacheSReloadCache(t *testing.T) { var reply string - if err := chcRPC.Call(utils.CacheSv1ReloadCache, new(utils.AttrReloadCacheWithAPIOpts), &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1ReloadCache, new(utils.AttrReloadCacheWithAPIOpts), &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Error("Calling CacheSv1.ReloadCache got reply: ", reply) @@ -340,18 +341,18 @@ func testCacheSRemoveItem(t *testing.T) { CacheID: utils.CacheThresholdProfiles, ItemID: "cgrates.org:Threshold1", } - if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: %v , received:%v", true, reply) } var remReply string - if err := chcRPC.Call(utils.CacheSv1RemoveItem, argsAPI, &remReply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1RemoveItem, argsAPI, &remReply); err != nil { t.Error(err) } else if remReply != utils.OK { t.Errorf("Expected: %v , received:%v", utils.OK, remReply) } - if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: %v , received:%v", false, reply) @@ -364,7 +365,7 @@ func testCacheSRemoveItems(t *testing.T) { // argsAPI2 := utils.ArgsGetCacheItemIDs{ // CacheID: utils.CacheStatQueueProfiles, // } - // if err := chcRPC.Call(utils.CacheSv1GetItemIDs, argsAPI2, &rcvKeys); err != nil { + // if err := chcRPC.Call(context.Background(),utils.CacheSv1GetItemIDs, argsAPI2, &rcvKeys); err != nil { // t.Fatalf("Got error on APIerSv1.GetCacheStats: %s ", err.Error()) // } // if !reflect.DeepEqual(expKeys, rcvKeys) { @@ -376,7 +377,7 @@ func testCacheSRemoveItems(t *testing.T) { ItemID: "cgrates.org:Stats1", } - if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: %v , received:%v", true, reply) @@ -386,13 +387,13 @@ func testCacheSRemoveItems(t *testing.T) { ItemID: "cgrates.org:ROUTE_1", } - if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: %v , received:%v", true, reply) } var remReply string - if err := chcRPC.Call(utils.CacheSv1RemoveItems, &utils.AttrReloadCacheWithAPIOpts{ + if err := chcRPC.Call(context.Background(), utils.CacheSv1RemoveItems, &utils.AttrReloadCacheWithAPIOpts{ APIOpts: make(map[string]any), Tenant: "cgrates.org", StatsQueueProfileIDs: []string{"cgrates.org:Stats1"}, @@ -402,7 +403,7 @@ func testCacheSRemoveItems(t *testing.T) { } else if remReply != utils.OK { t.Errorf("Expected: %v , received:%v", utils.OK, remReply) } - if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: %v , received:%v", false, reply) @@ -413,7 +414,7 @@ func testCacheSRemoveItems(t *testing.T) { ItemID: "cgrates.org:Stats1", } - if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: %v , received:%v", false, reply) @@ -422,14 +423,14 @@ func testCacheSRemoveItems(t *testing.T) { func testCacheSClear(t *testing.T) { reply := "" - if err := chcRPC.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Calling CacheSv1.ReloadCache got reply: ", reply) } var rcvStats map[string]*ltcache.CacheStats expStats := engine.GetDefaultEmptyCacheStats() - if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expStats, rcvStats) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats)) @@ -442,7 +443,7 @@ func testCacheSPrecacheStatus(t *testing.T) { for k := range utils.CachePartitions { expected[k] = utils.MetaReady } - if err := chcRPC.Call(utils.CacheSv1PrecacheStatus, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1PrecacheStatus, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil { t.Fatal(err) } reply[utils.MetaAPIBan] = utils.MetaReady // do not check the status for this partition @@ -454,7 +455,7 @@ func testCacheSPrecacheStatus(t *testing.T) { func testCacheSPing(t *testing.T) { var reply string expected := utils.Pong - if err := chcRPC.Call(utils.CacheSv1Ping, &utils.CGREvent{}, &reply); err != nil { + if err := chcRPC.Call(context.Background(), utils.CacheSv1Ping, &utils.CGREvent{}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, reply) { t.Errorf("Expected: %v , received:%v", utils.ToJSON(expected), utils.ToJSON(reply)) diff --git a/apier/v1/caches_test.go b/apier/v1/caches_test.go index 655d81563..7b335747c 100644 --- a/apier/v1/caches_test.go +++ b/apier/v1/caches_test.go @@ -20,6 +20,7 @@ package v1 import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -35,7 +36,7 @@ func TestCacheLoadCache(t *testing.T) { cache := NewCacheSv1(ch) var reply string - if err := cache.LoadCache(utils.NewAttrReloadCacheWithOpts(), + if err := cache.LoadCache(context.Background(), utils.NewAttrReloadCacheWithOpts(), &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -48,7 +49,7 @@ func TestCacheLoadCache(t *testing.T) { }, } var replyStr []string - if err := cache.GetItemIDs(argsGetItem, + if err := cache.GetItemIDs(context.Background(), argsGetItem, &replyStr); err == nil || err != utils.ErrNotFound { t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err) } @@ -64,7 +65,7 @@ func TestCacheReloadCache(t *testing.T) { cache := NewCacheSv1(ch) var reply string - if err := cache.ReloadCache(utils.NewAttrReloadCacheWithOpts(), + if err := cache.ReloadCache(context.Background(), utils.NewAttrReloadCacheWithOpts(), &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -77,7 +78,7 @@ func TestCacheReloadCache(t *testing.T) { }, } var replyStr []string - if err := cache.GetItemIDs(argsGetItem, + if err := cache.GetItemIDs(context.Background(), argsGetItem, &replyStr); err == nil || err != utils.ErrNotFound { t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err) } @@ -99,7 +100,7 @@ func TestCacheSetAndRemoveItems(t *testing.T) { "cgrates.org:TestCacheSetAndRemoveItems2", "cgrates.org:TestCacheSetAndRemoveItems3"}, } var reply string - if err := cache.RemoveItems(argsRemItm, &reply); err != nil { + if err := cache.RemoveItems(context.Background(), argsRemItm, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected replyBool returned") @@ -112,19 +113,19 @@ func TestCacheSetAndRemoveItems(t *testing.T) { }, } var replyBool bool - if err := cache.HasItem(argsHasItem, &replyBool); err != nil { + if err := cache.HasItem(context.Background(), argsHasItem, &replyBool); err != nil { t.Error(err) } else if replyBool { t.Errorf("Unexpected replyBool returned") } argsHasItem.ArgsGetCacheItem.ItemID = "cgrates.org:TestCacheSetAndRemoveItems2" - if err := cache.HasItem(argsHasItem, &replyBool); err != nil { + if err := cache.HasItem(context.Background(), argsHasItem, &replyBool); err != nil { t.Error(err) } else if replyBool { t.Errorf("Unexpected replyBool returned") } argsHasItem.ArgsGetCacheItem.ItemID = "cgrates.org:TestCacheSetAndRemoveItems3" - if err := cache.HasItem(argsHasItem, &replyBool); err != nil { + if err := cache.HasItem(context.Background(), argsHasItem, &replyBool); err != nil { t.Error(err) } else if replyBool { t.Errorf("Unexpected replyBool returned") @@ -136,7 +137,7 @@ func TestCacheSetAndRemoveItems(t *testing.T) { }, } var replyStr []string - if err := cache.GetItemIDs(argsGetItem, &replyStr); err == nil || err != utils.ErrNotFound { + if err := cache.GetItemIDs(context.Background(), argsGetItem, &replyStr); err == nil || err != utils.ErrNotFound { t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err) } } diff --git a/apier/v1/caps_it_test.go b/apier/v1/caps_it_test.go index ff0b3bb46..ee056082e 100644 --- a/apier/v1/caps_it_test.go +++ b/apier/v1/caps_it_test.go @@ -26,15 +26,14 @@ import ( "fmt" "io" "net/http" - "net/rpc" "path" "strings" "sync" "testing" "time" - "github.com/cenkalti/rpc2" - + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -43,8 +42,8 @@ import ( var ( capsCfgPath string capsCfg *config.CGRConfig - capsRPC *rpc.Client - capsBiRPC *rpc2.Client + capsRPC *birpc.Client + capsBiRPC *birpc.BirpcClient capsConfigDIR string //run tests for specific configuration sTestsCaps = []func(t *testing.T){ @@ -121,7 +120,7 @@ func testCapsBusyAPIs(t *testing.T) { go func() { defer wg.Done() var resp string - if err := capsRPC.Call(utils.CoreSv1Sleep, + if err := capsRPC.Call(context.Background(), utils.CoreSv1Sleep, &utils.DurationArgs{Duration: 10 * time.Millisecond}, &resp); err != nil { lock.Lock() @@ -147,7 +146,7 @@ func testCapsQueueAPIs(t *testing.T) { go func() { defer wg.Done() var resp string - if err := capsRPC.Call(utils.CoreSv1Sleep, + if err := capsRPC.Call(context.Background(), utils.CoreSv1Sleep, &utils.DurationArgs{Duration: 10 * time.Millisecond}, &resp); err != nil { t.Error(err) @@ -227,8 +226,10 @@ func testCapsOnBiJSONBusy(t *testing.T) { go func() { defer wg.Done() var resp string - if err := capsBiRPC.Call(utils.SessionSv1Sleep, &utils.DurationArgs{ - Duration: 10 * time.Millisecond}, &resp); err != nil { + if err := capsBiRPC.Call(context.Background(), utils.SessionSv1Sleep, + &utils.DurationArgs{ + Duration: 10 * time.Millisecond, + }, &resp); err != nil { errChan <- err lock.Lock() failedAPIs++ @@ -268,7 +269,7 @@ func testCapsOnBiJSONQueue(t *testing.T) { go func() { defer wg.Done() var resp string - if err := capsBiRPC.Call(utils.SessionSv1Sleep, + if err := capsBiRPC.Call(context.Background(), utils.SessionSv1Sleep, &utils.DurationArgs{Duration: 10 * time.Millisecond}, &resp); err != nil { t.Error(err) @@ -312,7 +313,7 @@ func benchmarkInit(b *testing.B, cfgDir string) { func benchmarkCall(b *testing.B) { var rply map[string]any for i := 0; i < b.N; i++ { - if err := capsRPC.Call(utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil { + if err := capsRPC.Call(context.Background(), utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil { b.Error(err) } } diff --git a/apier/v1/cdrs.go b/apier/v1/cdrs.go index 613b7c9e6..cc365f809 100644 --- a/apier/v1/cdrs.go +++ b/apier/v1/cdrs.go @@ -19,12 +19,13 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // Retrieves the callCost out of CGR logDb -func (apierSv1 *APIerSv1) GetEventCost(attrs *utils.AttrGetCallCost, reply *engine.EventCost) error { +func (apierSv1 *APIerSv1) GetEventCost(ctx *context.Context, attrs *utils.AttrGetCallCost, reply *engine.EventCost) error { if attrs.CgrId == utils.EmptyString { return utils.NewErrMandatoryIeMissing("CgrId") } @@ -50,7 +51,7 @@ func (apierSv1 *APIerSv1) GetEventCost(attrs *utils.AttrGetCallCost, reply *engi } // Retrieves CDRs based on the filters -func (apierSv1 *APIerSv1) GetCDRs(attrs *utils.AttrGetCdrs, reply *[]*engine.ExternalCDR) error { +func (apierSv1 *APIerSv1) GetCDRs(ctx *context.Context, attrs *utils.AttrGetCdrs, reply *[]*engine.ExternalCDR) error { cdrsFltr, err := attrs.AsCDRsFilter(apierSv1.Config.GeneralCfg().DefaultTimezone) if err != nil { return utils.NewErrServerError(err) @@ -68,7 +69,7 @@ func (apierSv1 *APIerSv1) GetCDRs(attrs *utils.AttrGetCdrs, reply *[]*engine.Ext } // New way of removing CDRs -func (apierSv1 *APIerSv1) RemoveCDRs(attrs *utils.RPCCDRsFilter, reply *string) error { +func (apierSv1 *APIerSv1) RemoveCDRs(ctx *context.Context, attrs *utils.RPCCDRsFilter, reply *string) error { cdrsFilter, err := attrs.AsCDRsFilter(apierSv1.Config.GeneralCfg().DefaultTimezone) if err != nil { return utils.NewErrServerError(err) @@ -90,39 +91,39 @@ type CDRsV1 struct { } // ProcessCDR will process a CDR in CGRateS internal format -func (cdrSv1 *CDRsV1) ProcessCDR(cdr *engine.CDRWithAPIOpts, reply *string) error { - return cdrSv1.CDRs.V1ProcessCDR(cdr, reply) +func (cdrSv1 *CDRsV1) ProcessCDR(ctx *context.Context, cdr *engine.CDRWithAPIOpts, reply *string) error { + return cdrSv1.CDRs.V1ProcessCDR(ctx, cdr, reply) } // ProcessEvent will process an Event based on the flags attached -func (cdrSv1 *CDRsV1) ProcessEvent(arg *engine.ArgV1ProcessEvent, reply *string) error { - return cdrSv1.CDRs.V1ProcessEvent(arg, reply) +func (cdrSv1 *CDRsV1) ProcessEvent(ctx *context.Context, arg *engine.ArgV1ProcessEvent, reply *string) error { + return cdrSv1.CDRs.V1ProcessEvent(ctx, arg, reply) } // ProcessExternalCDR will process a CDR in external format -func (cdrSv1 *CDRsV1) ProcessExternalCDR(cdr *engine.ExternalCDRWithAPIOpts, reply *string) error { - return cdrSv1.CDRs.V1ProcessExternalCDR(cdr, reply) +func (cdrSv1 *CDRsV1) ProcessExternalCDR(ctx *context.Context, cdr *engine.ExternalCDRWithAPIOpts, reply *string) error { + return cdrSv1.CDRs.V1ProcessExternalCDR(ctx, cdr, reply) } // RateCDRs can re-/rate remotely CDRs -func (cdrSv1 *CDRsV1) RateCDRs(arg *engine.ArgRateCDRs, reply *string) error { - return cdrSv1.CDRs.V1RateCDRs(arg, reply) +func (cdrSv1 *CDRsV1) RateCDRs(ctx *context.Context, arg *engine.ArgRateCDRs, reply *string) error { + return cdrSv1.CDRs.V1RateCDRs(ctx, arg, reply) } // StoreSMCost will store -func (cdrSv1 *CDRsV1) StoreSessionCost(attr *engine.AttrCDRSStoreSMCost, reply *string) error { - return cdrSv1.CDRs.V1StoreSessionCost(attr, reply) +func (cdrSv1 *CDRsV1) StoreSessionCost(ctx *context.Context, attr *engine.AttrCDRSStoreSMCost, reply *string) error { + return cdrSv1.CDRs.V1StoreSessionCost(ctx, attr, reply) } -func (cdrSv1 *CDRsV1) GetCDRsCount(args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) error { - return cdrSv1.CDRs.V1CountCDRs(args, reply) +func (cdrSv1 *CDRsV1) GetCDRsCount(ctx *context.Context, args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) error { + return cdrSv1.CDRs.V1GetCDRsCount(ctx, args, reply) } -func (cdrSv1 *CDRsV1) GetCDRs(args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) error { - return cdrSv1.CDRs.V1GetCDRs(*args, reply) +func (cdrSv1 *CDRsV1) GetCDRs(ctx *context.Context, args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) error { + return cdrSv1.CDRs.V1GetCDRs(ctx, *args, reply) } -func (cdrSv1 *CDRsV1) Ping(ign *utils.CGREvent, reply *string) error { +func (cdrSv1 *CDRsV1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } diff --git a/apier/v1/cdrs_it_test.go b/apier/v1/cdrs_it_test.go index b709998d9..60b5a836b 100644 --- a/apier/v1/cdrs_it_test.go +++ b/apier/v1/cdrs_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -34,7 +35,7 @@ import ( var ( cdrsCfgPath string cdrsCfg *config.CGRConfig - cdrsRpc *rpc.Client + cdrsRpc *birpc.Client cdrsConfDIR string // run the tests for specific configuration sTestsCDRsIT = []func(t *testing.T){ @@ -117,7 +118,7 @@ func testV1CDRsRpcConn(t *testing.T) { func testV1CDRsLoadTariffPlanFromFolder(t *testing.T) { var loadInst string - if err := cdrsRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, &utils.AttrLoadTpFromFolder{FolderPath: path.Join( *dataDir, "tariffplans", "testit")}, &loadInst); err != nil { t.Error(err) @@ -141,7 +142,7 @@ func testV1CDRsProcessEventWithRefund(t *testing.T) { }, } var reply string - if err := cdrsRpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("received: %s", reply) @@ -156,13 +157,13 @@ func testV1CDRsProcessEventWithRefund(t *testing.T) { utils.Weight: 10, }, } - if err := cdrsRpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("received: <%s>", reply) } expectedVoice := 300000000000.0 - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != expectedVoice { t.Errorf("Expecting: %v, received: %v", expectedVoice, rply) @@ -182,13 +183,13 @@ func testV1CDRsProcessEventWithRefund(t *testing.T) { }, }, } - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } var cdrs []*engine.ExternalCDR - if err := cdrsRpc.Call(utils.APIerSv1GetCDRs, &utils.AttrGetCdrs{}, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetCDRs, &utils.AttrGetCdrs{}, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -197,7 +198,7 @@ func testV1CDRsProcessEventWithRefund(t *testing.T) { t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost) } } - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if blc1 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE1"); blc1.Value != 0 { t.Errorf("Balance1 is: %s", utils.ToIJSON(blc1)) @@ -205,10 +206,10 @@ func testV1CDRsProcessEventWithRefund(t *testing.T) { t.Errorf("Balance2 is: %s", utils.ToIJSON(blc2)) } // without re-rate we should be denied - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err == nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err == nil { t.Error("should receive error here") } - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if blc1 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE1"); blc1.Value != 0 { t.Errorf("Balance1 is: %s", utils.ToIJSON(blc1)) @@ -230,12 +231,12 @@ func testV1CDRsProcessEventWithRefund(t *testing.T) { }, }, } - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if blc1 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE1"); blc1.Value != 60000000000 { t.Errorf("Balance1 is: %s", utils.ToIJSON(blc1)) @@ -261,14 +262,14 @@ func testV1CDRsRefundOutOfSessionCost(t *testing.T) { }, } var reply string - if err := cdrsRpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("received: %s", reply) } exp := 123.0 - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != exp { t.Errorf("Expecting: %v, received: %v", exp, rply) @@ -354,7 +355,7 @@ func testV1CDRsRefundOutOfSessionCost(t *testing.T) { }, }, } - if err := cdrsRpc.Call(utils.CDRsV1StoreSessionCost, + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1StoreSessionCost, attr, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -377,7 +378,7 @@ func testV1CDRsRefundOutOfSessionCost(t *testing.T) { }, }, } - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -386,7 +387,7 @@ func testV1CDRsRefundOutOfSessionCost(t *testing.T) { // Initial the balance was 123.0 // after refunc the balance become 123.0+2.3=125.3 exp = 124.0454 - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != exp { t.Errorf("Expecting: %v, received: %v", exp, rply) @@ -410,14 +411,14 @@ func testV1CDRsRefundCDR(t *testing.T) { }, } var reply string - if err := cdrsRpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("received: %s", reply) } exp := 123.0 - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != exp { t.Errorf("Expecting: %v, received: %v", exp, rply) @@ -510,7 +511,7 @@ func testV1CDRsRefundCDR(t *testing.T) { }, }, } - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -519,7 +520,7 @@ func testV1CDRsRefundCDR(t *testing.T) { // Initial the balance was 123.0 // after refund the balance become 123.0 + 2.3 = 125.3 exp = 125.3 - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != exp { t.Errorf("Expecting: %v, received: %v", exp, rply) @@ -528,7 +529,7 @@ func testV1CDRsRefundCDR(t *testing.T) { func testV1CDRsLoadTariffPlanFromFolderSMS(t *testing.T) { var loadInst string - if err := cdrsRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, &utils.AttrLoadTpFromFolder{FolderPath: path.Join( *dataDir, "tariffplans", "tutorial")}, &loadInst); err != nil { t.Error(err) @@ -544,7 +545,7 @@ func testV1CDRsAddBalanceForSMS(t *testing.T) { BalanceType: utils.MetaSMS, Value: 1000, } - if err := cdrsRpc.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -556,7 +557,7 @@ func testV1CDRsAddBalanceForSMS(t *testing.T) { BalanceType: utils.MetaMonetary, Value: 10, } - if err := cdrsRpc.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -568,7 +569,7 @@ func testV1CDRsAddBalanceForSMS(t *testing.T) { Account: "testV1CDRsAddBalanceForSMS", } - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaSMS]) != 1 { t.Errorf("Expecting: %v, received: %v", 1, len(acnt.BalanceMap[utils.MetaSMS])) @@ -598,13 +599,13 @@ func testV1CDRsAddBalanceForSMS(t *testing.T) { }, }, } - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaSMS]) != 1 { t.Errorf("Expecting: %v, received: %v", 1, len(acnt.BalanceMap[utils.MetaSMS])) diff --git a/apier/v1/chargers.go b/apier/v1/chargers.go index a26ab73c8..d23c4e7fa 100644 --- a/apier/v1/chargers.go +++ b/apier/v1/chargers.go @@ -21,12 +21,13 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // GetChargerProfile returns a Charger Profile -func (apierSv1 *APIerSv1) GetChargerProfile(arg *utils.TenantID, reply *engine.ChargerProfile) error { +func (apierSv1 *APIerSv1) GetChargerProfile(ctx *context.Context, arg *utils.TenantID, reply *engine.ChargerProfile) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -43,7 +44,7 @@ func (apierSv1 *APIerSv1) GetChargerProfile(arg *utils.TenantID, reply *engine.C } // GetChargerProfileIDs returns list of chargerProfile IDs registered for a tenant -func (apierSv1 *APIerSv1) GetChargerProfileIDs(args *utils.PaginatorWithTenant, chPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetChargerProfileIDs(ctx *context.Context, args *utils.PaginatorWithTenant, chPrfIDs *[]string) error { tnt := args.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -70,7 +71,7 @@ type ChargerWithAPIOpts struct { } // SetChargerProfile add/update a new Charger Profile -func (apierSv1 *APIerSv1) SetChargerProfile(arg *ChargerWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) SetChargerProfile(ctx *context.Context, arg *ChargerWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(arg.ChargerProfile, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -94,7 +95,7 @@ func (apierSv1 *APIerSv1) SetChargerProfile(arg *ChargerWithAPIOpts, reply *stri } // RemoveChargerProfile remove a specific Charger Profile -func (apierSv1 *APIerSv1) RemoveChargerProfile(arg *utils.TenantIDWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) RemoveChargerProfile(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -128,25 +129,25 @@ type ChargerSv1 struct { cS *engine.ChargerService } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (cSv1 *ChargerSv1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (cSv1 *ChargerSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(cSv1, serviceMethod, args, reply) } -func (cSv1 *ChargerSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (cSv1 *ChargerSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } // GetChargerForEvent returns matching ChargerProfile for Event -func (cSv1 *ChargerSv1) GetChargersForEvent(cgrEv *utils.CGREvent, +func (cSv1 *ChargerSv1) GetChargersForEvent(ctx *context.Context, cgrEv *utils.CGREvent, reply *engine.ChargerProfiles) error { - return cSv1.cS.V1GetChargersForEvent(cgrEv, reply) + return cSv1.cS.V1GetChargersForEvent(ctx, cgrEv, reply) } // ProcessEvent -func (cSv1 *ChargerSv1) ProcessEvent(args *utils.CGREvent, +func (cSv1 *ChargerSv1) ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*engine.ChrgSProcessEventReply) error { - return cSv1.cS.V1ProcessEvent(args, reply) + return cSv1.cS.V1ProcessEvent(ctx, args, reply) } diff --git a/apier/v1/chargers_it_test.go b/apier/v1/chargers_it_test.go index 094ad253c..bd75cb7b8 100644 --- a/apier/v1/chargers_it_test.go +++ b/apier/v1/chargers_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( chargerCfgPath string chargerCfg *config.CGRConfig - chargerRPC *rpc.Client + chargerRPC *birpc.Client chargerProfile *ChargerWithAPIOpts chargerConfigDIR string //run tests for specific configuration @@ -179,7 +180,7 @@ func testChargerSLoadAddCharger(t *testing.T) { } var result string - if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -198,7 +199,7 @@ func testChargerSLoadAddCharger(t *testing.T) { }, } - if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -218,7 +219,7 @@ func testChargerSLoadAddCharger(t *testing.T) { }, } - if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -243,7 +244,7 @@ func testChargerSLoadAddCharger(t *testing.T) { Weight: 10, }, } - if err := chargerRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -265,12 +266,12 @@ func testChargerSGetChargersForEvent(t *testing.T) { }, } var result *engine.ChargerProfiles - if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent, + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1GetChargersForEvent, chargerEvent[1], &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent, + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1GetChargersForEvent, chargerEvent[0], &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(result, chargerProfiles) { @@ -291,7 +292,7 @@ func testChargerSGetChargersForEvent(t *testing.T) { }, } chargerEvent[0].Tenant = utils.EmptyString - if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent, + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1GetChargersForEvent, chargerEvent[0], &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(result, chargerProfiles) { @@ -301,7 +302,7 @@ func testChargerSGetChargersForEvent(t *testing.T) { func testChargerSGetChargersForEvent2(t *testing.T) { var result *engine.ChargerProfiles - if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent, + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1GetChargersForEvent, &utils.CGREvent{ // matching Charger1 Tenant: utils.EmptyString, ID: "event1", @@ -339,11 +340,11 @@ func testChargerSProcessEvent(t *testing.T) { }, } var result []*engine.ChrgSProcessEventReply - if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, chargerEvent[1], &result); err == nil || + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, chargerEvent[1], &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, chargerEvent[0], &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, chargerEvent[0], &result); err != nil { t.Error(err) } else if utils.ToJSON(result) != utils.ToJSON(processedEv) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(processedEv), utils.ToJSON(result)) @@ -371,7 +372,7 @@ func testChargerSProcessEvent(t *testing.T) { }, }, } - if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, chargerEvent[2], &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, chargerEvent[2], &result); err != nil { t.Fatal(err) } sort.Strings(result[0].AlteredFields) @@ -380,7 +381,7 @@ func testChargerSProcessEvent(t *testing.T) { } chargerEvent[2].Tenant = utils.EmptyString - if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, chargerEvent[2], &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, chargerEvent[2], &result); err != nil { t.Fatal(err) } sort.Strings(result[0].AlteredFields) @@ -406,23 +407,23 @@ func testChargerSSetChargerProfile(t *testing.T) { } var result string expErr := "SERVER_ERROR: broken reference to filter: <*wrong:inline> for item with ID: cgrates.org:ApierTest" - if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err == nil || err.Error() != expErr { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err == nil || err.Error() != expErr { t.Fatalf("Expected error: %q, received: %v", expErr, err) } var reply *engine.ChargerProfile - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) } chargerProfile.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*opts.Account:1002"} - if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) { @@ -433,17 +434,17 @@ func testChargerSSetChargerProfile(t *testing.T) { func testChargerSGetChargerProfileIDs(t *testing.T) { expected := []string{"Charger1", "Charger2", "ApierTest", "ChargerNotMatching"} var result []string - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfileIDs, utils.PaginatorWithTenant{}, &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfileIDs, utils.PaginatorWithTenant{}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfileIDs, utils.PaginatorWithTenant{ + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfileIDs, utils.PaginatorWithTenant{ Tenant: "cgrates.org", Paginator: utils.Paginator{Limit: utils.IntPointer(1)}, }, &result); err != nil { @@ -456,13 +457,13 @@ func testChargerSGetChargerProfileIDs(t *testing.T) { func testChargerSUpdateChargerProfile(t *testing.T) { chargerProfile.RunID = "*rated" var result string - if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.ChargerProfile - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) { @@ -472,19 +473,19 @@ func testChargerSUpdateChargerProfile(t *testing.T) { func testChargerSRemChargerProfile(t *testing.T) { var resp string - if err := chargerRPC.Call(utils.APIerSv1RemoveChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1RemoveChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } var reply *engine.AttributeProfile - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := chargerRPC.Call(utils.APIerSv1RemoveChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1RemoveChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &resp); err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err) } @@ -492,7 +493,7 @@ func testChargerSRemChargerProfile(t *testing.T) { func testChargerSPing(t *testing.T) { var resp string - if err := chargerRPC.Call(utils.ChargerSv1Ping, new(utils.CGREvent), &resp); err != nil { + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1Ping, new(utils.CGREvent), &resp); err != nil { t.Error(err) } else if resp != utils.Pong { t.Error("Unexpected reply returned", resp) @@ -514,7 +515,7 @@ func testChargerSProcessWithNotFoundAttribute(t *testing.T) { }, } - if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -552,7 +553,7 @@ func testChargerSProcessWithNotFoundAttribute(t *testing.T) { processedEv[0].AttributeSProfiles = nil } var rply []*engine.ChrgSProcessEventReply - if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, ev, &rply); err != nil { + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, ev, &rply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rply, processedEv) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(processedEv), utils.ToJSON(rply)) @@ -581,13 +582,13 @@ func testChargerSProccessEventWithProcceSRunS(t *testing.T) { }, } var result string - if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.ChargerProfile - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) { @@ -623,7 +624,7 @@ func testChargerSProccessEventWithProcceSRunS(t *testing.T) { APIOpts: map[string]any{utils.OptsAttributesProcessRuns: 1}, } var result2 []*engine.ChrgSProcessEventReply - if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, cgrEv, &result2); err != nil { + if err := chargerRPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, cgrEv, &result2); err != nil { t.Error(err) } else if utils.ToJSON(result2) != utils.ToJSON(processedEv) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(processedEv), utils.ToJSON(result2)) @@ -645,14 +646,14 @@ func testChargerSSetChargerProfileWithoutTenant(t *testing.T) { }, } var reply string - if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } chargerProfile.ChargerProfile.Tenant = "cgrates.org" var result *engine.ChargerProfile - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{ID: "randomID"}, &result); err != nil { t.Error(err) @@ -663,7 +664,7 @@ func testChargerSSetChargerProfileWithoutTenant(t *testing.T) { func testChargerSRemChargerProfileWithoutTenant(t *testing.T) { var reply string - if err := chargerRPC.Call(utils.APIerSv1RemoveChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1RemoveChargerProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "randomID"}}, &reply); err != nil { t.Error(err) @@ -671,7 +672,7 @@ func testChargerSRemChargerProfileWithoutTenant(t *testing.T) { t.Error("Unexpected reply returned", reply) } var result *engine.ChargerProfile - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{ID: "randomID"}, &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -680,7 +681,7 @@ func testChargerSRemChargerProfileWithoutTenant(t *testing.T) { func testChargerSCacheTestGetNotFound(t *testing.T) { var reply *engine.ChargerProfile - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "CHARGERS_CACHE"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -689,7 +690,7 @@ func testChargerSCacheTestGetNotFound(t *testing.T) { func testChargerSCacheTestGetFound(t *testing.T) { var reply *engine.ChargerProfile - if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile, + if err := chargerRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "CHARGERS_CACHE"}, &reply); err != nil { t.Fatal(err) } @@ -706,7 +707,7 @@ func testChargerSCacheTestSet(t *testing.T) { }, } var reply string - if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { + if err := chargerRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -718,7 +719,7 @@ func testChargerSCacheReload(t *testing.T) { ChargerProfileIDs: []string{"cgrates.org:CHARGERS_CACHE"}, } var reply string - if err := chargerRPC.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil { + if err := chargerRPC.Call(context.Background(), utils.CacheSv1ReloadCache, cache, &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Error("Calling CacheSv1.ReloadCache got reply: ", reply) diff --git a/apier/v1/config.go b/apier/v1/config.go index 4a7d16b16..3544548c7 100644 --- a/apier/v1/config.go +++ b/apier/v1/config.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -34,32 +35,32 @@ type ConfigSv1 struct { } // GetConfig will retrieve from CGRConfig a section -func (cSv1 *ConfigSv1) GetConfig(section *config.SectionWithAPIOpts, reply *map[string]any) (err error) { - return cSv1.cfg.V1GetConfig(section, reply) +func (cSv1 *ConfigSv1) GetConfig(ctx *context.Context, section *config.SectionWithAPIOpts, reply *map[string]any) (err error) { + return cSv1.cfg.V1GetConfig(ctx, section, reply) } // ReloadConfig reloads the configuration -func (cSv1 *ConfigSv1) ReloadConfig(args *config.ReloadArgs, reply *string) (err error) { - return cSv1.cfg.V1ReloadConfig(args, reply) +func (cSv1 *ConfigSv1) ReloadConfig(ctx *context.Context, args *config.ReloadArgs, reply *string) (err error) { + return cSv1.cfg.V1ReloadConfig(ctx, args, reply) } // SetConfig reloads the sections of config -func (cSv1 *ConfigSv1) SetConfig(args *config.SetConfigArgs, reply *string) (err error) { - return cSv1.cfg.V1SetConfig(args, reply) +func (cSv1 *ConfigSv1) SetConfig(ctx *context.Context, args *config.SetConfigArgs, reply *string) (err error) { + return cSv1.cfg.V1SetConfig(ctx, args, reply) } // SetConfigFromJSON reloads the sections of config -func (cSv1 *ConfigSv1) SetConfigFromJSON(args *config.SetConfigFromJSONArgs, reply *string) (err error) { - return cSv1.cfg.V1SetConfigFromJSON(args, reply) +func (cSv1 *ConfigSv1) SetConfigFromJSON(ctx *context.Context, args *config.SetConfigFromJSONArgs, reply *string) (err error) { + return cSv1.cfg.V1SetConfigFromJSON(ctx, args, reply) } // GetConfigAsJSON will retrieve from CGRConfig a section -func (cSv1 *ConfigSv1) GetConfigAsJSON(args *config.SectionWithAPIOpts, reply *string) (err error) { - return cSv1.cfg.V1GetConfigAsJSON(args, reply) +func (cSv1 *ConfigSv1) GetConfigAsJSON(ctx *context.Context, args *config.SectionWithAPIOpts, reply *string) (err error) { + return cSv1.cfg.V1GetConfigAsJSON(ctx, args, reply) } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (cSv1 *ConfigSv1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (cSv1 *ConfigSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(cSv1, serviceMethod, args, reply) } diff --git a/apier/v1/config_it_test.go b/apier/v1/config_it_test.go index be157d3ee..58b3349c8 100644 --- a/apier/v1/config_it_test.go +++ b/apier/v1/config_it_test.go @@ -23,14 +23,15 @@ package v1 import ( "fmt" - "net/rpc" - "net/rpc/jsonrpc" "os/exec" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -39,7 +40,7 @@ import ( var ( configCfgPath string configCfg *config.CGRConfig - configRPC *rpc.Client + configRPC *birpc.Client configConfigDIR string //run tests for specific configuration sTestsConfig = []func(t *testing.T){ @@ -122,7 +123,7 @@ func testConfigSRPCConn(t *testing.T) { func testConfigSSetConfigSessionS(t *testing.T) { var reply string - if err := configRPC.Call(utils.ConfigSv1SetConfig, &config.SetConfigArgs{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1SetConfig, &config.SetConfigArgs{ Tenant: "cgrates.org", Config: map[string]any{ "sessions": map[string]any{ @@ -221,7 +222,7 @@ func testConfigSSetConfigSessionS(t *testing.T) { config.SessionSJson: exp, } var rpl map[string]any - if err := configRPC.Call(utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.SessionSJson, }, &rpl); err != nil { @@ -312,7 +313,7 @@ func testConfigSv1GetJSONSectionWithoutTenant(t *testing.T) { config.SessionSJson: exp, } var rpl map[string]any - if err := configRPC.Call(utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ Section: config.SessionSJson, }, &rpl); err != nil { t.Error(err) @@ -326,7 +327,7 @@ func testConfigSSetConfigEEsDryRun(t *testing.T) { t.SkipNow() } var reply string - if err := configRPC.Call(utils.ConfigSv1SetConfig, &config.SetConfigArgs{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1SetConfig, &config.SetConfigArgs{ Config: map[string]any{ "ees": map[string]any{ "enabled": true, @@ -340,7 +341,7 @@ func testConfigSSetConfigEEsDryRun(t *testing.T) { } var rpl map[string]any - if err := configRPC.Call(utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ Section: config.EEsJson, }, &rpl); err != nil { t.Error(err) @@ -354,7 +355,7 @@ func testConfigSSetConfigEEs(t *testing.T) { t.SkipNow() } var reply string - if err := configRPC.Call(utils.ConfigSv1SetConfig, &config.SetConfigArgs{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1SetConfig, &config.SetConfigArgs{ Config: map[string]any{ "ees": map[string]any{ "enabled": true, @@ -397,7 +398,7 @@ func testConfigSSetConfigEEs(t *testing.T) { config.EEsJson: exp, } var rpl map[string]any - if err := configRPC.Call(utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ Section: config.EEsJson, }, &rpl); err != nil { t.Error(err) @@ -427,7 +428,7 @@ func testConfigStartEngineWithConfigs(t *testing.T) { t.Fatal(err) } var rply map[string]any - if err := configRPC.Call(utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil { + if err := configRPC.Call(context.Background(), utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil { t.Error(err) } else if rply[utils.NodeID] != "EngineWithConfigSActive" { t.Errorf("Expected %+v , received: %+v ", "EngineWithConfigSActive", rply) @@ -444,7 +445,7 @@ func testConfigStartEngineFromHTTP(t *testing.T) { t.Error(err) } fib := utils.FibDuration(time.Millisecond, 0) - var jsonClnt *rpc.Client + var jsonClnt *birpc.Client var connected bool for i := 0; i < 200; i++ { time.Sleep(fib()) @@ -461,7 +462,7 @@ func testConfigStartEngineFromHTTP(t *testing.T) { } time.Sleep(100 * time.Millisecond) var rply map[string]any - if err := jsonClnt.Call(utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil { + if err := jsonClnt.Call(context.Background(), utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil { t.Error(err) } } @@ -469,7 +470,7 @@ func testConfigStartEngineFromHTTP(t *testing.T) { func testConfigSSetConfigFromJSONCoreSDryRun(t *testing.T) { cfgStr := `{"cores":{"caps":0,"caps_stats_interval":"0","caps_strategy":"*queue","shutdown_timeout":"1s"}}` var reply string - if err := configRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: cfgStr, DryRun: true, @@ -481,7 +482,7 @@ func testConfigSSetConfigFromJSONCoreSDryRun(t *testing.T) { expCfg := "{\"cores\":{\"caps\":0,\"caps_stats_interval\":\"0\",\"caps_strategy\":\"*busy\",\"shutdown_timeout\":\"1s\"}}" var rpl string - if err := configRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.CoreSCfgJson, }, &rpl); err != nil { @@ -494,7 +495,7 @@ func testConfigSSetConfigFromJSONCoreSDryRun(t *testing.T) { func testConfigSSetConfigFromJSONCoreS(t *testing.T) { cfgStr := `{"cores":{"caps":0,"caps_stats_interval":"0","caps_strategy":"*queue","shutdown_timeout":"1s"}}` var reply string - if err := configRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: cfgStr, }, &reply); err != nil { @@ -504,7 +505,7 @@ func testConfigSSetConfigFromJSONCoreS(t *testing.T) { } var rpl string - if err := configRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.CoreSCfgJson, }, &rpl); err != nil { @@ -517,7 +518,7 @@ func testConfigSSetConfigFromJSONCoreS(t *testing.T) { func testConfigSReloadConfigCoreSDryRun(t *testing.T) { cfgStr := `{"cores":{"caps":0,"caps_stats_interval":"0","caps_strategy":"*queue","shutdown_timeout":"1s"}}` var reply string - if err := configRPC.Call(utils.ConfigSv1ReloadConfig, &config.ReloadArgs{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1ReloadConfig, &config.ReloadArgs{ Tenant: "cgrates.org", Path: path.Join(*dataDir, "conf", "samples", "caps_busy"), Section: config.CoreSCfgJson, @@ -529,7 +530,7 @@ func testConfigSReloadConfigCoreSDryRun(t *testing.T) { } var rpl string - if err := configRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.CoreSCfgJson, }, &rpl); err != nil { @@ -542,7 +543,7 @@ func testConfigSReloadConfigCoreSDryRun(t *testing.T) { func testConfigSReloadConfigCoreS(t *testing.T) { cfgStr := `{"cores":{"caps":2,"caps_stats_interval":"0","caps_strategy":"*busy","shutdown_timeout":"1s"}}` var reply string - if err := configRPC.Call(utils.ConfigSv1ReloadConfig, &config.ReloadArgs{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1ReloadConfig, &config.ReloadArgs{ Tenant: "cgrates.org", Path: path.Join(*dataDir, "conf", "samples", "caps_busy"), Section: config.CoreSCfgJson, @@ -553,7 +554,7 @@ func testConfigSReloadConfigCoreS(t *testing.T) { } var rpl string - if err := configRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := configRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.CoreSCfgJson, }, &rpl); err != nil { diff --git a/apier/v1/core.go b/apier/v1/core.go index 2c70f1c1f..70d5ded8a 100644 --- a/apier/v1/core.go +++ b/apier/v1/core.go @@ -19,9 +19,7 @@ along with this program. If not, see package v1 import ( - "path" - "time" - + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/utils" ) @@ -35,67 +33,50 @@ type CoreSv1 struct { cS *cores.CoreService } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (cS *CoreSv1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (cS *CoreSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(cS, serviceMethod, args, reply) } -func (cS *CoreSv1) Status(arg *utils.TenantWithAPIOpts, reply *map[string]any) error { - return cS.cS.Status(arg, reply) +func (cS *CoreSv1) Status(ctx *context.Context, arg *utils.TenantWithAPIOpts, reply *map[string]any) error { + return cS.cS.V1Status(ctx, arg, reply) } // Ping used to determinate if component is active -func (cS *CoreSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (cS *CoreSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } // Sleep is used to test the concurrent requests mechanism -func (cS *CoreSv1) Sleep(arg *utils.DurationArgs, reply *string) error { - time.Sleep(arg.Duration) - *reply = utils.OK - return nil +func (cS *CoreSv1) Sleep(ctx *context.Context, args *utils.DurationArgs, reply *string) error { + return cS.cS.V1Sleep(ctx, args, reply) } // StartCPUProfiling is used to start CPUProfiling in the given path -func (cS *CoreSv1) StartCPUProfiling(args *utils.DirectoryArgs, reply *string) error { - if err := cS.cS.StartCPUProfiling(path.Join(args.DirPath, utils.CpuPathCgr)); err != nil { - return err - } - *reply = utils.OK - return nil +func (cS *CoreSv1) StartCPUProfiling(ctx *context.Context, args *utils.DirectoryArgs, reply *string) error { + return cS.cS.V1StartCPUProfiling(ctx, args, reply) } // StopCPUProfiling is used to stop CPUProfiling. The file should be written on the path // where the CPUProfiling already started -func (cS *CoreSv1) StopCPUProfiling(_ *utils.TenantWithAPIOpts, reply *string) error { - if err := cS.cS.StopCPUProfiling(); err != nil { - return err - } - *reply = utils.OK - return nil +func (cS *CoreSv1) StopCPUProfiling(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *string) error { + return cS.cS.V1StopCPUProfiling(ctx, args, reply) } // StartMemoryProfiling is used to start MemoryProfiling in the given path -func (cS *CoreSv1) StartMemoryProfiling(args *utils.MemoryPrf, reply *string) error { - if err := cS.cS.StartMemoryProfiling(args); err != nil { - return err - } - *reply = utils.OK - return nil +func (cS *CoreSv1) StartMemoryProfiling(ctx *context.Context, args *utils.MemoryPrf, reply *string) error { + return cS.cS.V1StartMemoryProfiling(ctx, args, reply) } // StopMemoryProfiling is used to stop MemoryProfiling. The file should be written on the path // where the MemoryProfiling already started -func (cS *CoreSv1) StopMemoryProfiling(_ *utils.TenantWithAPIOpts, reply *string) error { - if err := cS.cS.StopMemoryProfiling(); err != nil { - return err - } - *reply = utils.OK - return nil +func (cS *CoreSv1) StopMemoryProfiling(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *string) error { + return cS.cS.V1StopMemoryProfiling(ctx, args, reply) + } -func (cS *CoreSv1) Panic(args *utils.PanicMessageArgs, reply *string) error { - return cS.cS.Panic(args, reply) +func (cS *CoreSv1) Panic(ctx *context.Context, args *utils.PanicMessageArgs, reply *string) error { + return cS.cS.V1Panic(ctx, args, reply) } diff --git a/apier/v1/core_it_test.go b/apier/v1/core_it_test.go index 17da3233e..206c8f0eb 100644 --- a/apier/v1/core_it_test.go +++ b/apier/v1/core_it_test.go @@ -23,14 +23,15 @@ package v1 import ( "fmt" - "net/rpc" - "net/rpc/jsonrpc" "os" "os/exec" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -41,7 +42,7 @@ import ( var ( coreV1CfgPath string coreV1Cfg *config.CGRConfig - coreV1Rpc *rpc.Client + coreV1Rpc *birpc.Client coreV1ConfDIR string //run tests for specific configuration argPath string sTestCoreSv1 = []func(t *testing.T){ @@ -157,7 +158,7 @@ func testCoreSv1StartCPUProfilingErrorAlreadyStarted(t *testing.T) { DirPath: argPath, } expectedErr := "CPU profiling already started" - if err := coreV1Rpc.Call(utils.CoreSv1StartCPUProfiling, + if err := coreV1Rpc.Call(context.Background(), utils.CoreSv1StartCPUProfiling, dirPath, &reply); err == nil || err.Error() != expectedErr { t.Errorf("Expected %+v, received %+v", expectedErr, err) } @@ -172,7 +173,7 @@ func testCoreSv1StartEngine(t *testing.T) { func testCoreSv1StopMemProfilingBeforeStart(t *testing.T) { var reply string expectedErr := " Memory Profiling is not started" - if err := coreV1Rpc.Call(utils.CoreSv1StopMemoryProfiling, + if err := coreV1Rpc.Call(context.Background(), utils.CoreSv1StopMemoryProfiling, new(utils.TenantWithAPIOpts), &reply); err == nil || err.Error() != expectedErr { t.Errorf("Expected %+q, received %+q", expectedErr, err) } @@ -202,7 +203,7 @@ func testCoreSv1StartEngineByExecWIthMemProfiling(t *testing.T) { func testCoreSv1StopMemoryProfiling(t *testing.T) { var reply string - if err := coreV1Rpc.Call(utils.CoreSv1StopMemoryProfiling, + if err := coreV1Rpc.Call(context.Background(), utils.CoreSv1StopMemoryProfiling, new(utils.TenantWithAPIOpts), &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -260,7 +261,7 @@ func testCoreSv1StartMemProfilingErrorAlreadyStarted(t *testing.T) { NrFiles: 2, } expErr := "Memory Profiling already started" - if err := coreV1Rpc.Call(utils.CoreSv1StartMemoryProfiling, + if err := coreV1Rpc.Call(context.Background(), utils.CoreSv1StartMemoryProfiling, args, &reply); err == nil || err.Error() != expErr { t.Errorf("Expected %+v, received %+v", expErr, err) } @@ -269,7 +270,7 @@ func testCoreSv1StartMemProfilingErrorAlreadyStarted(t *testing.T) { func testCoreSv1StopCPUProfilingBeforeStart(t *testing.T) { var reply string expectedErr := " cannot stop because CPUProfiling is not active" - if err := coreV1Rpc.Call(utils.CoreSv1StopCPUProfiling, + if err := coreV1Rpc.Call(context.Background(), utils.CoreSv1StopCPUProfiling, new(utils.TenantWithAPIOpts), &reply); err == nil || err.Error() != expectedErr { t.Errorf("Expected %+q, received %+q", expectedErr, err) } @@ -280,7 +281,7 @@ func testCoreSv1StartCPUProfiling(t *testing.T) { dirPath := &utils.DirectoryArgs{ DirPath: argPath, } - if err := coreV1Rpc.Call(utils.CoreSv1StartCPUProfiling, + if err := coreV1Rpc.Call(context.Background(), utils.CoreSv1StartCPUProfiling, dirPath, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -293,7 +294,7 @@ func testCoreSv1Sleep(t *testing.T) { Duration: 600 * time.Millisecond, } var reply string - if err := coreV1Rpc.Call(utils.CoreSv1Sleep, + if err := coreV1Rpc.Call(context.Background(), utils.CoreSv1Sleep, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -303,7 +304,7 @@ func testCoreSv1Sleep(t *testing.T) { func testCoreSv1StopCPUProfiling(t *testing.T) { var reply string - if err := coreV1Rpc.Call(utils.CoreSv1StopCPUProfiling, + if err := coreV1Rpc.Call(context.Background(), utils.CoreSv1StopCPUProfiling, new(utils.TenantWithAPIOpts), &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -335,7 +336,7 @@ func testCoreSv1StartMemoryProfiling(t *testing.T) { Interval: 100 * time.Millisecond, NrFiles: 2, } - if err := coreV1Rpc.Call(utils.CoreSv1StartMemoryProfiling, + if err := coreV1Rpc.Call(context.Background(), utils.CoreSv1StartMemoryProfiling, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { diff --git a/apier/v1/costs.go b/apier/v1/costs.go index 32eaf8051..f88c98da7 100644 --- a/apier/v1/costs.go +++ b/apier/v1/costs.go @@ -21,6 +21,7 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -35,7 +36,7 @@ type AttrGetCost struct { APIOpts map[string]any } -func (apierSv1 *APIerSv1) GetCost(attrs *AttrGetCost, ec *engine.EventCost) error { +func (apierSv1 *APIerSv1) GetCost(ctx *context.Context, attrs *AttrGetCost, ec *engine.EventCost) error { if apierSv1.Responder == nil { return utils.NewErrNotConnected(utils.RALService) } @@ -59,7 +60,7 @@ func (apierSv1 *APIerSv1) GetCost(attrs *AttrGetCost, ec *engine.EventCost) erro DurationIndex: usage, } var cc engine.CallCost - if err := apierSv1.Responder.GetCost( + if err := apierSv1.Responder.GetCost(context.Background(), &engine.CallDescriptorWithAPIOpts{ CallDescriptor: cd, APIOpts: attrs.APIOpts, @@ -80,7 +81,7 @@ type AttrGetDataCost struct { Opts map[string]any } -func (apierSv1 *APIerSv1) GetDataCost(attrs *AttrGetDataCost, reply *engine.DataCost) error { +func (apierSv1 *APIerSv1) GetDataCost(ctx *context.Context, attrs *AttrGetDataCost, reply *engine.DataCost) error { if apierSv1.Responder == nil { return utils.NewErrNotConnected(utils.RALService) } @@ -99,10 +100,12 @@ func (apierSv1 *APIerSv1) GetDataCost(attrs *AttrGetDataCost, reply *engine.Data ToR: utils.MetaData, } var cc engine.CallCost - if err := apierSv1.Responder.GetCost(&engine.CallDescriptorWithAPIOpts{ - CallDescriptor: cd, - APIOpts: attrs.Opts, - }, &cc); err != nil { + if err := apierSv1.Responder.GetCost( + context.Background(), + &engine.CallDescriptorWithAPIOpts{ + CallDescriptor: cd, + APIOpts: attrs.Opts, + }, &cc); err != nil { return utils.NewErrServerError(err) } if dc, err := cc.ToDataCost(); err != nil { diff --git a/apier/v1/costs_it_test.go b/apier/v1/costs_it_test.go index 5f0158897..8e6f26cb1 100644 --- a/apier/v1/costs_it_test.go +++ b/apier/v1/costs_it_test.go @@ -22,11 +22,12 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -35,7 +36,7 @@ import ( var ( costCfgPath string costCfg *config.CGRConfig - costRPC *rpc.Client + costRPC *birpc.Client costConfigDIR string //run tests for specific configuration sTestsCost = []func(t *testing.T){ @@ -110,7 +111,7 @@ func testCostRPCConn(t *testing.T) { func testCostLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := costRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := costRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -120,7 +121,7 @@ func testCostGetCost(t *testing.T) { attrs := AttrGetCost{Category: "call", Tenant: "cgrates.org", Subject: "1001", AnswerTime: "*now", Destination: "1002", Usage: "120000000000"} //120s ( 2m) var rply *engine.EventCost - if err := costRPC.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := costRPC.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 0.700200 { // expect to get 0.7 (0.4 connect fee 0.2 first minute 0.1 each minute after) t.Errorf("Unexpected cost received: %f", *rply.Cost) diff --git a/apier/v1/debit.go b/apier/v1/debit.go index 651294bc4..d2d4f9a27 100644 --- a/apier/v1/debit.go +++ b/apier/v1/debit.go @@ -19,17 +19,19 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // DebitUsage will debit the balance for the usage cost, allowing the // account to go negative if the cost calculated is greater than the balance -func (apierSv1 *APIerSv1) DebitUsage(usageRecord *engine.UsageRecordWithAPIOpts, reply *string) error { - return apierSv1.DebitUsageWithOptions(&AttrDebitUsageWithOptions{ - UsageRecord: usageRecord, - AllowNegativeAccount: true, - }, reply) +func (apierSv1 *APIerSv1) DebitUsage(ctx *context.Context, usageRecord *engine.UsageRecordWithAPIOpts, reply *string) error { + return apierSv1.DebitUsageWithOptions(ctx, + &AttrDebitUsageWithOptions{ + UsageRecord: usageRecord, + AllowNegativeAccount: true, + }, reply) } // AttrDebitUsageWithOptions represents the DebitUsage request @@ -40,7 +42,7 @@ type AttrDebitUsageWithOptions struct { // DebitUsageWithOptions will debit the account based on the usage cost with // additional options to control if the balance can go negative -func (apierSv1 *APIerSv1) DebitUsageWithOptions(args *AttrDebitUsageWithOptions, reply *string) error { +func (apierSv1 *APIerSv1) DebitUsageWithOptions(ctx *context.Context, args *AttrDebitUsageWithOptions, reply *string) error { if apierSv1.Responder == nil { return utils.NewErrNotConnected(utils.RALService) } @@ -78,10 +80,12 @@ func (apierSv1 *APIerSv1) DebitUsageWithOptions(args *AttrDebitUsageWithOptions, // Calculate the cost for usage and debit the account var cc engine.CallCost - if err := apierSv1.Responder.Debit(&engine.CallDescriptorWithAPIOpts{ - CallDescriptor: cd, - APIOpts: args.UsageRecord.APIOpts, - }, &cc); err != nil { + if err := apierSv1.Responder.Debit( + context.Background(), + &engine.CallDescriptorWithAPIOpts{ + CallDescriptor: cd, + APIOpts: args.UsageRecord.APIOpts, + }, &cc); err != nil { return utils.NewErrServerError(err) } diff --git a/apier/v1/debit_test.go b/apier/v1/debit_test.go index b9ac25ce9..d8e7870aa 100644 --- a/apier/v1/debit_test.go +++ b/apier/v1/debit_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -146,9 +147,11 @@ func TestDebitUsageWithOptions(t *testing.T) { } var reply string - if err := apierDebit.DebitUsageWithOptions(&AttrDebitUsageWithOptions{ - UsageRecord: &engine.UsageRecordWithAPIOpts{UsageRecord: usageRecord}, - AllowNegativeAccount: false}, &reply); err != nil { + if err := apierDebit.DebitUsageWithOptions( + context.Background(), + &AttrDebitUsageWithOptions{ + UsageRecord: &engine.UsageRecordWithAPIOpts{UsageRecord: usageRecord}, + AllowNegativeAccount: false}, &reply); err != nil { t.Error(err) } diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index 56e7a46c5..24e6d5fe7 100644 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -21,6 +21,7 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/engine" @@ -30,7 +31,7 @@ import ( ) // GetDispatcherProfile returns a Dispatcher Profile -func (apierSv1 *APIerSv1) GetDispatcherProfile(arg *utils.TenantID, reply *engine.DispatcherProfile) error { +func (apierSv1 *APIerSv1) GetDispatcherProfile(ctx *context.Context, arg *utils.TenantID, reply *engine.DispatcherProfile) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -47,7 +48,7 @@ func (apierSv1 *APIerSv1) GetDispatcherProfile(arg *utils.TenantID, reply *engin } // GetDispatcherProfileIDs returns list of dispatcherProfile IDs registered for a tenant -func (apierSv1 *APIerSv1) GetDispatcherProfileIDs(tenantArg *utils.PaginatorWithTenant, dPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetDispatcherProfileIDs(ctx *context.Context, tenantArg *utils.PaginatorWithTenant, dPrfIDs *[]string) error { tenant := tenantArg.Tenant if tenant == utils.EmptyString { tenant = apierSv1.Config.GeneralCfg().DefaultTenant @@ -74,7 +75,7 @@ type DispatcherWithAPIOpts struct { } // SetDispatcherProfile add/update a new Dispatcher Profile -func (apierSv1 *APIerSv1) SetDispatcherProfile(args *DispatcherWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) SetDispatcherProfile(ctx *context.Context, args *DispatcherWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(args.DispatcherProfile, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -110,7 +111,7 @@ func (apierSv1 *APIerSv1) SetDispatcherProfile(args *DispatcherWithAPIOpts, repl } // RemoveDispatcherProfile remove a specific Dispatcher Profile -func (apierSv1 *APIerSv1) RemoveDispatcherProfile(arg *utils.TenantIDWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) RemoveDispatcherProfile(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -136,7 +137,7 @@ func (apierSv1 *APIerSv1) RemoveDispatcherProfile(arg *utils.TenantIDWithAPIOpts } // GetDispatcherHost returns a Dispatcher Host -func (apierSv1 *APIerSv1) GetDispatcherHost(arg *utils.TenantID, reply *engine.DispatcherHost) error { +func (apierSv1 *APIerSv1) GetDispatcherHost(ctx *context.Context, arg *utils.TenantID, reply *engine.DispatcherHost) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -153,7 +154,7 @@ func (apierSv1 *APIerSv1) GetDispatcherHost(arg *utils.TenantID, reply *engine.D } // GetDispatcherHostIDs returns list of dispatcherHost IDs registered for a tenant -func (apierSv1 *APIerSv1) GetDispatcherHostIDs(tenantArg *utils.PaginatorWithTenant, dPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetDispatcherHostIDs(ctx *context.Context, tenantArg *utils.PaginatorWithTenant, dPrfIDs *[]string) error { tenant := tenantArg.Tenant if tenant == utils.EmptyString { tenant = apierSv1.Config.GeneralCfg().DefaultTenant @@ -175,7 +176,7 @@ func (apierSv1 *APIerSv1) GetDispatcherHostIDs(tenantArg *utils.PaginatorWithTen } // SetDispatcherHost add/update a new Dispatcher Host -func (apierSv1 *APIerSv1) SetDispatcherHost(args *engine.DispatcherHostWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) SetDispatcherHost(ctx *context.Context, args *engine.DispatcherHostWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(args.DispatcherHost, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -199,7 +200,7 @@ func (apierSv1 *APIerSv1) SetDispatcherHost(args *engine.DispatcherHostWithAPIOp } // RemoveDispatcherHost remove a specific Dispatcher Host -func (apierSv1 *APIerSv1) RemoveDispatcherHost(arg *utils.TenantIDWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) RemoveDispatcherHost(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -234,30 +235,30 @@ type DispatcherThresholdSv1 struct { } // Ping implements ThresholdSv1Ping -func (dT *DispatcherThresholdSv1) Ping(args *utils.CGREvent, reply *string) error { - return dT.dS.ThresholdSv1Ping(args, reply) +func (dT *DispatcherThresholdSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dT.dS.ThresholdSv1Ping(ctx, args, reply) } // GetThresholdsForEvent implements ThresholdSv1GetThresholdsForEvent -func (dT *DispatcherThresholdSv1) GetThresholdsForEvent(tntID *utils.CGREvent, +func (dT *DispatcherThresholdSv1) GetThresholdsForEvent(ctx *context.Context, tntID *utils.CGREvent, t *engine.Thresholds) error { - return dT.dS.ThresholdSv1GetThresholdsForEvent(tntID, t) + return dT.dS.ThresholdSv1GetThresholdsForEvent(ctx, tntID, t) } // ProcessEvent implements ThresholdSv1ProcessEvent -func (dT *DispatcherThresholdSv1) ProcessEvent(args *utils.CGREvent, +func (dT *DispatcherThresholdSv1) ProcessEvent(ctx *context.Context, args *utils.CGREvent, tIDs *[]string) error { - return dT.dS.ThresholdSv1ProcessEvent(args, tIDs) + return dT.dS.ThresholdSv1ProcessEvent(ctx, args, tIDs) } -func (dT *DispatcherThresholdSv1) GetThresholdIDs(args *utils.TenantWithAPIOpts, +func (dT *DispatcherThresholdSv1) GetThresholdIDs(ctx *context.Context, args *utils.TenantWithAPIOpts, tIDs *[]string) error { - return dT.dS.ThresholdSv1GetThresholdIDs(args, tIDs) + return dT.dS.ThresholdSv1GetThresholdIDs(ctx, args, tIDs) } -func (dT *DispatcherThresholdSv1) GetThreshold(args *utils.TenantIDWithAPIOpts, +func (dT *DispatcherThresholdSv1) GetThreshold(ctx *context.Context, args *utils.TenantIDWithAPIOpts, th *engine.Threshold) error { - return dT.dS.ThresholdSv1GetThreshold(args, th) + return dT.dS.ThresholdSv1GetThreshold(ctx, args, th) } func NewDispatcherStatSv1(dps *dispatchers.DispatcherService) *DispatcherStatSv1 { @@ -270,34 +271,34 @@ type DispatcherStatSv1 struct { } // Ping implements StatSv1Ping -func (dSts *DispatcherStatSv1) Ping(args *utils.CGREvent, reply *string) error { - return dSts.dS.StatSv1Ping(args, reply) +func (dSts *DispatcherStatSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dSts.dS.StatSv1Ping(ctx, args, reply) } // GetStatQueuesForEvent implements StatSv1GetStatQueuesForEvent -func (dSts *DispatcherStatSv1) GetStatQueuesForEvent(args *utils.CGREvent, reply *[]string) error { - return dSts.dS.StatSv1GetStatQueuesForEvent(args, reply) +func (dSts *DispatcherStatSv1) GetStatQueuesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) error { + return dSts.dS.StatSv1GetStatQueuesForEvent(ctx, args, reply) } // GetQueueStringMetrics implements StatSv1GetQueueStringMetrics -func (dSts *DispatcherStatSv1) GetQueueStringMetrics(args *utils.TenantIDWithAPIOpts, +func (dSts *DispatcherStatSv1) GetQueueStringMetrics(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *map[string]string) error { - return dSts.dS.StatSv1GetQueueStringMetrics(args, reply) + return dSts.dS.StatSv1GetQueueStringMetrics(ctx, args, reply) } -func (dSts *DispatcherStatSv1) GetQueueFloatMetrics(args *utils.TenantIDWithAPIOpts, +func (dSts *DispatcherStatSv1) GetQueueFloatMetrics(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *map[string]float64) error { - return dSts.dS.StatSv1GetQueueFloatMetrics(args, reply) + return dSts.dS.StatSv1GetQueueFloatMetrics(ctx, args, reply) } -func (dSts *DispatcherStatSv1) GetQueueIDs(args *utils.TenantWithAPIOpts, +func (dSts *DispatcherStatSv1) GetQueueIDs(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *[]string) error { - return dSts.dS.StatSv1GetQueueIDs(args, reply) + return dSts.dS.StatSv1GetQueueIDs(ctx, args, reply) } // GetQueueStringMetrics implements StatSv1ProcessEvent -func (dSts *DispatcherStatSv1) ProcessEvent(args *utils.CGREvent, reply *[]string) error { - return dSts.dS.StatSv1ProcessEvent(args, reply) +func (dSts *DispatcherStatSv1) ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) error { + return dSts.dS.StatSv1ProcessEvent(ctx, args, reply) } func NewDispatcherResourceSv1(dps *dispatchers.DispatcherService) *DispatcherResourceSv1 { @@ -310,37 +311,37 @@ type DispatcherResourceSv1 struct { } // Ping implements ResourceSv1Ping -func (dRs *DispatcherResourceSv1) Ping(args *utils.CGREvent, reply *string) error { - return dRs.dRs.ResourceSv1Ping(args, reply) +func (dRs *DispatcherResourceSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dRs.dRs.ResourceSv1Ping(ctx, args, reply) } // GetResourcesForEvent implements ResourceSv1GetResourcesForEvent -func (dRs *DispatcherResourceSv1) GetResourcesForEvent(args *utils.CGREvent, +func (dRs *DispatcherResourceSv1) GetResourcesForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.Resources) error { - return dRs.dRs.ResourceSv1GetResourcesForEvent(args, reply) + return dRs.dRs.ResourceSv1GetResourcesForEvent(ctx, args, reply) } -func (dRs *DispatcherResourceSv1) GetResource(args *utils.TenantIDWithAPIOpts, reply *engine.Resource) error { - return dRs.dRs.ResourceSv1GetResource(args, reply) +func (dRs *DispatcherResourceSv1) GetResource(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.Resource) error { + return dRs.dRs.ResourceSv1GetResource(ctx, args, reply) } -func (dRs *DispatcherResourceSv1) GetResourceWithConfig(args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) error { - return dRs.dRs.ResourceSv1GetResourceWithConfig(args, reply) +func (dRs *DispatcherResourceSv1) GetResourceWithConfig(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) error { + return dRs.dRs.ResourceSv1GetResourceWithConfig(ctx, args, reply) } -func (dRs *DispatcherResourceSv1) AuthorizeResources(args *utils.CGREvent, +func (dRs *DispatcherResourceSv1) AuthorizeResources(ctx *context.Context, args *utils.CGREvent, reply *string) error { - return dRs.dRs.ResourceSv1AuthorizeResources(args, reply) + return dRs.dRs.ResourceSv1AuthorizeResources(ctx, args, reply) } -func (dRs *DispatcherResourceSv1) AllocateResources(args *utils.CGREvent, +func (dRs *DispatcherResourceSv1) AllocateResources(ctx *context.Context, args *utils.CGREvent, reply *string) error { - return dRs.dRs.ResourceSv1AllocateResources(args, reply) + return dRs.dRs.ResourceSv1AllocateResources(ctx, args, reply) } -func (dRs *DispatcherResourceSv1) ReleaseResources(args *utils.CGREvent, +func (dRs *DispatcherResourceSv1) ReleaseResources(ctx *context.Context, args *utils.CGREvent, reply *string) error { - return dRs.dRs.ResourceSv1ReleaseResources(args, reply) + return dRs.dRs.ResourceSv1ReleaseResources(ctx, args, reply) } func NewDispatcherRouteSv1(dps *dispatchers.DispatcherService) *DispatcherRouteSv1 { @@ -353,23 +354,23 @@ type DispatcherRouteSv1 struct { } // Ping implements RouteSv1Ping -func (dRoute *DispatcherRouteSv1) Ping(args *utils.CGREvent, reply *string) error { - return dRoute.dRoute.RouteSv1Ping(args, reply) +func (dRoute *DispatcherRouteSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dRoute.dRoute.RouteSv1Ping(ctx, args, reply) } // GetRoutes implements RouteSv1GetRoutes -func (dRoute *DispatcherRouteSv1) GetRoutes(args *utils.CGREvent, reply *engine.SortedRoutesList) error { - return dRoute.dRoute.RouteSv1GetRoutes(args, reply) +func (dRoute *DispatcherRouteSv1) GetRoutes(ctx *context.Context, args *utils.CGREvent, reply *engine.SortedRoutesList) error { + return dRoute.dRoute.RouteSv1GetRoutes(ctx, args, reply) } // GetRouteProfilesForEvent returns a list of route profiles that match for Event -func (dRoute *DispatcherRouteSv1) GetRouteProfilesForEvent(args *utils.CGREvent, reply *[]*engine.RouteProfile) error { - return dRoute.dRoute.RouteSv1GetRouteProfilesForEvent(args, reply) +func (dRoute *DispatcherRouteSv1) GetRouteProfilesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*engine.RouteProfile) error { + return dRoute.dRoute.RouteSv1GetRouteProfilesForEvent(ctx, args, reply) } // GetRoutesList returns sorted list of routes for Event as a string slice -func (dRoute *DispatcherRouteSv1) GetRoutesList(args *utils.CGREvent, reply *[]string) error { - return dRoute.dRoute.RouteSv1GetRoutesList(args, reply) +func (dRoute *DispatcherRouteSv1) GetRoutesList(ctx *context.Context, args *utils.CGREvent, reply *[]string) error { + return dRoute.dRoute.RouteSv1GetRoutesList(ctx, args, reply) } func NewDispatcherAttributeSv1(dps *dispatchers.DispatcherService) *DispatcherAttributeSv1 { @@ -382,20 +383,20 @@ type DispatcherAttributeSv1 struct { } // Ping implements AttributeSv1Ping -func (dA *DispatcherAttributeSv1) Ping(args *utils.CGREvent, reply *string) error { - return dA.dA.AttributeSv1Ping(args, reply) +func (dA *DispatcherAttributeSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dA.dA.AttributeSv1Ping(ctx, args, reply) } // GetAttributeForEvent implements AttributeSv1GetAttributeForEvent -func (dA *DispatcherAttributeSv1) GetAttributeForEvent(args *utils.CGREvent, +func (dA *DispatcherAttributeSv1) GetAttributeForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.AttributeProfile) error { - return dA.dA.AttributeSv1GetAttributeForEvent(args, reply) + return dA.dA.AttributeSv1GetAttributeForEvent(ctx, args, reply) } // ProcessEvent implements AttributeSv1ProcessEvent -func (dA *DispatcherAttributeSv1) ProcessEvent(args *utils.CGREvent, +func (dA *DispatcherAttributeSv1) ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.AttrSProcessEventReply) error { - return dA.dA.AttributeSv1ProcessEvent(args, reply) + return dA.dA.AttributeSv1ProcessEvent(ctx, args, reply) } func NewDispatcherChargerSv1(dps *dispatchers.DispatcherService) *DispatcherChargerSv1 { @@ -408,20 +409,20 @@ type DispatcherChargerSv1 struct { } // Ping implements ChargerSv1Ping -func (dC *DispatcherChargerSv1) Ping(args *utils.CGREvent, reply *string) error { - return dC.dC.ChargerSv1Ping(args, reply) +func (dC *DispatcherChargerSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dC.dC.ChargerSv1Ping(ctx, args, reply) } // GetChargersForEvent implements ChargerSv1GetChargersForEvent -func (dC *DispatcherChargerSv1) GetChargersForEvent(args *utils.CGREvent, +func (dC *DispatcherChargerSv1) GetChargersForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.ChargerProfiles) (err error) { - return dC.dC.ChargerSv1GetChargersForEvent(args, reply) + return dC.dC.ChargerSv1GetChargersForEvent(ctx, args, reply) } // ProcessEvent implements ChargerSv1ProcessEvent -func (dC *DispatcherChargerSv1) ProcessEvent(args *utils.CGREvent, +func (dC *DispatcherChargerSv1) ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*engine.ChrgSProcessEventReply) (err error) { - return dC.dC.ChargerSv1ProcessEvent(args, reply) + return dC.dC.ChargerSv1ProcessEvent(ctx, args, reply) } func NewDispatcherSessionSv1(dps *dispatchers.DispatcherService) *DispatcherSessionSv1 { @@ -434,121 +435,121 @@ type DispatcherSessionSv1 struct { } // Ping implements SessionSv1Ping -func (dS *DispatcherSessionSv1) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.SessionSv1Ping(args, reply) +func (dS *DispatcherSessionSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.SessionSv1Ping(ctx, args, reply) } // AuthorizeEventWithDigest implements SessionSv1AuthorizeEventWithDigest -func (dS *DispatcherSessionSv1) AuthorizeEventWithDigest(args *sessions.V1AuthorizeArgs, +func (dS *DispatcherSessionSv1) AuthorizeEventWithDigest(ctx *context.Context, args *sessions.V1AuthorizeArgs, reply *sessions.V1AuthorizeReplyWithDigest) error { - return dS.dS.SessionSv1AuthorizeEventWithDigest(args, reply) + return dS.dS.SessionSv1AuthorizeEventWithDigest(ctx, args, reply) } -func (dS *DispatcherSessionSv1) AuthorizeEvent(args *sessions.V1AuthorizeArgs, +func (dS *DispatcherSessionSv1) AuthorizeEvent(ctx *context.Context, args *sessions.V1AuthorizeArgs, reply *sessions.V1AuthorizeReply) error { - return dS.dS.SessionSv1AuthorizeEvent(args, reply) + return dS.dS.SessionSv1AuthorizeEvent(ctx, args, reply) } // InitiateSessionWithDigest implements SessionSv1InitiateSessionWithDigest -func (dS *DispatcherSessionSv1) InitiateSessionWithDigest(args *sessions.V1InitSessionArgs, +func (dS *DispatcherSessionSv1) InitiateSessionWithDigest(ctx *context.Context, args *sessions.V1InitSessionArgs, reply *sessions.V1InitReplyWithDigest) (err error) { - return dS.dS.SessionSv1InitiateSessionWithDigest(args, reply) + return dS.dS.SessionSv1InitiateSessionWithDigest(ctx, args, reply) } // InitiateSessionWithDigest implements SessionSv1InitiateSessionWithDigest -func (dS *DispatcherSessionSv1) InitiateSession(args *sessions.V1InitSessionArgs, +func (dS *DispatcherSessionSv1) InitiateSession(ctx *context.Context, args *sessions.V1InitSessionArgs, reply *sessions.V1InitSessionReply) (err error) { - return dS.dS.SessionSv1InitiateSession(args, reply) + return dS.dS.SessionSv1InitiateSession(ctx, args, reply) } // ProcessCDR implements SessionSv1ProcessCDR -func (dS *DispatcherSessionSv1) ProcessCDR(args *utils.CGREvent, +func (dS *DispatcherSessionSv1) ProcessCDR(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { - return dS.dS.SessionSv1ProcessCDR(args, reply) + return dS.dS.SessionSv1ProcessCDR(ctx, args, reply) } // ProcessMessage implements SessionSv1ProcessMessage -func (dS *DispatcherSessionSv1) ProcessMessage(args *sessions.V1ProcessMessageArgs, +func (dS *DispatcherSessionSv1) ProcessMessage(ctx *context.Context, args *sessions.V1ProcessMessageArgs, reply *sessions.V1ProcessMessageReply) (err error) { - return dS.dS.SessionSv1ProcessMessage(args, reply) + return dS.dS.SessionSv1ProcessMessage(ctx, args, reply) } // ProcessMessage implements SessionSv1ProcessMessage -func (dS *DispatcherSessionSv1) ProcessEvent(args *sessions.V1ProcessEventArgs, +func (dS *DispatcherSessionSv1) ProcessEvent(ctx *context.Context, args *sessions.V1ProcessEventArgs, reply *sessions.V1ProcessEventReply) (err error) { - return dS.dS.SessionSv1ProcessEvent(args, reply) + return dS.dS.SessionSv1ProcessEvent(ctx, args, reply) } // GetCost implements SessionSv1GetCost -func (dS *DispatcherSessionSv1) GetCost(args *sessions.V1ProcessEventArgs, +func (dS *DispatcherSessionSv1) GetCost(ctx *context.Context, args *sessions.V1ProcessEventArgs, reply *sessions.V1GetCostReply) (err error) { - return dS.dS.SessionSv1GetCost(args, reply) + return dS.dS.SessionSv1GetCost(ctx, args, reply) } // TerminateSession implements SessionSv1TerminateSession -func (dS *DispatcherSessionSv1) TerminateSession(args *sessions.V1TerminateSessionArgs, +func (dS *DispatcherSessionSv1) TerminateSession(ctx *context.Context, args *sessions.V1TerminateSessionArgs, reply *string) (err error) { - return dS.dS.SessionSv1TerminateSession(args, reply) + return dS.dS.SessionSv1TerminateSession(ctx, args, reply) } // UpdateSession implements SessionSv1UpdateSession -func (dS *DispatcherSessionSv1) UpdateSession(args *sessions.V1UpdateSessionArgs, +func (dS *DispatcherSessionSv1) UpdateSession(ctx *context.Context, args *sessions.V1UpdateSessionArgs, reply *sessions.V1UpdateSessionReply) (err error) { - return dS.dS.SessionSv1UpdateSession(args, reply) + return dS.dS.SessionSv1UpdateSession(ctx, args, reply) } -func (dS *DispatcherSessionSv1) GetActiveSessions(args *utils.SessionFilter, +func (dS *DispatcherSessionSv1) GetActiveSessions(ctx *context.Context, args *utils.SessionFilter, reply *[]*sessions.ExternalSession) (err error) { - return dS.dS.SessionSv1GetActiveSessions(args, reply) + return dS.dS.SessionSv1GetActiveSessions(ctx, args, reply) } -func (dS *DispatcherSessionSv1) GetActiveSessionsCount(args *utils.SessionFilter, +func (dS *DispatcherSessionSv1) GetActiveSessionsCount(ctx *context.Context, args *utils.SessionFilter, reply *int) (err error) { - return dS.dS.SessionSv1GetActiveSessionsCount(args, reply) + return dS.dS.SessionSv1GetActiveSessionsCount(ctx, args, reply) } -func (dS *DispatcherSessionSv1) ForceDisconnect(args *utils.SessionFilter, +func (dS *DispatcherSessionSv1) ForceDisconnect(ctx *context.Context, args *utils.SessionFilter, reply *string) (err error) { - return dS.dS.SessionSv1ForceDisconnect(args, reply) + return dS.dS.SessionSv1ForceDisconnect(ctx, args, reply) } -func (dS *DispatcherSessionSv1) GetPassiveSessions(args *utils.SessionFilter, +func (dS *DispatcherSessionSv1) GetPassiveSessions(ctx *context.Context, args *utils.SessionFilter, reply *[]*sessions.ExternalSession) (err error) { - return dS.dS.SessionSv1GetPassiveSessions(args, reply) + return dS.dS.SessionSv1GetPassiveSessions(ctx, args, reply) } -func (dS *DispatcherSessionSv1) GetPassiveSessionsCount(args *utils.SessionFilter, +func (dS *DispatcherSessionSv1) GetPassiveSessionsCount(ctx *context.Context, args *utils.SessionFilter, reply *int) (err error) { - return dS.dS.SessionSv1GetPassiveSessionsCount(args, reply) + return dS.dS.SessionSv1GetPassiveSessionsCount(ctx, args, reply) } -func (dS *DispatcherSessionSv1) ReplicateSessions(args *dispatchers.ArgsReplicateSessionsWithAPIOpts, +func (dS *DispatcherSessionSv1) ReplicateSessions(ctx *context.Context, args *dispatchers.ArgsReplicateSessionsWithAPIOpts, reply *string) (err error) { - return dS.dS.SessionSv1ReplicateSessions(*args, reply) + return dS.dS.SessionSv1ReplicateSessions(ctx, *args, reply) } -func (dS *DispatcherSessionSv1) SetPassiveSession(args *sessions.Session, +func (dS *DispatcherSessionSv1) SetPassiveSession(ctx *context.Context, args *sessions.Session, reply *string) (err error) { - return dS.dS.SessionSv1SetPassiveSession(args, reply) + return dS.dS.SessionSv1SetPassiveSession(ctx, args, reply) } -func (dS *DispatcherSessionSv1) ActivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error { - return dS.dS.SessionSv1ActivateSessions(args, reply) +func (dS *DispatcherSessionSv1) ActivateSessions(ctx *context.Context, args *utils.SessionIDsWithArgsDispatcher, reply *string) error { + return dS.dS.SessionSv1ActivateSessions(ctx, args, reply) } -func (dS *DispatcherSessionSv1) DeactivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error { - return dS.dS.SessionSv1DeactivateSessions(args, reply) +func (dS *DispatcherSessionSv1) DeactivateSessions(ctx *context.Context, args *utils.SessionIDsWithArgsDispatcher, reply *string) error { + return dS.dS.SessionSv1DeactivateSessions(ctx, args, reply) } -func (dS *DispatcherSessionSv1) SyncSessions(args *utils.TenantWithAPIOpts, rply *string) error { - return dS.dS.SessionSv1SyncSessions(args, rply) +func (dS *DispatcherSessionSv1) SyncSessions(ctx *context.Context, args *utils.TenantWithAPIOpts, rply *string) error { + return dS.dS.SessionSv1SyncSessions(ctx, args, rply) } -func (dS *DispatcherSessionSv1) STIRAuthenticate(args *sessions.V1STIRAuthenticateArgs, reply *string) error { - return dS.dS.SessionSv1STIRAuthenticate(args, reply) +func (dS *DispatcherSessionSv1) STIRAuthenticate(ctx *context.Context, args *sessions.V1STIRAuthenticateArgs, reply *string) error { + return dS.dS.SessionSv1STIRAuthenticate(ctx, args, reply) } -func (dS *DispatcherSessionSv1) STIRIdentity(args *sessions.V1STIRIdentityArgs, reply *string) error { - return dS.dS.SessionSv1STIRIdentity(args, reply) +func (dS *DispatcherSessionSv1) STIRIdentity(ctx *context.Context, args *sessions.V1STIRIdentityArgs, reply *string) error { + return dS.dS.SessionSv1STIRIdentity(ctx, args, reply) } func NewDispatcherResponder(dps *dispatchers.DispatcherService) *DispatcherResponder { @@ -560,44 +561,44 @@ type DispatcherResponder struct { dS *dispatchers.DispatcherService } -func (dS *DispatcherResponder) GetCost(args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) error { - return dS.dS.ResponderGetCost(args, reply) +func (dS *DispatcherResponder) GetCost(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) error { + return dS.dS.ResponderGetCost(ctx, args, reply) } -func (dS *DispatcherResponder) Debit(args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) error { - return dS.dS.ResponderDebit(args, reply) +func (dS *DispatcherResponder) Debit(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) error { + return dS.dS.ResponderDebit(ctx, args, reply) } -func (dS *DispatcherResponder) MaxDebit(args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) error { - return dS.dS.ResponderMaxDebit(args, reply) +func (dS *DispatcherResponder) MaxDebit(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) error { + return dS.dS.ResponderMaxDebit(ctx, args, reply) } -func (dS *DispatcherResponder) RefundIncrements(args *engine.CallDescriptorWithAPIOpts, reply *engine.Account) error { - return dS.dS.ResponderRefundIncrements(args, reply) +func (dS *DispatcherResponder) RefundIncrements(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *engine.Account) error { + return dS.dS.ResponderRefundIncrements(ctx, args, reply) } -func (dS *DispatcherResponder) RefundRounding(args *engine.CallDescriptorWithAPIOpts, reply *engine.Account) error { - return dS.dS.ResponderRefundRounding(args, reply) +func (dS *DispatcherResponder) RefundRounding(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *engine.Account) error { + return dS.dS.ResponderRefundRounding(ctx, args, reply) } -func (dS *DispatcherResponder) GetMaxSessionTime(args *engine.CallDescriptorWithAPIOpts, reply *time.Duration) error { - return dS.dS.ResponderGetMaxSessionTime(args, reply) +func (dS *DispatcherResponder) GetMaxSessionTime(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *time.Duration) error { + return dS.dS.ResponderGetMaxSessionTime(ctx, args, reply) } -func (dS *DispatcherResponder) Shutdown(args *utils.TenantWithAPIOpts, reply *string) error { - return dS.dS.ResponderShutdown(args, reply) +func (dS *DispatcherResponder) Shutdown(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *string) error { + return dS.dS.ResponderShutdown(ctx, args, reply) } -func (dS *DispatcherResponder) GetCostOnRatingPlans(arg *utils.GetCostOnRatingPlansArgs, reply *map[string]any) (err error) { - return dS.dS.ResponderGetCostOnRatingPlans(arg, reply) +func (dS *DispatcherResponder) GetCostOnRatingPlans(ctx *context.Context, arg *utils.GetCostOnRatingPlansArgs, reply *map[string]any) (err error) { + return dS.dS.ResponderGetCostOnRatingPlans(ctx, arg, reply) } -func (dS *DispatcherResponder) GetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]any) (err error) { - return dS.dS.ResponderGetMaxSessionTimeOnAccounts(arg, reply) +func (dS *DispatcherResponder) GetMaxSessionTimeOnAccounts(ctx *context.Context, arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]any) (err error) { + return dS.dS.ResponderGetMaxSessionTimeOnAccounts(ctx, arg, reply) } // Ping used to detreminate if component is active -func (dS *DispatcherResponder) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.ResponderPing(args, reply) +func (dS *DispatcherResponder) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.ResponderPing(ctx, args, reply) } func NewDispatcherCacheSv1(dps *dispatchers.DispatcherService) *DispatcherCacheSv1 { @@ -610,105 +611,105 @@ type DispatcherCacheSv1 struct { } // GetItemIDs returns the IDs for cacheID with given prefix -func (dS *DispatcherCacheSv1) GetItemIDs(args *utils.ArgsGetCacheItemIDsWithAPIOpts, +func (dS *DispatcherCacheSv1) GetItemIDs(ctx *context.Context, args *utils.ArgsGetCacheItemIDsWithAPIOpts, reply *[]string) error { - return dS.dS.CacheSv1GetItemIDs(args, reply) + return dS.dS.CacheSv1GetItemIDs(ctx, args, reply) } // HasItem verifies the existence of an Item in cache -func (dS *DispatcherCacheSv1) HasItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (dS *DispatcherCacheSv1) HasItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *bool) error { - return dS.dS.CacheSv1HasItem(args, reply) + return dS.dS.CacheSv1HasItem(ctx, args, reply) } // GetItem returns an Item from the cache -func (dS *DispatcherCacheSv1) GetItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (dS *DispatcherCacheSv1) GetItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *any) error { - return dS.dS.CacheSv1GetItem(args, reply) + return dS.dS.CacheSv1GetItem(ctx, args, reply) } // GetItemWithRemote returns an Item from local or remote cache -func (dS *DispatcherCacheSv1) GetItemWithRemote(args *utils.ArgsGetCacheItemWithAPIOpts, +func (dS *DispatcherCacheSv1) GetItemWithRemote(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *any) error { - return dS.dS.CacheSv1GetItemWithRemote(args, reply) + return dS.dS.CacheSv1GetItemWithRemote(ctx, args, reply) } // GetItemExpiryTime returns the expiryTime for an item -func (dS *DispatcherCacheSv1) GetItemExpiryTime(args *utils.ArgsGetCacheItemWithAPIOpts, +func (dS *DispatcherCacheSv1) GetItemExpiryTime(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *time.Time) error { - return dS.dS.CacheSv1GetItemExpiryTime(args, reply) + return dS.dS.CacheSv1GetItemExpiryTime(ctx, args, reply) } // RemoveItem removes the Item with ID from cache -func (dS *DispatcherCacheSv1) RemoveItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (dS *DispatcherCacheSv1) RemoveItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *string) error { - return dS.dS.CacheSv1RemoveItem(args, reply) + return dS.dS.CacheSv1RemoveItem(ctx, args, reply) } // RemoveItems removes the Item with ID from cache -func (dS *DispatcherCacheSv1) RemoveItems(args *utils.AttrReloadCacheWithAPIOpts, +func (dS *DispatcherCacheSv1) RemoveItems(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) error { - return dS.dS.CacheSv1RemoveItems(args, reply) + return dS.dS.CacheSv1RemoveItems(ctx, args, reply) } // Clear will clear partitions in the cache (nil fol all, empty slice for none) -func (dS *DispatcherCacheSv1) Clear(args *utils.AttrCacheIDsWithAPIOpts, +func (dS *DispatcherCacheSv1) Clear(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, reply *string) error { - return dS.dS.CacheSv1Clear(args, reply) + return dS.dS.CacheSv1Clear(ctx, args, reply) } // GetCacheStats returns CacheStats filtered by cacheIDs -func (dS *DispatcherCacheSv1) GetCacheStats(args *utils.AttrCacheIDsWithAPIOpts, +func (dS *DispatcherCacheSv1) GetCacheStats(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, reply *map[string]*ltcache.CacheStats) error { - return dS.dS.CacheSv1GetCacheStats(args, reply) + return dS.dS.CacheSv1GetCacheStats(ctx, args, reply) } // PrecacheStatus checks status of active precache processes -func (dS *DispatcherCacheSv1) PrecacheStatus(args *utils.AttrCacheIDsWithAPIOpts, reply *map[string]string) error { - return dS.dS.CacheSv1PrecacheStatus(args, reply) +func (dS *DispatcherCacheSv1) PrecacheStatus(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, reply *map[string]string) error { + return dS.dS.CacheSv1PrecacheStatus(ctx, args, reply) } // HasGroup checks existence of a group in cache -func (dS *DispatcherCacheSv1) HasGroup(args *utils.ArgsGetGroupWithAPIOpts, +func (dS *DispatcherCacheSv1) HasGroup(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, reply *bool) (err error) { - return dS.dS.CacheSv1HasGroup(args, reply) + return dS.dS.CacheSv1HasGroup(ctx, args, reply) } // GetGroupItemIDs returns a list of itemIDs in a cache group -func (dS *DispatcherCacheSv1) GetGroupItemIDs(args *utils.ArgsGetGroupWithAPIOpts, +func (dS *DispatcherCacheSv1) GetGroupItemIDs(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, reply *[]string) (err error) { - return dS.dS.CacheSv1GetGroupItemIDs(args, reply) + return dS.dS.CacheSv1GetGroupItemIDs(ctx, args, reply) } // RemoveGroup will remove a group and all items belonging to it from cache -func (dS *DispatcherCacheSv1) RemoveGroup(args *utils.ArgsGetGroupWithAPIOpts, +func (dS *DispatcherCacheSv1) RemoveGroup(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, reply *string) (err error) { - return dS.dS.CacheSv1RemoveGroup(args, reply) + return dS.dS.CacheSv1RemoveGroup(ctx, args, reply) } // ReloadCache reloads cache from DB for a prefix or completely -func (dS *DispatcherCacheSv1) ReloadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { - return dS.dS.CacheSv1ReloadCache(args, reply) +func (dS *DispatcherCacheSv1) ReloadCache(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { + return dS.dS.CacheSv1ReloadCache(ctx, args, reply) } // LoadCache loads cache from DB for a prefix or completely -func (dS *DispatcherCacheSv1) LoadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { - return dS.dS.CacheSv1LoadCache(args, reply) +func (dS *DispatcherCacheSv1) LoadCache(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { + return dS.dS.CacheSv1LoadCache(ctx, args, reply) } // ReplicateSet replicate an item -func (dS *DispatcherCacheSv1) ReplicateSet(args *utils.ArgCacheReplicateSet, reply *string) (err error) { - return dS.dS.CacheSv1ReplicateSet(args, reply) +func (dS *DispatcherCacheSv1) ReplicateSet(ctx *context.Context, args *utils.ArgCacheReplicateSet, reply *string) (err error) { + return dS.dS.CacheSv1ReplicateSet(ctx, args, reply) } // ReplicateRemove remove an item -func (dS *DispatcherCacheSv1) ReplicateRemove(args *utils.ArgCacheReplicateRemove, reply *string) (err error) { - return dS.dS.CacheSv1ReplicateRemove(args, reply) +func (dS *DispatcherCacheSv1) ReplicateRemove(ctx *context.Context, args *utils.ArgCacheReplicateRemove, reply *string) (err error) { + return dS.dS.CacheSv1ReplicateRemove(ctx, args, reply) } // Ping used to determinate if component is active -func (dS *DispatcherCacheSv1) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.CacheSv1Ping(args, reply) +func (dS *DispatcherCacheSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.CacheSv1Ping(ctx, args, reply) } func NewDispatcherGuardianSv1(dps *dispatchers.DispatcherService) *DispatcherGuardianSv1 { @@ -721,18 +722,18 @@ type DispatcherGuardianSv1 struct { } // RemoteLock will lock a key from remote -func (dS *DispatcherGuardianSv1) RemoteLock(attr *dispatchers.AttrRemoteLockWithAPIOpts, reply *string) (err error) { - return dS.dS.GuardianSv1RemoteLock(*attr, reply) +func (dS *DispatcherGuardianSv1) RemoteLock(ctx *context.Context, attr *dispatchers.AttrRemoteLockWithAPIOpts, reply *string) (err error) { + return dS.dS.GuardianSv1RemoteLock(ctx, *attr, reply) } // RemoteUnlock will unlock a key from remote based on reference ID -func (dS *DispatcherGuardianSv1) RemoteUnlock(attr *dispatchers.AttrRemoteUnlockWithAPIOpts, reply *[]string) (err error) { - return dS.dS.GuardianSv1RemoteUnlock(*attr, reply) +func (dS *DispatcherGuardianSv1) RemoteUnlock(ctx *context.Context, attr *dispatchers.AttrRemoteUnlockWithAPIOpts, reply *[]string) (err error) { + return dS.dS.GuardianSv1RemoteUnlock(ctx, *attr, reply) } // Ping used to detreminate if component is active -func (dS *DispatcherGuardianSv1) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.GuardianSv1Ping(args, reply) +func (dS *DispatcherGuardianSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.GuardianSv1Ping(ctx, args, reply) } func NewDispatcherSchedulerSv1(dps *dispatchers.DispatcherService) *DispatcherSchedulerSv1 { @@ -745,23 +746,23 @@ type DispatcherSchedulerSv1 struct { } // Reload reloads scheduler instructions -func (dS *DispatcherSchedulerSv1) Reload(attr *utils.CGREvent, reply *string) (err error) { - return dS.dS.SchedulerSv1Reload(attr, reply) +func (dS *DispatcherSchedulerSv1) Reload(ctx *context.Context, attr *utils.CGREvent, reply *string) (err error) { + return dS.dS.SchedulerSv1Reload(ctx, attr, reply) } // Ping used to detreminate if component is active -func (dS *DispatcherSchedulerSv1) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.SchedulerSv1Ping(args, reply) +func (dS *DispatcherSchedulerSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.SchedulerSv1Ping(ctx, args, reply) } // ExecuteActions execute an actionPlan or multiple actionsPlans between a time interval -func (dS *DispatcherSchedulerSv1) ExecuteActions(args *utils.AttrsExecuteActions, reply *string) error { - return dS.dS.SchedulerSv1ExecuteActions(args, reply) +func (dS *DispatcherSchedulerSv1) ExecuteActions(ctx *context.Context, args *utils.AttrsExecuteActions, reply *string) error { + return dS.dS.SchedulerSv1ExecuteActions(ctx, args, reply) } // ExecuteActionPlans execute multiple actionPlans one by one -func (dS *DispatcherSchedulerSv1) ExecuteActionPlans(args *utils.AttrsExecuteActionPlans, reply *string) (err error) { - return dS.dS.SchedulerSv1ExecuteActionPlans(args, reply) +func (dS *DispatcherSchedulerSv1) ExecuteActionPlans(ctx *context.Context, args *utils.AttrsExecuteActionPlans, reply *string) (err error) { + return dS.dS.SchedulerSv1ExecuteActionPlans(ctx, args, reply) } func NewDispatcherSv1(dS *dispatchers.DispatcherService) *DispatcherSv1 { @@ -773,30 +774,30 @@ type DispatcherSv1 struct { } // GetProfileForEvent returns the matching dispatcher profile for the provided event -func (dSv1 DispatcherSv1) GetProfilesForEvent(ev *utils.CGREvent, +func (dSv1 DispatcherSv1) GetProfilesForEvent(ctx *context.Context, ev *utils.CGREvent, dPrfl *engine.DispatcherProfiles) error { - return dSv1.dS.V1GetProfilesForEvent(ev, dPrfl) + return dSv1.dS.DispatcherSv1GetProfilesForEvent(ctx, ev, dPrfl) } -func (dS *DispatcherSv1) RemoteStatus(args *utils.TenantWithAPIOpts, reply *map[string]any) (err error) { - return dS.dS.DispatcherSv1RemoteStatus(args, reply) +func (dS *DispatcherSv1) RemoteStatus(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *map[string]any) (err error) { + return dS.dS.DispatcherSv1RemoteStatus(ctx, args, reply) } -func (dS *DispatcherSv1) RemotePing(args *utils.CGREvent, reply *string) (err error) { - return dS.dS.DispatcherSv1RemotePing(args, reply) +func (dS *DispatcherSv1) RemotePing(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { + return dS.dS.DispatcherSv1RemotePing(ctx, args, reply) } -func (dS *DispatcherSv1) RemoteSleep(args *utils.DurationArgs, reply *string) (err error) { - return dS.dS.DispatcherSv1RemoteSleep(args, reply) +func (dS *DispatcherSv1) RemoteSleep(ctx *context.Context, args *utils.DurationArgs, reply *string) (err error) { + return dS.dS.DispatcherSv1RemoteSleep(ctx, args, reply) } /* -func (dSv1 DispatcherSv1) Apier(args *utils.MethodParameters, reply *any) (err error) { - return dSv1.dS.V1Apier(new(APIerSv1), args, reply) +func (dSv1 DispatcherSv1) Apier(ctx *context.Context,args *utils.MethodParameters, reply *any) (err error) { + return dSv1.dS.V1Apier(ctx,new(APIerSv1), args, reply) } */ -func (rS *DispatcherSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (rS *DispatcherSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } @@ -811,36 +812,36 @@ type DispatcherSCDRsV1 struct { } // Ping used to detreminate if component is active -func (dS *DispatcherSCDRsV1) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.CDRsV1Ping(args, reply) +func (dS *DispatcherSCDRsV1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.CDRsV1Ping(ctx, args, reply) } -func (dS *DispatcherSCDRsV1) GetCDRs(args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) error { - return dS.dS.CDRsV1GetCDRs(args, reply) +func (dS *DispatcherSCDRsV1) GetCDRs(ctx *context.Context, args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) error { + return dS.dS.CDRsV1GetCDRs(ctx, args, reply) } -func (dS *DispatcherSCDRsV1) GetCDRsCount(args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) error { - return dS.dS.CDRsV1GetCDRsCount(args, reply) +func (dS *DispatcherSCDRsV1) GetCDRsCount(ctx *context.Context, args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) error { + return dS.dS.CDRsV1GetCDRsCount(ctx, args, reply) } -func (dS *DispatcherSCDRsV1) StoreSessionCost(args *engine.AttrCDRSStoreSMCost, reply *string) error { - return dS.dS.CDRsV1StoreSessionCost(args, reply) +func (dS *DispatcherSCDRsV1) StoreSessionCost(ctx *context.Context, args *engine.AttrCDRSStoreSMCost, reply *string) error { + return dS.dS.CDRsV1StoreSessionCost(ctx, args, reply) } -func (dS *DispatcherSCDRsV1) RateCDRs(args *engine.ArgRateCDRs, reply *string) error { - return dS.dS.CDRsV1RateCDRs(args, reply) +func (dS *DispatcherSCDRsV1) RateCDRs(ctx *context.Context, args *engine.ArgRateCDRs, reply *string) error { + return dS.dS.CDRsV1RateCDRs(ctx, args, reply) } -func (dS *DispatcherSCDRsV1) ProcessExternalCDR(args *engine.ExternalCDRWithAPIOpts, reply *string) error { - return dS.dS.CDRsV1ProcessExternalCDR(args, reply) +func (dS *DispatcherSCDRsV1) ProcessExternalCDR(ctx *context.Context, args *engine.ExternalCDRWithAPIOpts, reply *string) error { + return dS.dS.CDRsV1ProcessExternalCDR(ctx, args, reply) } -func (dS *DispatcherSCDRsV1) ProcessEvent(args *engine.ArgV1ProcessEvent, reply *string) error { - return dS.dS.CDRsV1ProcessEvent(args, reply) +func (dS *DispatcherSCDRsV1) ProcessEvent(ctx *context.Context, args *engine.ArgV1ProcessEvent, reply *string) error { + return dS.dS.CDRsV1ProcessEvent(ctx, args, reply) } -func (dS *DispatcherSCDRsV1) ProcessCDR(args *engine.CDRWithAPIOpts, reply *string) error { - return dS.dS.CDRsV1ProcessCDR(args, reply) +func (dS *DispatcherSCDRsV1) ProcessCDR(ctx *context.Context, args *engine.CDRWithAPIOpts, reply *string) error { + return dS.dS.CDRsV1ProcessCDR(ctx, args, reply) } func NewDispatcherSServiceManagerV1(dps *dispatchers.DispatcherService) *DispatcherSServiceManagerV1 { @@ -853,17 +854,17 @@ type DispatcherSServiceManagerV1 struct { } // Ping used to detreminate if component is active -func (dS *DispatcherSServiceManagerV1) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.ServiceManagerV1Ping(args, reply) +func (dS *DispatcherSServiceManagerV1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.ServiceManagerV1Ping(ctx, args, reply) } -func (dS *DispatcherSServiceManagerV1) StartService(args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error { - return dS.dS.ServiceManagerV1StartService(*args, reply) +func (dS *DispatcherSServiceManagerV1) StartService(ctx *context.Context, args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error { + return dS.dS.ServiceManagerV1StartService(ctx, *args, reply) } -func (dS *DispatcherSServiceManagerV1) StopService(args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error { - return dS.dS.ServiceManagerV1StopService(*args, reply) +func (dS *DispatcherSServiceManagerV1) StopService(ctx *context.Context, args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error { + return dS.dS.ServiceManagerV1StopService(ctx, *args, reply) } -func (dS *DispatcherSServiceManagerV1) ServiceStatus(args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error { - return dS.dS.ServiceManagerV1ServiceStatus(*args, reply) +func (dS *DispatcherSServiceManagerV1) ServiceStatus(ctx *context.Context, args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) error { + return dS.dS.ServiceManagerV1ServiceStatus(ctx, *args, reply) } func NewDispatcherConfigSv1(dps *dispatchers.DispatcherService) *DispatcherConfigSv1 { @@ -875,23 +876,23 @@ type DispatcherConfigSv1 struct { dS *dispatchers.DispatcherService } -func (dS *DispatcherConfigSv1) GetConfig(args *config.SectionWithAPIOpts, reply *map[string]any) (err error) { - return dS.dS.ConfigSv1GetConfig(args, reply) +func (dS *DispatcherConfigSv1) GetConfig(ctx *context.Context, args *config.SectionWithAPIOpts, reply *map[string]any) (err error) { + return dS.dS.ConfigSv1GetConfig(ctx, args, reply) } -func (dS *DispatcherConfigSv1) ReloadConfig(args *config.ReloadArgs, reply *string) (err error) { - return dS.dS.ConfigSv1ReloadConfig(args, reply) +func (dS *DispatcherConfigSv1) ReloadConfig(ctx *context.Context, args *config.ReloadArgs, reply *string) (err error) { + return dS.dS.ConfigSv1ReloadConfig(ctx, args, reply) } -func (dS *DispatcherConfigSv1) SetConfig(args *config.SetConfigArgs, reply *string) (err error) { - return dS.dS.ConfigSv1SetConfig(args, reply) +func (dS *DispatcherConfigSv1) SetConfig(ctx *context.Context, args *config.SetConfigArgs, reply *string) (err error) { + return dS.dS.ConfigSv1SetConfig(ctx, args, reply) } -func (dS *DispatcherConfigSv1) SetConfigFromJSON(args *config.SetConfigFromJSONArgs, reply *string) (err error) { - return dS.dS.ConfigSv1SetConfigFromJSON(args, reply) +func (dS *DispatcherConfigSv1) SetConfigFromJSON(ctx *context.Context, args *config.SetConfigFromJSONArgs, reply *string) (err error) { + return dS.dS.ConfigSv1SetConfigFromJSON(ctx, args, reply) } -func (dS *DispatcherConfigSv1) GetConfigAsJSON(args *config.SectionWithAPIOpts, reply *string) (err error) { - return dS.dS.ConfigSv1GetConfigAsJSON(args, reply) +func (dS *DispatcherConfigSv1) GetConfigAsJSON(ctx *context.Context, args *config.SectionWithAPIOpts, reply *string) (err error) { + return dS.dS.ConfigSv1GetConfigAsJSON(ctx, args, reply) } func NewDispatcherRALsV1(dps *dispatchers.DispatcherService) *DispatcherRALsV1 { @@ -903,13 +904,13 @@ type DispatcherRALsV1 struct { dS *dispatchers.DispatcherService } -func (dS *DispatcherRALsV1) GetRatingPlansCost(args *utils.RatingPlanCostArg, reply *dispatchers.RatingPlanCost) error { - return dS.dS.RALsV1GetRatingPlansCost(args, reply) +func (dS *DispatcherRALsV1) GetRatingPlansCost(ctx *context.Context, args *utils.RatingPlanCostArg, reply *dispatchers.RatingPlanCost) error { + return dS.dS.RALsV1GetRatingPlansCost(ctx, args, reply) } // Ping used to detreminate if component is active -func (dS *DispatcherRALsV1) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.RALsV1Ping(args, reply) +func (dS *DispatcherRALsV1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.RALsV1Ping(ctx, args, reply) } // DispatcherCoreSv1 exports RPC from CoreSv1 @@ -921,36 +922,36 @@ func NewDispatcherCoreSv1(dps *dispatchers.DispatcherService) *DispatcherCoreSv1 return &DispatcherCoreSv1{dS: dps} } -func (dS *DispatcherCoreSv1) Status(args *utils.TenantWithAPIOpts, reply *map[string]any) error { - return dS.dS.CoreSv1Status(args, reply) +func (dS *DispatcherCoreSv1) Status(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *map[string]any) error { + return dS.dS.CoreSv1Status(ctx, args, reply) } -func (dS *DispatcherCoreSv1) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.CoreSv1Ping(args, reply) +func (dS *DispatcherCoreSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.CoreSv1Ping(ctx, args, reply) } -func (dS *DispatcherCoreSv1) Sleep(args *utils.DurationArgs, reply *string) error { - return dS.dS.CoreSv1Sleep(args, reply) +func (dS *DispatcherCoreSv1) Sleep(ctx *context.Context, args *utils.DurationArgs, reply *string) error { + return dS.dS.CoreSv1Sleep(ctx, args, reply) } -func (dS *DispatcherCoreSv1) StartCPUProfiling(args *utils.DirectoryArgs, reply *string) error { - return dS.dS.CoreSv1StartCPUProfiling(args, reply) +func (dS *DispatcherCoreSv1) StartCPUProfiling(ctx *context.Context, args *utils.DirectoryArgs, reply *string) error { + return dS.dS.CoreSv1StartCPUProfiling(ctx, args, reply) } -func (dS *DispatcherCoreSv1) StopCPUProfiling(args *utils.TenantWithAPIOpts, reply *string) error { - return dS.dS.CoreSv1StopCPUProfiling(args, reply) +func (dS *DispatcherCoreSv1) StopCPUProfiling(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *string) error { + return dS.dS.CoreSv1StopCPUProfiling(ctx, args, reply) } -func (dS *DispatcherCoreSv1) StartMemoryProfiling(args *utils.MemoryPrf, reply *string) error { - return dS.dS.CoreSv1StartMemoryProfiling(args, reply) +func (dS *DispatcherCoreSv1) StartMemoryProfiling(ctx *context.Context, args *utils.MemoryPrf, reply *string) error { + return dS.dS.CoreSv1StartMemoryProfiling(ctx, args, reply) } -func (dS *DispatcherCoreSv1) StopMemoryProfiling(args *utils.TenantWithAPIOpts, reply *string) error { - return dS.dS.CoreSv1StopMemoryProfiling(args, reply) +func (dS *DispatcherCoreSv1) StopMemoryProfiling(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *string) error { + return dS.dS.CoreSv1StopMemoryProfiling(ctx, args, reply) } -func (dS *DispatcherCoreSv1) Panic(args *utils.PanicMessageArgs, reply *string) error { - return dS.dS.CoreSv1Panic(args, reply) +func (dS *DispatcherCoreSv1) Panic(ctx *context.Context, args *utils.PanicMessageArgs, reply *string) error { + return dS.dS.CoreSv1Panic(ctx, args, reply) } // DispatcherCoreSv1 exports RPC from CoreSv1 @@ -962,12 +963,12 @@ func NewDispatcherEeSv1(dps *dispatchers.DispatcherService) *DispatcherEeSv1 { return &DispatcherEeSv1{dS: dps} } -func (dS *DispatcherEeSv1) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.EeSv1Ping(args, reply) +func (dS *DispatcherEeSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.EeSv1Ping(ctx, args, reply) } -func (dS *DispatcherEeSv1) ProcessEvent(args *engine.CGREventWithEeIDs, reply *map[string]map[string]any) error { - return dS.dS.EeSv1ProcessEvent(args, reply) +func (dS *DispatcherEeSv1) ProcessEvent(ctx *context.Context, args *engine.CGREventWithEeIDs, reply *map[string]map[string]any) error { + return dS.dS.EeSv1ProcessEvent(ctx, args, reply) } type DispatcherReplicatorSv1 struct { @@ -979,378 +980,378 @@ func NewDispatcherReplicatorSv1(dps *dispatchers.DispatcherService) *DispatcherR } // Ping used to detreminate if component is active -func (dS *DispatcherReplicatorSv1) Ping(args *utils.CGREvent, reply *string) error { - return dS.dS.ReplicatorSv1Ping(args, reply) +func (dS *DispatcherReplicatorSv1) Ping(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return dS.dS.ReplicatorSv1Ping(ctx, args, reply) } // GetAccount -func (dS *DispatcherReplicatorSv1) GetAccount(args *utils.StringWithAPIOpts, reply *engine.Account) error { - return dS.dS.ReplicatorSv1GetAccount(args, reply) +func (dS *DispatcherReplicatorSv1) GetAccount(ctx *context.Context, args *utils.StringWithAPIOpts, reply *engine.Account) error { + return dS.dS.ReplicatorSv1GetAccount(ctx, args, reply) } // GetDestination -func (dS *DispatcherReplicatorSv1) GetDestination(key *utils.StringWithAPIOpts, reply *engine.Destination) error { - return dS.dS.ReplicatorSv1GetDestination(key, reply) +func (dS *DispatcherReplicatorSv1) GetDestination(ctx *context.Context, key *utils.StringWithAPIOpts, reply *engine.Destination) error { + return dS.dS.ReplicatorSv1GetDestination(ctx, key, reply) } // GetReverseDestination -func (dS *DispatcherReplicatorSv1) GetReverseDestination(key *utils.StringWithAPIOpts, reply *[]string) error { - return dS.dS.ReplicatorSv1GetReverseDestination(key, reply) +func (dS *DispatcherReplicatorSv1) GetReverseDestination(ctx *context.Context, key *utils.StringWithAPIOpts, reply *[]string) error { + return dS.dS.ReplicatorSv1GetReverseDestination(ctx, key, reply) } // GetStatQueue -func (dS *DispatcherReplicatorSv1) GetStatQueue(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) error { - return dS.dS.ReplicatorSv1GetStatQueue(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetStatQueue(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) error { + return dS.dS.ReplicatorSv1GetStatQueue(ctx, tntID, reply) } // GetFilter -func (dS *DispatcherReplicatorSv1) GetFilter(tntID *utils.TenantIDWithAPIOpts, reply *engine.Filter) error { - return dS.dS.ReplicatorSv1GetFilter(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetFilter(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.Filter) error { + return dS.dS.ReplicatorSv1GetFilter(ctx, tntID, reply) } // GetThreshold -func (dS *DispatcherReplicatorSv1) GetThreshold(tntID *utils.TenantIDWithAPIOpts, reply *engine.Threshold) error { - return dS.dS.ReplicatorSv1GetThreshold(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetThreshold(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.Threshold) error { + return dS.dS.ReplicatorSv1GetThreshold(ctx, tntID, reply) } // GetThresholdProfile -func (dS *DispatcherReplicatorSv1) GetThresholdProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) error { - return dS.dS.ReplicatorSv1GetThresholdProfile(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetThresholdProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) error { + return dS.dS.ReplicatorSv1GetThresholdProfile(ctx, tntID, reply) } // GetStatQueueProfile -func (dS *DispatcherReplicatorSv1) GetStatQueueProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) error { - return dS.dS.ReplicatorSv1GetStatQueueProfile(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetStatQueueProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) error { + return dS.dS.ReplicatorSv1GetStatQueueProfile(ctx, tntID, reply) } // GetTiming -func (dS *DispatcherReplicatorSv1) GetTiming(id *utils.StringWithAPIOpts, reply *utils.TPTiming) error { - return dS.dS.ReplicatorSv1GetTiming(id, reply) +func (dS *DispatcherReplicatorSv1) GetTiming(ctx *context.Context, id *utils.StringWithAPIOpts, reply *utils.TPTiming) error { + return dS.dS.ReplicatorSv1GetTiming(ctx, id, reply) } // GetResource -func (dS *DispatcherReplicatorSv1) GetResource(tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error { - return dS.dS.ReplicatorSv1GetResource(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetResource(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error { + return dS.dS.ReplicatorSv1GetResource(ctx, tntID, reply) } // GetResourceProfile -func (dS *DispatcherReplicatorSv1) GetResourceProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error { - return dS.dS.ReplicatorSv1GetResourceProfile(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetResourceProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error { + return dS.dS.ReplicatorSv1GetResourceProfile(ctx, tntID, reply) } // GetActionTriggers -func (dS *DispatcherReplicatorSv1) GetActionTriggers(id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error { - return dS.dS.ReplicatorSv1GetActionTriggers(id, reply) +func (dS *DispatcherReplicatorSv1) GetActionTriggers(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error { + return dS.dS.ReplicatorSv1GetActionTriggers(ctx, id, reply) } // GetSharedGroup -func (dS *DispatcherReplicatorSv1) GetSharedGroup(id *utils.StringWithAPIOpts, reply *engine.SharedGroup) error { - return dS.dS.ReplicatorSv1GetSharedGroup(id, reply) +func (dS *DispatcherReplicatorSv1) GetSharedGroup(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.SharedGroup) error { + return dS.dS.ReplicatorSv1GetSharedGroup(ctx, id, reply) } // GetActions -func (dS *DispatcherReplicatorSv1) GetActions(id *utils.StringWithAPIOpts, reply *engine.Actions) error { - return dS.dS.ReplicatorSv1GetActions(id, reply) +func (dS *DispatcherReplicatorSv1) GetActions(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.Actions) error { + return dS.dS.ReplicatorSv1GetActions(ctx, id, reply) } // GetActionPlan -func (dS *DispatcherReplicatorSv1) GetActionPlan(id *utils.StringWithAPIOpts, reply *engine.ActionPlan) error { - return dS.dS.ReplicatorSv1GetActionPlan(id, reply) +func (dS *DispatcherReplicatorSv1) GetActionPlan(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.ActionPlan) error { + return dS.dS.ReplicatorSv1GetActionPlan(ctx, id, reply) } // GetAllActionPlans -func (dS *DispatcherReplicatorSv1) GetAllActionPlans(args *utils.StringWithAPIOpts, reply *map[string]*engine.ActionPlan) error { - return dS.dS.ReplicatorSv1GetAllActionPlans(args, reply) +func (dS *DispatcherReplicatorSv1) GetAllActionPlans(ctx *context.Context, args *utils.StringWithAPIOpts, reply *map[string]*engine.ActionPlan) error { + return dS.dS.ReplicatorSv1GetAllActionPlans(ctx, args, reply) } // GetAccountActionPlans -func (dS *DispatcherReplicatorSv1) GetAccountActionPlans(id *utils.StringWithAPIOpts, reply *[]string) error { - return dS.dS.ReplicatorSv1GetAccountActionPlans(id, reply) +func (dS *DispatcherReplicatorSv1) GetAccountActionPlans(ctx *context.Context, id *utils.StringWithAPIOpts, reply *[]string) error { + return dS.dS.ReplicatorSv1GetAccountActionPlans(ctx, id, reply) } // GetRatingPlan -func (dS *DispatcherReplicatorSv1) GetRatingPlan(id *utils.StringWithAPIOpts, reply *engine.RatingPlan) error { - return dS.dS.ReplicatorSv1GetRatingPlan(id, reply) +func (dS *DispatcherReplicatorSv1) GetRatingPlan(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.RatingPlan) error { + return dS.dS.ReplicatorSv1GetRatingPlan(ctx, id, reply) } // GetRatingProfile -func (dS *DispatcherReplicatorSv1) GetRatingProfile(id *utils.StringWithAPIOpts, reply *engine.RatingProfile) error { - return dS.dS.ReplicatorSv1GetRatingProfile(id, reply) +func (dS *DispatcherReplicatorSv1) GetRatingProfile(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.RatingProfile) error { + return dS.dS.ReplicatorSv1GetRatingProfile(ctx, id, reply) } // GetRouteProfile -func (dS *DispatcherReplicatorSv1) GetRouteProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error { - return dS.dS.ReplicatorSv1GetRouteProfile(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetRouteProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error { + return dS.dS.ReplicatorSv1GetRouteProfile(ctx, tntID, reply) } // GetAttributeProfile -func (dS *DispatcherReplicatorSv1) GetAttributeProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) error { - return dS.dS.ReplicatorSv1GetAttributeProfile(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetAttributeProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) error { + return dS.dS.ReplicatorSv1GetAttributeProfile(ctx, tntID, reply) } // GetChargerProfile -func (dS *DispatcherReplicatorSv1) GetChargerProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) error { - return dS.dS.ReplicatorSv1GetChargerProfile(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetChargerProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) error { + return dS.dS.ReplicatorSv1GetChargerProfile(ctx, tntID, reply) } // GetDispatcherProfile -func (dS *DispatcherReplicatorSv1) GetDispatcherProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) error { - return dS.dS.ReplicatorSv1GetDispatcherProfile(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetDispatcherProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) error { + return dS.dS.ReplicatorSv1GetDispatcherProfile(ctx, tntID, reply) } // GetDispatcherHost -func (dS *DispatcherReplicatorSv1) GetDispatcherHost(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) error { - return dS.dS.ReplicatorSv1GetDispatcherHost(tntID, reply) +func (dS *DispatcherReplicatorSv1) GetDispatcherHost(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) error { + return dS.dS.ReplicatorSv1GetDispatcherHost(ctx, tntID, reply) } // GetItemLoadIDs -func (dS *DispatcherReplicatorSv1) GetItemLoadIDs(itemID *utils.StringWithAPIOpts, reply *map[string]int64) error { - return dS.dS.ReplicatorSv1GetItemLoadIDs(itemID, reply) +func (dS *DispatcherReplicatorSv1) GetItemLoadIDs(ctx *context.Context, itemID *utils.StringWithAPIOpts, reply *map[string]int64) error { + return dS.dS.ReplicatorSv1GetItemLoadIDs(ctx, itemID, reply) } //finished all the above // SetThresholdProfile -func (dS *DispatcherReplicatorSv1) SetThresholdProfile(args *engine.ThresholdProfileWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetThresholdProfile(args, reply) +func (dS *DispatcherReplicatorSv1) SetThresholdProfile(ctx *context.Context, args *engine.ThresholdProfileWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetThresholdProfile(ctx, args, reply) } // SetThreshold -func (dS *DispatcherReplicatorSv1) SetThreshold(args *engine.ThresholdWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetThreshold(args, reply) +func (dS *DispatcherReplicatorSv1) SetThreshold(ctx *context.Context, args *engine.ThresholdWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetThreshold(ctx, args, reply) } // SetDestination -func (dS *DispatcherReplicatorSv1) SetDestination(args *engine.DestinationWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetDestination(args, reply) +func (dS *DispatcherReplicatorSv1) SetDestination(ctx *context.Context, args *engine.DestinationWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetDestination(ctx, args, reply) } // SetAccount -func (dS *DispatcherReplicatorSv1) SetAccount(args *engine.AccountWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetAccount(args, reply) +func (dS *DispatcherReplicatorSv1) SetAccount(ctx *context.Context, args *engine.AccountWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetAccount(ctx, args, reply) } // SetReverseDestination -func (dS *DispatcherReplicatorSv1) SetReverseDestination(args *engine.DestinationWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetReverseDestination(args, reply) +func (dS *DispatcherReplicatorSv1) SetReverseDestination(ctx *context.Context, args *engine.DestinationWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetReverseDestination(ctx, args, reply) } // SetStatQueue -func (dS *DispatcherReplicatorSv1) SetStatQueue(args *engine.StatQueueWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetStatQueue(args, reply) +func (dS *DispatcherReplicatorSv1) SetStatQueue(ctx *context.Context, args *engine.StatQueueWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetStatQueue(ctx, args, reply) } // SetFilter -func (dS *DispatcherReplicatorSv1) SetFilter(args *engine.FilterWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetFilter(args, reply) +func (dS *DispatcherReplicatorSv1) SetFilter(ctx *context.Context, args *engine.FilterWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetFilter(ctx, args, reply) } // SetStatQueueProfile -func (dS *DispatcherReplicatorSv1) SetStatQueueProfile(args *engine.StatQueueProfileWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetStatQueueProfile(args, reply) +func (dS *DispatcherReplicatorSv1) SetStatQueueProfile(ctx *context.Context, args *engine.StatQueueProfileWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetStatQueueProfile(ctx, args, reply) } // SetTiming -func (dS *DispatcherReplicatorSv1) SetTiming(args *utils.TPTimingWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetTiming(args, reply) +func (dS *DispatcherReplicatorSv1) SetTiming(ctx *context.Context, args *utils.TPTimingWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetTiming(ctx, args, reply) } // SetResource -func (dS *DispatcherReplicatorSv1) SetResource(args *engine.ResourceWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetResource(args, reply) +func (dS *DispatcherReplicatorSv1) SetResource(ctx *context.Context, args *engine.ResourceWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetResource(ctx, args, reply) } // SetResourceProfile -func (dS *DispatcherReplicatorSv1) SetResourceProfile(args *engine.ResourceProfileWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetResourceProfile(args, reply) +func (dS *DispatcherReplicatorSv1) SetResourceProfile(ctx *context.Context, args *engine.ResourceProfileWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetResourceProfile(ctx, args, reply) } // SetActionTriggers -func (dS *DispatcherReplicatorSv1) SetActionTriggers(args *engine.SetActionTriggersArgWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetActionTriggers(args, reply) +func (dS *DispatcherReplicatorSv1) SetActionTriggers(ctx *context.Context, args *engine.SetActionTriggersArgWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetActionTriggers(ctx, args, reply) } // SetSharedGroup -func (dS *DispatcherReplicatorSv1) SetSharedGroup(args *engine.SharedGroupWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetSharedGroup(args, reply) +func (dS *DispatcherReplicatorSv1) SetSharedGroup(ctx *context.Context, args *engine.SharedGroupWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetSharedGroup(ctx, args, reply) } // SetActions -func (dS *DispatcherReplicatorSv1) SetActions(args *engine.SetActionsArgsWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetActions(args, reply) +func (dS *DispatcherReplicatorSv1) SetActions(ctx *context.Context, args *engine.SetActionsArgsWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetActions(ctx, args, reply) } // SetRatingPlan -func (dS *DispatcherReplicatorSv1) SetRatingPlan(args *engine.RatingPlanWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetRatingPlan(args, reply) +func (dS *DispatcherReplicatorSv1) SetRatingPlan(ctx *context.Context, args *engine.RatingPlanWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetRatingPlan(ctx, args, reply) } // SetRatingProfile -func (dS *DispatcherReplicatorSv1) SetRatingProfile(args *engine.RatingProfileWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetRatingProfile(args, reply) +func (dS *DispatcherReplicatorSv1) SetRatingProfile(ctx *context.Context, args *engine.RatingProfileWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetRatingProfile(ctx, args, reply) } // SetRouteProfile -func (dS *DispatcherReplicatorSv1) SetRouteProfile(args *engine.RouteProfileWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetRouteProfile(args, reply) +func (dS *DispatcherReplicatorSv1) SetRouteProfile(ctx *context.Context, args *engine.RouteProfileWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetRouteProfile(ctx, args, reply) } // SetAttributeProfile -func (dS *DispatcherReplicatorSv1) SetAttributeProfile(args *engine.AttributeProfileWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetAttributeProfile(args, reply) +func (dS *DispatcherReplicatorSv1) SetAttributeProfile(ctx *context.Context, args *engine.AttributeProfileWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetAttributeProfile(ctx, args, reply) } // SetChargerProfile -func (dS *DispatcherReplicatorSv1) SetChargerProfile(args *engine.ChargerProfileWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetChargerProfile(args, reply) +func (dS *DispatcherReplicatorSv1) SetChargerProfile(ctx *context.Context, args *engine.ChargerProfileWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetChargerProfile(ctx, args, reply) } // SetDispatcherProfile -func (dS *DispatcherReplicatorSv1) SetDispatcherProfile(args *engine.DispatcherProfileWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetDispatcherProfile(args, reply) +func (dS *DispatcherReplicatorSv1) SetDispatcherProfile(ctx *context.Context, args *engine.DispatcherProfileWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetDispatcherProfile(ctx, args, reply) } // SetActionPlan -func (dS *DispatcherReplicatorSv1) SetActionPlan(args *engine.SetActionPlanArgWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetActionPlan(args, reply) +func (dS *DispatcherReplicatorSv1) SetActionPlan(ctx *context.Context, args *engine.SetActionPlanArgWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetActionPlan(ctx, args, reply) } // SetAccountActionPlans -func (dS *DispatcherReplicatorSv1) SetAccountActionPlans(args *engine.SetAccountActionPlansArgWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetAccountActionPlans(args, reply) +func (dS *DispatcherReplicatorSv1) SetAccountActionPlans(ctx *context.Context, args *engine.SetAccountActionPlansArgWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetAccountActionPlans(ctx, args, reply) } // SetDispatcherHost -func (dS *DispatcherReplicatorSv1) SetDispatcherHost(args *engine.DispatcherHostWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetDispatcherHost(args, reply) +func (dS *DispatcherReplicatorSv1) SetDispatcherHost(ctx *context.Context, args *engine.DispatcherHostWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetDispatcherHost(ctx, args, reply) } // RemoveThreshold -func (dS *DispatcherReplicatorSv1) RemoveThreshold(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveThreshold(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveThreshold(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveThreshold(ctx, args, reply) } // SetLoadIDs -func (dS *DispatcherReplicatorSv1) SetLoadIDs(args *utils.LoadIDsWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1SetLoadIDs(args, reply) +func (dS *DispatcherReplicatorSv1) SetLoadIDs(ctx *context.Context, args *utils.LoadIDsWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1SetLoadIDs(ctx, args, reply) } // RemoveDestination -func (dS *DispatcherReplicatorSv1) RemoveDestination(args *utils.StringWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveDestination(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveDestination(ctx *context.Context, args *utils.StringWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveDestination(ctx, args, reply) } // RemoveAccount -func (dS *DispatcherReplicatorSv1) RemoveAccount(args *utils.StringWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveAccount(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveAccount(ctx *context.Context, args *utils.StringWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveAccount(ctx, args, reply) } // RemoveStatQueue -func (dS *DispatcherReplicatorSv1) RemoveStatQueue(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveStatQueue(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveStatQueue(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveStatQueue(ctx, args, reply) } // RemoveFilter -func (dS *DispatcherReplicatorSv1) RemoveFilter(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveFilter(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveFilter(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveFilter(ctx, args, reply) } // RemoveThresholdProfile -func (dS *DispatcherReplicatorSv1) RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveThresholdProfile(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveThresholdProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveThresholdProfile(ctx, args, reply) } // RemoveStatQueueProfile -func (dS *DispatcherReplicatorSv1) RemoveStatQueueProfile(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveStatQueueProfile(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveStatQueueProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveStatQueueProfile(ctx, args, reply) } // RemoveTiming -func (dS *DispatcherReplicatorSv1) RemoveTiming(args *utils.StringWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveTiming(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveTiming(ctx *context.Context, args *utils.StringWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveTiming(ctx, args, reply) } // RemoveResource -func (dS *DispatcherReplicatorSv1) RemoveResource(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveResource(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveResource(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveResource(ctx, args, reply) } // RemoveResourceProfile -func (dS *DispatcherReplicatorSv1) RemoveResourceProfile(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveResourceProfile(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveResourceProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveResourceProfile(ctx, args, reply) } // RemoveActionTriggers -func (dS *DispatcherReplicatorSv1) RemoveActionTriggers(args *utils.StringWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveActionTriggers(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveActionTriggers(ctx *context.Context, args *utils.StringWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveActionTriggers(ctx, args, reply) } // RemoveSharedGroup -func (dS *DispatcherReplicatorSv1) RemoveSharedGroup(args *utils.StringWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveSharedGroup(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveSharedGroup(ctx *context.Context, args *utils.StringWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveSharedGroup(ctx, args, reply) } // RemoveActions -func (dS *DispatcherReplicatorSv1) RemoveActions(args *utils.StringWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveActions(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveActions(ctx *context.Context, args *utils.StringWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveActions(ctx, args, reply) } // RemoveActionPlan -func (dS *DispatcherReplicatorSv1) RemoveActionPlan(args *utils.StringWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveActionPlan(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveActionPlan(ctx *context.Context, args *utils.StringWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveActionPlan(ctx, args, reply) } // RemAccountActionPlans -func (dS *DispatcherReplicatorSv1) RemAccountActionPlans(args *engine.RemAccountActionPlansArgsWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemAccountActionPlans(args, reply) +func (dS *DispatcherReplicatorSv1) RemAccountActionPlans(ctx *context.Context, args *engine.RemAccountActionPlansArgsWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemAccountActionPlans(ctx, args, reply) } // RemoveRatingPlan -func (dS *DispatcherReplicatorSv1) RemoveRatingPlan(args *utils.StringWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveRatingPlan(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveRatingPlan(ctx *context.Context, args *utils.StringWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveRatingPlan(ctx, args, reply) } // RemoveRatingProfile -func (dS *DispatcherReplicatorSv1) RemoveRatingProfile(args *utils.StringWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveRatingProfile(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveRatingProfile(ctx *context.Context, args *utils.StringWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveRatingProfile(ctx, args, reply) } // RemoveRouteProfile -func (dS *DispatcherReplicatorSv1) RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveRouteProfile(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveRouteProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveRouteProfile(ctx, args, reply) } // RemoveAttributeProfile -func (dS *DispatcherReplicatorSv1) RemoveAttributeProfile(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveAttributeProfile(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveAttributeProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveAttributeProfile(ctx, args, reply) } // RemoveChargerProfile -func (dS *DispatcherReplicatorSv1) RemoveChargerProfile(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveChargerProfile(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveChargerProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveChargerProfile(ctx, args, reply) } // RemoveDispatcherProfile -func (dS *DispatcherReplicatorSv1) RemoveDispatcherProfile(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveDispatcherProfile(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveDispatcherProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveDispatcherProfile(ctx, args, reply) } // RemoveDispatcherHost -func (dS *DispatcherReplicatorSv1) RemoveDispatcherHost(args *utils.TenantIDWithAPIOpts, reply *string) error { - return dS.dS.ReplicatorSv1RemoveDispatcherHost(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveDispatcherHost(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return dS.dS.ReplicatorSv1RemoveDispatcherHost(ctx, args, reply) } // GetIndexes . -func (dS *DispatcherReplicatorSv1) GetIndexes(args *utils.GetIndexesArg, reply *map[string]utils.StringSet) error { - return dS.dS.ReplicatorSv1GetIndexes(args, reply) +func (dS *DispatcherReplicatorSv1) GetIndexes(ctx *context.Context, args *utils.GetIndexesArg, reply *map[string]utils.StringSet) error { + return dS.dS.ReplicatorSv1GetIndexes(ctx, args, reply) } // SetIndexes . -func (dS *DispatcherReplicatorSv1) SetIndexes(args *utils.SetIndexesArg, reply *string) error { - return dS.dS.ReplicatorSv1SetIndexes(args, reply) +func (dS *DispatcherReplicatorSv1) SetIndexes(ctx *context.Context, args *utils.SetIndexesArg, reply *string) error { + return dS.dS.ReplicatorSv1SetIndexes(ctx, args, reply) } // RemoveIndexes . -func (dS *DispatcherReplicatorSv1) RemoveIndexes(args *utils.GetIndexesArg, reply *string) error { - return dS.dS.ReplicatorSv1RemoveIndexes(args, reply) +func (dS *DispatcherReplicatorSv1) RemoveIndexes(ctx *context.Context, args *utils.GetIndexesArg, reply *string) error { + return dS.dS.ReplicatorSv1RemoveIndexes(ctx, args, reply) } diff --git a/apier/v1/dispatcher_it_test.go b/apier/v1/dispatcher_it_test.go index dbb580b96..a59f1b281 100644 --- a/apier/v1/dispatcher_it_test.go +++ b/apier/v1/dispatcher_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" "os" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ import ( var ( dispatcherCfgPath string dispatcherCfg *config.CGRConfig - dispatcherRPC *rpc.Client + dispatcherRPC *birpc.Client dispatcherProfile *DispatcherWithAPIOpts dispatcherHost *engine.DispatcherHostWithAPIOpts dispatcherConfigDIR string //run tests for specific configuration @@ -152,7 +153,7 @@ func testDispatcherStartCPUProfiling(t *testing.T) { DirPath: "/tmp", } var reply string - if err := dispatcherRPC.Call(utils.CoreSv1StartCPUProfiling, + if err := dispatcherRPC.Call(context.Background(), utils.CoreSv1StartCPUProfiling, argPath, &reply); err != nil { t.Error(err) } @@ -172,13 +173,13 @@ func testDispatcherSSetDispatcherProfile(t *testing.T) { } expErr := "SERVER_ERROR: broken reference to filter: <*wrong:inline> for item with ID: cgrates.org:Dsp1" - if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err == nil || err.Error() != expErr { t.Fatalf("Expected error: %q, received: %v", expErr, err) } - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Error(err) @@ -186,7 +187,7 @@ func testDispatcherSSetDispatcherProfile(t *testing.T) { dispatcherProfile.FilterIDs = []string{"*string:~*req.Account:1001"} - if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil { t.Error(err) @@ -195,7 +196,7 @@ func testDispatcherSSetDispatcherProfile(t *testing.T) { } var dsp *engine.DispatcherProfile - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err != nil { t.Error(err) @@ -207,13 +208,13 @@ func testDispatcherSSetDispatcherProfile(t *testing.T) { func testDispatcherSGetDispatcherProfileIDs(t *testing.T) { var result []string expected := []string{"Dsp1"} - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfileIDs, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil { t.Error(err) } else if len(result) != len(expected) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfileIDs, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{Tenant: dispatcherProfile.Tenant}, &result); err != nil { t.Error(err) } else if len(result) != len(expected) { @@ -233,7 +234,7 @@ func testDispatcherSUpdateDispatcherProfile(t *testing.T) { &engine.DispatcherHostProfile{ID: "HOST1", Weight: 20.0}, &engine.DispatcherHostProfile{ID: "HOST2", Weight: 10.0}, } - if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -241,7 +242,7 @@ func testDispatcherSUpdateDispatcherProfile(t *testing.T) { } var dsp *engine.DispatcherProfile - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err != nil { t.Error(err) @@ -255,7 +256,7 @@ func testDispatcherSGetDispatcherProfileCache(t *testing.T) { t.SkipNow() } var rcvStats map[string]*ltcache.CacheStats - if err := dispatcherRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { + if err := dispatcherRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { t.Error(err) } else if rcvStats[utils.CacheDispatcherProfiles].Items != 1 { t.Errorf("Expecting: 1 DispatcherProfiles, received: %+v", rcvStats[utils.CacheDispatcherProfiles]) @@ -264,7 +265,7 @@ func testDispatcherSGetDispatcherProfileCache(t *testing.T) { func testDispatcherSRemDispatcherProfile(t *testing.T) { var result string - if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &result); err != nil { t.Error(err) @@ -273,13 +274,13 @@ func testDispatcherSRemDispatcherProfile(t *testing.T) { } var dsp *engine.DispatcherProfile - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Error(err) } - if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &result); err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Errorf("Expected error: %v received: %v", utils.ErrDSPProfileNotFound, err) @@ -288,7 +289,7 @@ func testDispatcherSRemDispatcherProfile(t *testing.T) { func testDispatcherSSetDispatcherHost(t *testing.T) { var reply string - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { t.Error(err) @@ -304,7 +305,7 @@ func testDispatcherSSetDispatcherHost(t *testing.T) { }, } - if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1SetDispatcherHost, dispatcherHost, &reply); err != nil { t.Error(err) @@ -313,7 +314,7 @@ func testDispatcherSSetDispatcherHost(t *testing.T) { } var dsp *engine.DispatcherHost - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}, &dsp); err != nil { t.Error(err) @@ -325,13 +326,13 @@ func testDispatcherSSetDispatcherHost(t *testing.T) { func testDispatcherSGetDispatcherHostIDs(t *testing.T) { var result []string expected := []string{"DspHst1"} - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHostIDs, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &result); err != nil { t.Error(err) } else if len(result) != len(expected) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHostIDs, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{Tenant: dispatcherHost.Tenant}, &result); err != nil { t.Error(err) } else if len(result) != len(expected) { @@ -347,7 +348,7 @@ func testDispatcherSUpdateDispatcherHost(t *testing.T) { Transport: utils.MetaGOB, TLS: false, } - if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1SetDispatcherHost, dispatcherHost, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -355,7 +356,7 @@ func testDispatcherSUpdateDispatcherHost(t *testing.T) { } var dsp *engine.DispatcherHost - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}, &dsp); err != nil { t.Error(err) @@ -369,7 +370,7 @@ func testDispatcherSGetDispatcherHostCache(t *testing.T) { t.SkipNow() } var rcvStats map[string]*ltcache.CacheStats - if err := dispatcherRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { + if err := dispatcherRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil { t.Error(err) } else if rcvStats[utils.CacheDispatcherHosts].Items != 0 { t.Errorf("Expecting: 0 DispatcherProfiles, received: %+v", rcvStats[utils.CacheDispatcherHosts]) @@ -378,7 +379,7 @@ func testDispatcherSGetDispatcherHostCache(t *testing.T) { func testDispatcherSRemDispatcherHost(t *testing.T) { var result string - if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherHost, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}}, &result); err != nil { t.Error(err) @@ -387,13 +388,13 @@ func testDispatcherSRemDispatcherHost(t *testing.T) { } var dsp *engine.DispatcherHost - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}, &dsp); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { t.Error(err) } - if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherHost, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}}, &result); err.Error() != utils.ErrDSPHostNotFound.Error() { t.Errorf("Expected error: %v received: %v", utils.ErrDSPHostNotFound, err) @@ -403,7 +404,7 @@ func testDispatcherSRemDispatcherHost(t *testing.T) { func testV1DispatcherStopCPUProfiling(t *testing.T) { argPath := "/tmp/cpu.prof" var reply string - if err := dispatcherRPC.Call(utils.CoreSv1StopCPUProfiling, + if err := dispatcherRPC.Call(context.Background(), utils.CoreSv1StopCPUProfiling, new(utils.DirectoryArgs), &reply); err != nil { t.Error(err) } @@ -443,14 +444,14 @@ func testDispatcherSSetDispatcherProfileWithoutTenant(t *testing.T) { }, } var reply string - if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil { + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } dispatcherProfile.DispatcherProfile.Tenant = "cgrates.org" var result *engine.DispatcherProfile - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{ID: "Dsp1"}, &result); err != nil { t.Error(err) @@ -461,7 +462,7 @@ func testDispatcherSSetDispatcherProfileWithoutTenant(t *testing.T) { func testDispatcherSRemDispatcherProfileWithoutTenant(t *testing.T) { var reply string - if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "Dsp1"}}, &reply); err != nil { t.Error(err) @@ -469,7 +470,7 @@ func testDispatcherSRemDispatcherProfileWithoutTenant(t *testing.T) { t.Error("Unexpected reply returned", reply) } var result *engine.DispatcherProfile - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{ID: "Dsp1"}, &result); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Error(err) @@ -486,14 +487,14 @@ func testDispatcherSSetDispatcherHostWithoutTenant(t *testing.T) { }, } var reply string - if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherHost, dispatcherHost, &reply); err != nil { + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1SetDispatcherHost, dispatcherHost, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } dispatcherHost.DispatcherHost.Tenant = "cgrates.org" var result *engine.DispatcherHost - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{ID: "DspHst7"}, &result); err != nil { t.Error(err) @@ -504,7 +505,7 @@ func testDispatcherSSetDispatcherHostWithoutTenant(t *testing.T) { func testDispatcherSRemDispatcherHostWithoutTenant(t *testing.T) { var reply string - if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherHost, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "DspHst7"}}, &reply); err != nil { t.Error(err) @@ -512,7 +513,7 @@ func testDispatcherSRemDispatcherHostWithoutTenant(t *testing.T) { t.Error("Unexpected reply returned", reply) } var result *engine.DispatcherHost - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{ID: "DspHst7"}, &result); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { t.Error(err) @@ -521,7 +522,7 @@ func testDispatcherSRemDispatcherHostWithoutTenant(t *testing.T) { func testDispatcherSCacheTestGetNotFound(t *testing.T) { var suplsReply *engine.DispatcherProfile - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{ Tenant: "cgrates.org", ID: "DISPATCHER_CACHE", @@ -532,7 +533,7 @@ func testDispatcherSCacheTestGetNotFound(t *testing.T) { func testDispatcherSCacheTestGetFound(t *testing.T) { var suplsReply *engine.DispatcherProfile - if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{ Tenant: "cgrates.org", ID: "DISPATCHER_CACHE", @@ -553,7 +554,7 @@ func testDispatcherSCacheTestSet(t *testing.T) { utils.CacheOpt: utils.MetaNone, }, } - if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherProfile, + if err := dispatcherRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil { t.Error(err) @@ -568,7 +569,7 @@ func testDispatcherSCacheReload(t *testing.T) { DispatcherProfileIDs: []string{"cgrates.org:DISPATCHER_CACHE"}, } var reply string - if err := dispatcherRPC.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil { + if err := dispatcherRPC.Call(context.Background(), utils.CacheSv1ReloadCache, cache, &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Error("Calling CacheSv1.ReloadCache got reply: ", reply) diff --git a/apier/v1/dispatchersv1_it_test.go b/apier/v1/dispatchersv1_it_test.go index 98770d354..3f9608d23 100644 --- a/apier/v1/dispatchersv1_it_test.go +++ b/apier/v1/dispatchersv1_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" "os/exec" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( dspCfgPath string dspCfg *config.CGRConfig - dspRPC *rpc.Client + dspRPC *birpc.Client sTestsDspDspv1 = []func(t *testing.T){ testDspITLoadConfig, @@ -173,7 +174,7 @@ func testDspDspv1GetProfileForEvent(t *testing.T) { expected.Hosts[1].FilterIDs = nil } expected.Hosts.Sort() - if err := dspRPC.Call(utils.DispatcherSv1GetProfilesForEvent, &arg, &reply); err != nil { + if err := dspRPC.Call(context.Background(), utils.DispatcherSv1GetProfilesForEvent, &arg, &reply); err != nil { t.Fatal(err) } else if len(reply) != 1 { t.Fatalf("Unexpected number of profiles:%v", len(reply)) @@ -194,7 +195,7 @@ func testDspDspv1GetProfileForEvent(t *testing.T) { }, } expected.Hosts.Sort() - if err := dspRPC.Call(utils.DispatcherSv1GetProfilesForEvent, &arg2, &reply); err != nil { + if err := dspRPC.Call(context.Background(), utils.DispatcherSv1GetProfilesForEvent, &arg2, &reply); err != nil { t.Fatal(err) } else if len(reply) != 1 { t.Fatalf("Unexpected number of profiles:%v", len(reply)) @@ -238,7 +239,7 @@ func testDspDspv1GetProfileForEventWithMethod(t *testing.T) { expected.Hosts[0].FilterIDs = nil } expected.Hosts.Sort() - if err := dspRPC.Call(utils.DispatcherSv1GetProfilesForEvent, &arg, &reply); err != nil { + if err := dspRPC.Call(context.Background(), utils.DispatcherSv1GetProfilesForEvent, &arg, &reply); err != nil { t.Fatal(err) } else if len(reply) != 1 { t.Error(utils.ToJSON(reply)) diff --git a/apier/v1/ees.go b/apier/v1/ees.go index 9ba9b4d41..91a44d0c1 100644 --- a/apier/v1/ees.go +++ b/apier/v1/ees.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/ees" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -32,13 +33,13 @@ type EeSv1 struct { eeS *ees.EventExporterS } -func (eeSv1 *EeSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (eeSv1 *EeSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } // ProcessEvent triggers exports on EEs side -func (eeSv1 *EeSv1) ProcessEvent(args *engine.CGREventWithEeIDs, +func (eeSv1 *EeSv1) ProcessEvent(ctx *context.Context, args *engine.CGREventWithEeIDs, reply *map[string]map[string]any) error { - return eeSv1.eeS.V1ProcessEvent(args, reply) + return eeSv1.eeS.V1ProcessEvent(ctx, args, reply) } diff --git a/apier/v1/ees_it_test.go b/apier/v1/ees_it_test.go index 03f8899b5..2f7730cff 100644 --- a/apier/v1/ees_it_test.go +++ b/apier/v1/ees_it_test.go @@ -22,7 +22,6 @@ along with this program. If not, see package v1 import ( - "net/rpc" "os" "path" "path/filepath" @@ -30,6 +29,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ import ( var ( eeSCfgPath string eeSCfg *config.CGRConfig - eeSRPC *rpc.Client + eeSRPC *birpc.Client eeSConfigDIR string //run tests for specific configuration sTestsEEs = []func(t *testing.T){ @@ -138,7 +139,7 @@ func testEEsAddCDRs(t *testing.T) { }, } var result string - if err := eeSRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := eeSRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -175,7 +176,7 @@ func testEEsAddCDRs(t *testing.T) { } for _, cdr := range storedCdrs { var reply string - if err := eeSRPC.Call(utils.CDRsV1ProcessCDR, &engine.CDRWithAPIOpts{CDR: cdr}, &reply); err != nil { + if err := eeSRPC.Call(context.Background(), utils.CDRsV1ProcessCDR, &engine.CDRWithAPIOpts{CDR: cdr}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -189,7 +190,7 @@ func testEEsExportCDRs(t *testing.T) { Verbose: true, } var rply map[string]any - if err := eeSRPC.Call(utils.APIerSv1ExportCDRs, &attr, &rply); err != nil { + if err := eeSRPC.Call(context.Background(), utils.APIerSv1ExportCDRs, &attr, &rply); err != nil { t.Error("Unexpected error: ", err.Error()) } if len(rply) != 1 { @@ -252,7 +253,7 @@ func testEEsExportCDRsMultipleExporters(t *testing.T) { Verbose: true, } var rply map[string]any - if err := eeSRPC.Call(utils.APIerSv1ExportCDRs, &attr, &rply); err != nil { + if err := eeSRPC.Call(context.Background(), utils.APIerSv1ExportCDRs, &attr, &rply); err != nil { t.Error("Unexpected error: ", err.Error()) } if len(rply) != 2 { diff --git a/apier/v1/filter_indexes.go b/apier/v1/filter_indexes.go index 6e87ae6b0..4d8982058 100644 --- a/apier/v1/filter_indexes.go +++ b/apier/v1/filter_indexes.go @@ -22,6 +22,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" @@ -44,7 +45,7 @@ type AttrRemFilterIndexes struct { APIOpts map[string]any } -func (apierSv1 *APIerSv1) RemoveFilterIndexes(arg *AttrRemFilterIndexes, reply *string) (err error) { +func (apierSv1 *APIerSv1) RemoveFilterIndexes(ctx *context.Context, arg *AttrRemFilterIndexes, reply *string) (err error) { if missing := utils.MissingStructFields(arg, []string{"ItemType"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -92,7 +93,7 @@ func (apierSv1 *APIerSv1) RemoveFilterIndexes(arg *AttrRemFilterIndexes, reply * return } -func (apierSv1 *APIerSv1) GetFilterIndexes(arg *AttrGetFilterIndexes, reply *[]string) (err error) { +func (apierSv1 *APIerSv1) GetFilterIndexes(ctx *context.Context, arg *AttrGetFilterIndexes, reply *[]string) (err error) { var indexes map[string]utils.StringSet var indexedSlice []string indexesFilter := make(map[string]utils.StringSet) @@ -217,7 +218,7 @@ func (apierSv1 *APIerSv1) GetFilterIndexes(arg *AttrGetFilterIndexes, reply *[]s } // ComputeFilterIndexes selects which index filters to recompute -func (apierSv1 *APIerSv1) ComputeFilterIndexes(args *utils.ArgsComputeFilterIndexes, reply *string) (err error) { +func (apierSv1 *APIerSv1) ComputeFilterIndexes(ctx *context.Context, args *utils.ArgsComputeFilterIndexes, reply *string) (err error) { transactionID := utils.GenUUID() tnt := args.Tenant if tnt == utils.EmptyString { @@ -433,7 +434,7 @@ func (apierSv1 *APIerSv1) ComputeFilterIndexes(args *utils.ArgsComputeFilterInde } // ComputeFilterIndexIDs computes specific filter indexes -func (apierSv1 *APIerSv1) ComputeFilterIndexIDs(args *utils.ArgsComputeFilterIndexIDs, reply *string) (err error) { +func (apierSv1 *APIerSv1) ComputeFilterIndexIDs(ctx *context.Context, args *utils.ArgsComputeFilterIndexIDs, reply *string) (err error) { transactionID := utils.NonTransactional tnt := args.Tenant if tnt == utils.EmptyString { @@ -595,7 +596,7 @@ func (apierSv1 *APIerSv1) ComputeFilterIndexIDs(args *utils.ArgsComputeFilterInd return nil } -func (apierSv1 *APIerSv1) GetAccountActionPlansIndexHealth(args *engine.IndexHealthArgsWith2Ch, reply *engine.AccountActionPlanIHReply) error { +func (apierSv1 *APIerSv1) GetAccountActionPlansIndexHealth(ctx *context.Context, args *engine.IndexHealthArgsWith2Ch, reply *engine.AccountActionPlanIHReply) error { rp, err := engine.GetAccountActionPlansIndexHealth(apierSv1.DataManager, args.ObjectCacheLimit, args.IndexCacheLimit, args.ObjectCacheTTL, args.IndexCacheTTL, args.ObjectCacheStaticTTL, args.IndexCacheStaticTTL) @@ -606,7 +607,7 @@ func (apierSv1 *APIerSv1) GetAccountActionPlansIndexHealth(args *engine.IndexHea return nil } -func (apierSv1 *APIerSv1) GetReverseDestinationsIndexHealth(args *engine.IndexHealthArgsWith2Ch, reply *engine.ReverseDestinationsIHReply) error { +func (apierSv1 *APIerSv1) GetReverseDestinationsIndexHealth(ctx *context.Context, args *engine.IndexHealthArgsWith2Ch, reply *engine.ReverseDestinationsIHReply) error { rp, err := engine.GetReverseDestinationsIndexHealth(apierSv1.DataManager, args.ObjectCacheLimit, args.IndexCacheLimit, args.ObjectCacheTTL, args.IndexCacheTTL, args.ObjectCacheStaticTTL, args.IndexCacheStaticTTL) @@ -617,7 +618,7 @@ func (apierSv1 *APIerSv1) GetReverseDestinationsIndexHealth(args *engine.IndexHe return nil } -func (apierSv1 *APIerSv1) GetReverseFilterHealth(args *engine.IndexHealthArgsWith3Ch, reply *map[string]*engine.ReverseFilterIHReply) (err error) { +func (apierSv1 *APIerSv1) GetReverseFilterHealth(ctx *context.Context, args *engine.IndexHealthArgsWith3Ch, reply *map[string]*engine.ReverseFilterIHReply) (err error) { objCaches := make(map[string]*ltcache.Cache) for indxType := range utils.CacheIndexesToPrefix { objCaches[indxType] = ltcache.NewCache(-1, 0, false, nil) @@ -630,7 +631,7 @@ func (apierSv1 *APIerSv1) GetReverseFilterHealth(args *engine.IndexHealthArgsWit return } -func (apierSv1 *APIerSv1) GetThresholdsIndexesHealth(args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { +func (apierSv1 *APIerSv1) GetThresholdsIndexesHealth(ctx *context.Context, args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { rp, err := engine.GetFltrIdxHealth(apierSv1.DataManager, ltcache.NewCache(args.FilterCacheLimit, args.FilterCacheTTL, args.FilterCacheStaticTTL, nil), ltcache.NewCache(args.IndexCacheLimit, args.IndexCacheTTL, args.IndexCacheStaticTTL, nil), @@ -644,7 +645,7 @@ func (apierSv1 *APIerSv1) GetThresholdsIndexesHealth(args *engine.IndexHealthArg return nil } -func (apierSv1 *APIerSv1) GetResourcesIndexesHealth(args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { +func (apierSv1 *APIerSv1) GetResourcesIndexesHealth(ctx *context.Context, args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { rp, err := engine.GetFltrIdxHealth(apierSv1.DataManager, ltcache.NewCache(args.FilterCacheLimit, args.FilterCacheTTL, args.FilterCacheStaticTTL, nil), ltcache.NewCache(args.IndexCacheLimit, args.IndexCacheTTL, args.IndexCacheStaticTTL, nil), @@ -658,7 +659,7 @@ func (apierSv1 *APIerSv1) GetResourcesIndexesHealth(args *engine.IndexHealthArgs return nil } -func (apierSv1 *APIerSv1) GetStatsIndexesHealth(args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { +func (apierSv1 *APIerSv1) GetStatsIndexesHealth(ctx *context.Context, args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { rp, err := engine.GetFltrIdxHealth(apierSv1.DataManager, ltcache.NewCache(args.FilterCacheLimit, args.FilterCacheTTL, args.FilterCacheStaticTTL, nil), ltcache.NewCache(args.IndexCacheLimit, args.IndexCacheTTL, args.IndexCacheStaticTTL, nil), @@ -672,7 +673,7 @@ func (apierSv1 *APIerSv1) GetStatsIndexesHealth(args *engine.IndexHealthArgsWith return nil } -func (apierSv1 *APIerSv1) GetRoutesIndexesHealth(args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { +func (apierSv1 *APIerSv1) GetRoutesIndexesHealth(ctx *context.Context, args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { rp, err := engine.GetFltrIdxHealth(apierSv1.DataManager, ltcache.NewCache(args.FilterCacheLimit, args.FilterCacheTTL, args.FilterCacheStaticTTL, nil), ltcache.NewCache(args.IndexCacheLimit, args.IndexCacheTTL, args.IndexCacheStaticTTL, nil), @@ -686,7 +687,7 @@ func (apierSv1 *APIerSv1) GetRoutesIndexesHealth(args *engine.IndexHealthArgsWit return nil } -func (apierSv1 *APIerSv1) GetAttributesIndexesHealth(args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { +func (apierSv1 *APIerSv1) GetAttributesIndexesHealth(ctx *context.Context, args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { rp, err := engine.GetFltrIdxHealth(apierSv1.DataManager, ltcache.NewCache(args.FilterCacheLimit, args.FilterCacheTTL, args.FilterCacheStaticTTL, nil), ltcache.NewCache(args.IndexCacheLimit, args.IndexCacheTTL, args.IndexCacheStaticTTL, nil), @@ -700,7 +701,7 @@ func (apierSv1 *APIerSv1) GetAttributesIndexesHealth(args *engine.IndexHealthArg return nil } -func (apierSv1 *APIerSv1) GetChargersIndexesHealth(args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { +func (apierSv1 *APIerSv1) GetChargersIndexesHealth(ctx *context.Context, args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { rp, err := engine.GetFltrIdxHealth(apierSv1.DataManager, ltcache.NewCache(args.FilterCacheLimit, args.FilterCacheTTL, args.FilterCacheStaticTTL, nil), ltcache.NewCache(args.IndexCacheLimit, args.IndexCacheTTL, args.IndexCacheStaticTTL, nil), @@ -714,7 +715,7 @@ func (apierSv1 *APIerSv1) GetChargersIndexesHealth(args *engine.IndexHealthArgsW return nil } -func (apierSv1 *APIerSv1) GetDispatchersIndexesHealth(args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { +func (apierSv1 *APIerSv1) GetDispatchersIndexesHealth(ctx *context.Context, args *engine.IndexHealthArgsWith3Ch, reply *engine.FilterIHReply) error { rp, err := engine.GetFltrIdxHealth(apierSv1.DataManager, ltcache.NewCache(args.FilterCacheLimit, args.FilterCacheTTL, args.FilterCacheStaticTTL, nil), ltcache.NewCache(args.IndexCacheLimit, args.IndexCacheTTL, args.IndexCacheStaticTTL, nil), diff --git a/apier/v1/filter_indexes_health_it_test.go b/apier/v1/filter_indexes_health_it_test.go index e64372b6c..76d3eb6ea 100644 --- a/apier/v1/filter_indexes_health_it_test.go +++ b/apier/v1/filter_indexes_health_it_test.go @@ -21,20 +21,21 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) var ( - tFIdxHRpc *rpc.Client + tFIdxHRpc *birpc.Client tSv1InternalRestart bool sTestsFilterIndexesSHealth = []func(t *testing.T){ @@ -132,7 +133,7 @@ func testV1FIdxHRpcConn(t *testing.T) { func testV1FIdxHLoadFromFolderTutorial2(t *testing.T) { var reply string - if err := tFIdxHRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := tFIdxHRpc.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ CacheIDs: nil, }, &reply); err != nil { t.Error(err) @@ -140,7 +141,7 @@ func testV1FIdxHLoadFromFolderTutorial2(t *testing.T) { t.Error("Reply: ", reply) } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial2")} - if err := tFIdxHRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -148,7 +149,7 @@ func testV1FIdxHLoadFromFolderTutorial2(t *testing.T) { func testV1FIdxHAccountActionPlansHealth(t *testing.T) { var reply engine.AccountActionPlanIHReply - if err := tFIdxHRpc.Call(utils.APIerSv1GetAccountActionPlansIndexHealth, engine.IndexHealthArgsWith2Ch{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetAccountActionPlansIndexHealth, engine.IndexHealthArgsWith2Ch{ IndexCacheLimit: -1, ObjectCacheLimit: -1, }, &reply); err != nil { @@ -165,7 +166,7 @@ func testV1FIdxHAccountActionPlansHealth(t *testing.T) { func testV1FIdxHReverseDestinationHealth(t *testing.T) { var reply engine.ReverseDestinationsIHReply - if err := tFIdxHRpc.Call(utils.APIerSv1GetReverseDestinationsIndexHealth, engine.IndexHealthArgsWith2Ch{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetReverseDestinationsIndexHealth, engine.IndexHealthArgsWith2Ch{ IndexCacheLimit: -1, ObjectCacheLimit: -1, }, &reply); err != nil { @@ -182,7 +183,7 @@ func testV1FIdxHReverseDestinationHealth(t *testing.T) { func testV1FIdxHLoadFromFolderTutorial(t *testing.T) { var reply string - if err := tFIdxHRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := tFIdxHRpc.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ CacheIDs: nil, }, &reply); err != nil { t.Error(err) @@ -190,7 +191,7 @@ func testV1FIdxHLoadFromFolderTutorial(t *testing.T) { t.Error("Reply: ", reply) } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := tFIdxHRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -201,7 +202,7 @@ func testV1FIdxGetReverseFilterHealth(t *testing.T) { args := &engine.IndexHealthArgsWith3Ch{} expRPly := map[string]*engine.ReverseFilterIHReply{} var rply map[string]*engine.ReverseFilterIHReply - if err := tFIdxHRpc.Call(utils.APIerSv1GetReverseFilterHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetReverseFilterHealth, args, &rply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rply, expRPly) { @@ -227,7 +228,7 @@ func testV1FIdxGetThresholdsIndexesHealth(t *testing.T) { } var rplyok string - if err := tFIdxHRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &rplyok); err != nil { + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &rplyok); err != nil { t.Error(err) } else if rplyok != utils.OK { t.Error("Unexpected reply returned", rplyok) @@ -242,7 +243,7 @@ func testV1FIdxGetThresholdsIndexesHealth(t *testing.T) { "*prefix:*opts.Destination:+554:TEST_PROFILE1", } var result []string - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, //Tenant: "cgrates.org", }, &result); err != nil { @@ -264,7 +265,7 @@ func testV1FIdxGetThresholdsIndexesHealth(t *testing.T) { MissingFilters: map[string][]string{}, } var rply *engine.FilterIHReply - if err := tFIdxHRpc.Call(utils.APIerSv1GetThresholdsIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetThresholdsIndexesHealth, args, &rply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rply, expRPly) { @@ -272,7 +273,7 @@ func testV1FIdxGetThresholdsIndexesHealth(t *testing.T) { } // removing a profile + their indexes - if err := tFIdxHRpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: "cgrates.org", @@ -291,7 +292,7 @@ func testV1FIdxGetThresholdsIndexesHealth(t *testing.T) { "*prefix:*opts.Destination:+442:TEST_PROFILE1", "*prefix:*opts.Destination:+554:TEST_PROFILE1", } - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, }, &result); err != nil { t.Error(err) @@ -309,7 +310,7 @@ func testV1FIdxGetThresholdsIndexesHealth(t *testing.T) { BrokenIndexes: map[string][]string{}, MissingFilters: map[string][]string{}, } - if err := tFIdxHRpc.Call(utils.APIerSv1GetThresholdsIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetThresholdsIndexesHealth, args, &rply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rply, expRPly) { @@ -337,7 +338,7 @@ func testV1FIdxGetResourcesIndexesHealth(t *testing.T) { ThresholdIDs: []string{utils.MetaNone}, }, } - if err := tFIdxHRpc.Call(utils.APIerSv1SetResourceProfile, rlsPrf, &reply); err != nil { + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsPrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -353,7 +354,7 @@ func testV1FIdxGetResourcesIndexesHealth(t *testing.T) { "*string:*req.Account:1003:ResGroup1", } var result []string - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaResources, }, &result); err != nil { t.Error(err) @@ -374,7 +375,7 @@ func testV1FIdxGetResourcesIndexesHealth(t *testing.T) { } args := &engine.IndexHealthArgsWith3Ch{} var rply *engine.FilterIHReply - if err := tFIdxHRpc.Call(utils.APIerSv1GetResourcesIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetResourcesIndexesHealth, args, &rply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rply, expRPly) { @@ -382,7 +383,7 @@ func testV1FIdxGetResourcesIndexesHealth(t *testing.T) { } // removing a profile + their indexes - if err := tFIdxHRpc.Call(utils.APIerSv1RemoveResourceProfile, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1RemoveResourceProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: "cgrates.org", @@ -395,7 +396,7 @@ func testV1FIdxGetResourcesIndexesHealth(t *testing.T) { } //as we removed the object, the index specified is removed too, so the health of the indexes is fine - if err := tFIdxHRpc.Call(utils.APIerSv1GetResourcesIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetResourcesIndexesHealth, args, &rply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rply, expRPly) { @@ -426,7 +427,7 @@ func testV1FIdxGetStatsIndexesHealth(t *testing.T) { }, } var rply string - if err := tFIdxHRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &rply); err != nil { + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &rply); err != nil { t.Error(err) } else if rply != utils.OK { t.Error("Unexpected reply returned", rply) @@ -448,7 +449,7 @@ func testV1FIdxGetStatsIndexesHealth(t *testing.T) { "*string:*req.Destination:1001:Stats2_1", } var result []string - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaStats, }, &result); err != nil { t.Error(err) @@ -469,7 +470,7 @@ func testV1FIdxGetStatsIndexesHealth(t *testing.T) { } args := &engine.IndexHealthArgsWith3Ch{} var rplyFl *engine.FilterIHReply - if err := tFIdxHRpc.Call(utils.APIerSv1GetStatsIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetStatsIndexesHealth, args, &rplyFl); err != nil { t.Error(err) } else if !reflect.DeepEqual(rplyFl, expRPly) { @@ -477,7 +478,7 @@ func testV1FIdxGetStatsIndexesHealth(t *testing.T) { } // removing a profile + their indexes - if err := tFIdxHRpc.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: "cgrates.org", @@ -490,7 +491,7 @@ func testV1FIdxGetStatsIndexesHealth(t *testing.T) { } //as we removed the object, the index specified is removed too, so the health of the indexes is fine - if err := tFIdxHRpc.Call(utils.APIerSv1GetStatsIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetStatsIndexesHealth, args, &rplyFl); err != nil { t.Error(err) } else if !reflect.DeepEqual(rplyFl, expRPly) { @@ -518,7 +519,7 @@ func testV1FIdxGetRoutesIndexesHealth(t *testing.T) { }, } var reply string - if err := tFIdxHRpc.Call(utils.APIerSv1SetRouteProfile, rPrf, &reply); err != nil { + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, rPrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -532,7 +533,7 @@ func testV1FIdxGetRoutesIndexesHealth(t *testing.T) { "*string:*req.Account:1003:ROUTE_ACNT_1003", } var result []string - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaRoutes, }, &result); err != nil { t.Error(err) @@ -553,7 +554,7 @@ func testV1FIdxGetRoutesIndexesHealth(t *testing.T) { } args := &engine.IndexHealthArgsWith3Ch{} var rplyFl *engine.FilterIHReply - if err := tFIdxHRpc.Call(utils.APIerSv1GetRoutesIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetRoutesIndexesHealth, args, &rplyFl); err != nil { t.Error(err) } else if !reflect.DeepEqual(rplyFl, expRPly) { @@ -561,7 +562,7 @@ func testV1FIdxGetRoutesIndexesHealth(t *testing.T) { } // removing a profile + their indexes - if err := tFIdxHRpc.Call(utils.APIerSv1RemoveRouteProfile, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1RemoveRouteProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: "cgrates.org", @@ -574,7 +575,7 @@ func testV1FIdxGetRoutesIndexesHealth(t *testing.T) { } //as we removed the object, the index specified is removed too, so the health of the indexes is fine - if err := tFIdxHRpc.Call(utils.APIerSv1GetRoutesIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetRoutesIndexesHealth, args, &rplyFl); err != nil { t.Error(err) } else if !reflect.DeepEqual(rplyFl, expRPly) { @@ -596,7 +597,7 @@ func testV1FIdxGetChargersIndexesHealth(t *testing.T) { }, } var reply string - if err := tFIdxHRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -611,7 +612,7 @@ func testV1FIdxGetChargersIndexesHealth(t *testing.T) { "*none:*any:*any:Raw", } var result []string - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaChargers, }, &result); err != nil { t.Error(err) @@ -632,7 +633,7 @@ func testV1FIdxGetChargersIndexesHealth(t *testing.T) { } args := &engine.IndexHealthArgsWith3Ch{} var rplyFl *engine.FilterIHReply - if err := tFIdxHRpc.Call(utils.APIerSv1GetChargersIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetChargersIndexesHealth, args, &rplyFl); err != nil { t.Error(err) } else if !reflect.DeepEqual(rplyFl, expRPly) { @@ -640,7 +641,7 @@ func testV1FIdxGetChargersIndexesHealth(t *testing.T) { } // removing a profile + their indexes - if err := tFIdxHRpc.Call(utils.APIerSv1RemoveChargerProfile, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1RemoveChargerProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: "cgrates.org", @@ -653,7 +654,7 @@ func testV1FIdxGetChargersIndexesHealth(t *testing.T) { } //as we removed the object, the index specified is removed too, so the health of the indexes is fine - if err := tFIdxHRpc.Call(utils.APIerSv1GetRoutesIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetRoutesIndexesHealth, args, &rplyFl); err != nil { t.Error(err) } else if !reflect.DeepEqual(rplyFl, expRPly) { @@ -671,7 +672,7 @@ func testV1FIdxGetAttributesIndexesHealth(t *testing.T) { "*string:*req.Account:1003:ATTR_1003_SIMPLEAUTH", } var result []string - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Context: "simpleauth", }, &result); err != nil { @@ -690,7 +691,7 @@ func testV1FIdxGetAttributesIndexesHealth(t *testing.T) { "*string:*req.Account:1002:ATTR_1002_SESSIONAUTH", "*string:*req.Account:1003:ATTR_1003_SESSIONAUTH", } - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Context: utils.MetaSessionS, }, &result); err != nil { @@ -707,7 +708,7 @@ func testV1FIdxGetAttributesIndexesHealth(t *testing.T) { expIdx = []string{ "*string:*req.SubscriberId:1006:ATTR_ACC_ALIAS", } - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Context: utils.MetaAny, }, &result); err != nil { @@ -727,7 +728,7 @@ func testV1FIdxGetAttributesIndexesHealth(t *testing.T) { "*string:*req.Account:testDiamInitWithSessionDisconnect:ATTR_TNT_DISC", "*string:*req.SubscriberId:testDiamItEmulateTerminate:ATTR_ACC_EMULATE_TERMINATE", } - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.com", ItemType: utils.MetaAttributes, Context: utils.MetaAny, @@ -750,7 +751,7 @@ func testV1FIdxGetAttributesIndexesHealth(t *testing.T) { } args := &engine.IndexHealthArgsWith3Ch{} var rplyFl *engine.FilterIHReply - if err := tFIdxHRpc.Call(utils.APIerSv1GetAttributesIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetAttributesIndexesHealth, args, &rplyFl); err != nil { t.Error(err) } else if !reflect.DeepEqual(rplyFl, expRPly) { @@ -761,7 +762,7 @@ func testV1FIdxGetAttributesIndexesHealth(t *testing.T) { func testV1FIdxHLoadFromFolderDispatchers(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "dispatchers")} - if err := tFIdxHRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -781,7 +782,7 @@ func testV1FIdxHGetDispatchersIndexesHealth(t *testing.T) { "*string:*opts.EventType:LoadDispatcher:EVENT7", } var result []string - if err := tFIdxHRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaDispatchers, Context: utils.MetaAny, }, &result); err != nil { @@ -803,7 +804,7 @@ func testV1FIdxHGetDispatchersIndexesHealth(t *testing.T) { } args := &engine.IndexHealthArgsWith3Ch{} var rplyFl *engine.FilterIHReply - if err := tFIdxHRpc.Call(utils.APIerSv1GetDispatchersIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetDispatchersIndexesHealth, args, &rplyFl); err != nil { t.Error(err) } else if !reflect.DeepEqual(rplyFl, expRPly) { @@ -812,7 +813,7 @@ func testV1FIdxHGetDispatchersIndexesHealth(t *testing.T) { var reply string // removing a profile + their indexes - if err := tFIdxHRpc.Call(utils.APIerSv1RemoveDispatcherProfile, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1RemoveDispatcherProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: "cgrates.org", @@ -826,7 +827,7 @@ func testV1FIdxHGetDispatchersIndexesHealth(t *testing.T) { //as we removed the object, the index specified is removed too, so the health of the indexes is fine args = &engine.IndexHealthArgsWith3Ch{} - if err := tFIdxHRpc.Call(utils.APIerSv1GetDispatchersIndexesHealth, + if err := tFIdxHRpc.Call(context.Background(), utils.APIerSv1GetDispatchersIndexesHealth, args, &rplyFl); err != nil { t.Error(err) } else if !reflect.DeepEqual(rplyFl, expRPly) { diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go index ab0050cd1..bc439a560 100644 --- a/apier/v1/filter_indexes_it_test.go +++ b/apier/v1/filter_indexes_it_test.go @@ -21,13 +21,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ const ( ) var ( - tFIdxRpc *rpc.Client + tFIdxRpc *birpc.Client sTestsFilterIndexesSV1 = []func(t *testing.T){ testV1FIdxLoadConfig, @@ -158,7 +159,7 @@ func testV1FIdxdxInitDataDb(t *testing.T) { func testV1IndexClearCache(t *testing.T) { var reply string - if err := tFIdxRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil { t.Fatal(err) } } @@ -199,12 +200,12 @@ func testV1FIdxSetThresholdProfile(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -222,12 +223,12 @@ func testV1FIdxSetThresholdProfile(t *testing.T) { Async: true, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { @@ -236,7 +237,7 @@ func testV1FIdxSetThresholdProfile(t *testing.T) { var indexes []string expectedIdx := []string{"*string:*req.Account:1001:TEST_PROFILE1"} - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -255,7 +256,7 @@ func testV1FIdxSetThresholdProfile(t *testing.T) { }}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -264,7 +265,7 @@ func testV1FIdxSetThresholdProfile(t *testing.T) { expectedIdx = []string{"*string:*req.Account:1006:TEST_PROFILE1", "*string:*req.Account:1009:TEST_PROFILE1"} sort.Strings(expectedIdx) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -286,20 +287,20 @@ func testV1FIdxSetThresholdProfile(t *testing.T) { }}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: tenant}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -309,7 +310,7 @@ func testV1FIdxSetThresholdProfile(t *testing.T) { func testV1FIdxComputeThresholdsIndexes(t *testing.T) { var reply2 string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, ThresholdS: true, @@ -321,7 +322,7 @@ func testV1FIdxComputeThresholdsIndexes(t *testing.T) { } expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE1"} var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -350,12 +351,12 @@ func testV1FIdxSetSecondThresholdProfile(t *testing.T) { } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -377,25 +378,25 @@ func testV1FIdxSetSecondThresholdProfile(t *testing.T) { Async: true, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: tenant}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -405,7 +406,7 @@ func testV1FIdxSetSecondThresholdProfile(t *testing.T) { func testV1FIdxSecondComputeThresholdsIndexes(t *testing.T) { thid := []string{"TEST_PROFILE2"} var result string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexIDs, &utils.ArgsComputeFilterIndexIDs{ Tenant: tenant, ThresholdIDs: thid, @@ -417,7 +418,7 @@ func testV1FIdxSecondComputeThresholdsIndexes(t *testing.T) { } expectedIDX := []string{"*string:*req.Account:1002:TEST_PROFILE2"} var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -429,7 +430,7 @@ func testV1FIdxSecondComputeThresholdsIndexes(t *testing.T) { func testV1FIdxThirdComputeThresholdsIndexes(t *testing.T) { var result string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, ThresholdS: true, }, &result); err != nil { @@ -442,7 +443,7 @@ func testV1FIdxThirdComputeThresholdsIndexes(t *testing.T) { "*string:*req.Account:1002:TEST_PROFILE2"} sort.Strings(expectedIDX) var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -456,7 +457,7 @@ func testV1FIdxThirdComputeThresholdsIndexes(t *testing.T) { func testV1FIdxRemoveThresholdProfile(t *testing.T) { var result string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, ThresholdS: true, }, &result); err != nil { @@ -465,31 +466,31 @@ func testV1FIdxRemoveThresholdProfile(t *testing.T) { if result != utils.OK { t.Errorf("Error: %+v", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var sqp *engine.ThresholdProfile - if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -511,12 +512,12 @@ func testV1FIdxSetStatQueueProfileIndexes(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -543,12 +544,12 @@ func testV1FIdxSetStatQueueProfileIndexes(t *testing.T) { MinItems: 1, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -567,7 +568,7 @@ func testV1FIdxSetStatQueueProfileIndexes(t *testing.T) { }}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -575,7 +576,7 @@ func testV1FIdxSetStatQueueProfileIndexes(t *testing.T) { var indexes []string expectedIdx := []string{"*string:*req.Destinations:+122:TEST_PROFILE1", "*string:*req.Destinations:+5543:TEST_PROFILE1"} - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -599,19 +600,19 @@ func testV1FIdxSetStatQueueProfileIndexes(t *testing.T) { }}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaStats, Tenant: tenant}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -620,7 +621,7 @@ func testV1FIdxSetStatQueueProfileIndexes(t *testing.T) { func testV1FIdxComputeStatQueueProfileIndexes(t *testing.T) { var result string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, StatS: true, }, &result); err != nil { @@ -631,7 +632,7 @@ func testV1FIdxComputeStatQueueProfileIndexes(t *testing.T) { } expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE1"} var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -660,12 +661,12 @@ func testV1FIdxSetSecondStatQueueProfileIndexes(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -696,25 +697,25 @@ func testV1FIdxSetSecondStatQueueProfileIndexes(t *testing.T) { MinItems: 1, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { t.Errorf("Expecting: %+v, received: %+v", statConfig.StatQueueProfile, reply) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaStats, Tenant: tenant}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -723,7 +724,7 @@ func testV1FIdxSetSecondStatQueueProfileIndexes(t *testing.T) { func testV1FIdxSecondComputeStatQueueProfileIndexes(t *testing.T) { var result string - if err := tFIdxRpc.Call( + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexIDs, &utils.ArgsComputeFilterIndexIDs{ Tenant: tenant, StatIDs: []string{"TEST_PROFILE2"}, @@ -735,7 +736,7 @@ func testV1FIdxSecondComputeStatQueueProfileIndexes(t *testing.T) { } expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE2"} var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -748,7 +749,7 @@ func testV1FIdxSecondComputeStatQueueProfileIndexes(t *testing.T) { func testV1FIdxRemoveStatQueueProfile(t *testing.T) { var result string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, StatS: true, }, &result); err != nil { @@ -757,30 +758,30 @@ func testV1FIdxRemoveStatQueueProfile(t *testing.T) { if result != utils.OK { t.Errorf("Error: %+v", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -802,12 +803,12 @@ func testV1FIdxSetResourceProfileIndexes(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG1"}, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -825,7 +826,7 @@ func testV1FIdxSetResourceProfileIndexes(t *testing.T) { ThresholdIDs: []string{"Val1", "Val2"}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -843,7 +844,7 @@ func testV1FIdxSetResourceProfileIndexes(t *testing.T) { }}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -852,7 +853,7 @@ func testV1FIdxSetResourceProfileIndexes(t *testing.T) { expectedIdx := []string{"*string:*req.Usage:20m:RCFG1", "*string:*req.Usage:45m:RCFG1", "*string:*req.Usage:10s:RCFG1"} - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -876,18 +877,18 @@ func testV1FIdxSetResourceProfileIndexes(t *testing.T) { }}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -896,7 +897,7 @@ func testV1FIdxSetResourceProfileIndexes(t *testing.T) { func testV1FIdxComputeResourceProfileIndexes(t *testing.T) { var reply2 string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, ResourceS: true, }, &reply2); err != nil { @@ -907,7 +908,7 @@ func testV1FIdxComputeResourceProfileIndexes(t *testing.T) { } expectedIDX := []string{"*string:*req.Account:1001:RCFG1"} var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -932,12 +933,12 @@ func testV1FIdxSetSecondResourceProfileIndexes(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG2"}, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG2"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -955,19 +956,19 @@ func testV1FIdxSetSecondResourceProfileIndexes(t *testing.T) { ThresholdIDs: []string{"Val1", "Val2"}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -977,7 +978,7 @@ func testV1FIdxSetSecondResourceProfileIndexes(t *testing.T) { func testV1FIdxSecondComputeResourceProfileIndexes(t *testing.T) { rsid := []string{"RCFG2"} var reply2 string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexIDs, &utils.ArgsComputeFilterIndexIDs{ Tenant: tenant, ResourceIDs: rsid, @@ -989,7 +990,7 @@ func testV1FIdxSecondComputeResourceProfileIndexes(t *testing.T) { } expectedIDX := []string{"*string:*req.Account:1001:RCFG2"} var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -1002,7 +1003,7 @@ func testV1FIdxSecondComputeResourceProfileIndexes(t *testing.T) { func testV1FIdxRemoveResourceProfile(t *testing.T) { var resp string var reply2 string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, ResourceS: true, }, &reply2); err != nil { @@ -1011,28 +1012,28 @@ func testV1FIdxRemoveResourceProfile(t *testing.T) { if reply2 != utils.OK { t.Errorf("Error: %+v", reply2) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveResourceProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveResourceProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG2"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := tFIdxRpc.Call(utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG1"}, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG1"}, &reply2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxRpc.Call(utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG2"}, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG2"}, &reply2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1056,12 +1057,12 @@ func testV1FIdxSetRouteProfileIndexes(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1087,12 +1088,12 @@ func testV1FIdxSetRouteProfileIndexes(t *testing.T) { }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetRouteProfile, rPrf, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, rPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rPrf.RouteProfile, reply) { @@ -1111,7 +1112,7 @@ func testV1FIdxSetRouteProfileIndexes(t *testing.T) { }}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1119,7 +1120,7 @@ func testV1FIdxSetRouteProfileIndexes(t *testing.T) { var indexes []string expectedIdx := []string{"*string:*req.CGRID:qweasdzxc:TEST_PROFILE1", "*string:*req.CGRID:iopjklbnm:TEST_PROFILE1"} - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaRoutes, Tenant: tenant}, &indexes); err != nil { t.Error(err) @@ -1145,18 +1146,18 @@ func testV1FIdxSetRouteProfileIndexes(t *testing.T) { }, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaRoutes, Tenant: tenant}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaRoutes, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1165,7 +1166,7 @@ func testV1FIdxSetRouteProfileIndexes(t *testing.T) { func testV1FIdxComputeRouteProfileIndexes(t *testing.T) { var reply2 string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, RouteS: true, }, &reply2); err != nil { @@ -1176,7 +1177,7 @@ func testV1FIdxComputeRouteProfileIndexes(t *testing.T) { } expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE1"} var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaRoutes, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -1205,12 +1206,12 @@ func testV1FIdxSetSecondRouteProfileIndexes(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1235,25 +1236,25 @@ func testV1FIdxSetSecondRouteProfileIndexes(t *testing.T) { Weight: 10, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetRouteProfile, rPrf, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, rPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rPrf.RouteProfile, reply) { t.Errorf("Expecting: %+v, received: %+v", rPrf.RouteProfile, reply) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaRoutes, Tenant: tenant}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaRoutes, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1263,7 +1264,7 @@ func testV1FIdxSetSecondRouteProfileIndexes(t *testing.T) { func testV1FIdxSecondComputeRouteProfileIndexes(t *testing.T) { spid := []string{"TEST_PROFILE2"} var reply2 string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexIDs, &utils.ArgsComputeFilterIndexIDs{ Tenant: tenant, RouteIDs: spid, @@ -1275,7 +1276,7 @@ func testV1FIdxSecondComputeRouteProfileIndexes(t *testing.T) { } expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE2"} var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaRoutes, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -1289,7 +1290,7 @@ func testV1FIdxSecondComputeRouteProfileIndexes(t *testing.T) { func testV1FIdxRemoveRouteProfile(t *testing.T) { var resp string var reply2 string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, RouteS: true, }, &reply2); err != nil { @@ -1298,30 +1299,30 @@ func testV1FIdxRemoveRouteProfile(t *testing.T) { if reply2 != utils.OK { t.Errorf("Error: %+v", reply2) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveRouteProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveRouteProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveRouteProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveRouteProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaRoutes, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil && err.Error() != utils.ErrNotFound.Error() { @@ -1344,12 +1345,12 @@ func testV1FIdxSetAttributeProfileIndexes(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ApierTest"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1370,12 +1371,12 @@ func testV1FIdxSetAttributeProfileIndexes(t *testing.T) { Weight: 20, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ApierTest"}}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(alsPrf.FilterIDs, reply.FilterIDs) { @@ -1400,7 +1401,7 @@ func testV1FIdxSetAttributeProfileIndexes(t *testing.T) { }}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1409,7 +1410,7 @@ func testV1FIdxSetAttributeProfileIndexes(t *testing.T) { expectedIdx := []string{"*string:*opts.Subsystems:*chargers:ApierTest", "*string:*opts.Subsystems:*thresholds:ApierTest", "*string:*opts.Subsystems:*stats:ApierTest"} - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: tenant, FilterType: utils.MetaString, Context: utils.MetaSessionS}, &indexes); err != nil { @@ -1434,12 +1435,12 @@ func testV1FIdxSetAttributeProfileIndexes(t *testing.T) { }}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: tenant, Context: utils.MetaSessionS}, &result); err != nil { @@ -1447,7 +1448,7 @@ func testV1FIdxSetAttributeProfileIndexes(t *testing.T) { } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: tenant, FilterType: utils.MetaString, Context: utils.MetaSessionS}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1456,7 +1457,7 @@ func testV1FIdxSetAttributeProfileIndexes(t *testing.T) { func testV1FIdxComputeAttributeProfileIndexes(t *testing.T) { var result string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, Context: utils.MetaSessionS, @@ -1468,7 +1469,7 @@ func testV1FIdxComputeAttributeProfileIndexes(t *testing.T) { } expectedIDX := []string{"*string:*req.Account:1001:ApierTest"} var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: tenant, FilterType: utils.MetaString, @@ -1498,12 +1499,12 @@ func testV1FIdxSetSecondAttributeProfileIndexes(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: tenant, ID: "ApierTest2"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { @@ -1523,12 +1524,12 @@ func testV1FIdxSetSecondAttributeProfileIndexes(t *testing.T) { Weight: 20, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: tenant, ID: "ApierTest2"}}, &reply); err != nil { t.Error(err) @@ -1542,7 +1543,7 @@ func testV1FIdxSetSecondAttributeProfileIndexes(t *testing.T) { } else if !reflect.DeepEqual(alsPrf.ID, reply.ID) { t.Errorf("Expecting : %+v, received: %+v", alsPrf.ID, reply.ID) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: tenant, @@ -1552,7 +1553,7 @@ func testV1FIdxSetSecondAttributeProfileIndexes(t *testing.T) { t.Error("Unexpected reply returned", result) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: tenant, @@ -1565,7 +1566,7 @@ func testV1FIdxSetSecondAttributeProfileIndexes(t *testing.T) { func testV1FIdxSecondComputeAttributeProfileIndexes(t *testing.T) { var result string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexIDs, &utils.ArgsComputeFilterIndexIDs{ Tenant: tenant, Context: utils.MetaSessionS, @@ -1577,7 +1578,7 @@ func testV1FIdxSecondComputeAttributeProfileIndexes(t *testing.T) { } expectedIDX := []string{"*string:*req.Account:1001:ApierTest2"} var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: tenant, FilterType: utils.MetaString, @@ -1592,7 +1593,7 @@ func testV1FIdxSecondComputeAttributeProfileIndexes(t *testing.T) { func testV1FIdxComputeWithAnotherContext(t *testing.T) { var result string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, Context: utils.MetaAny, @@ -1603,7 +1604,7 @@ func testV1FIdxComputeWithAnotherContext(t *testing.T) { t.Errorf("Error: %+v", result) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: tenant, FilterType: utils.MetaString, @@ -1616,7 +1617,7 @@ func testV1FIdxComputeWithAnotherContext(t *testing.T) { func testV1FIdxRemoveAttributeProfile(t *testing.T) { var result string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, Context: utils.MetaSessionS, @@ -1626,14 +1627,14 @@ func testV1FIdxRemoveAttributeProfile(t *testing.T) { } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: tenant, ID: "ApierTest"}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: tenant, ID: "ApierTest2"}}, &result); err != nil { t.Error(err) @@ -1641,20 +1642,20 @@ func testV1FIdxRemoveAttributeProfile(t *testing.T) { t.Error("Unexpected reply returned", result) } var reply *engine.AttributeProfile - if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: tenant, ID: "ApierTest2"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: tenant, ID: "ApierTest"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: tenant, FilterType: utils.MetaString, @@ -1716,19 +1717,19 @@ func testV1FIdxSetMultipleAttributesMultipleFilters(t *testing.T) { } // First we will set a filter for usage var reply string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, fltr, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply result", reply) } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, fltr1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply result", reply) } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, fltr2, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -1786,26 +1787,26 @@ func testV1FIdxSetMultipleAttributesMultipleFilters(t *testing.T) { }, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetAttributeProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf2, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(err) } - if err := tFIdxRpc.Call(utils.APIerSv1SetAttributeProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf3, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(err) } - if err := tFIdxRpc.Call(utils.APIerSv1SetAttributeProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(err) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaAny, @@ -1819,7 +1820,7 @@ func testV1FIdxSetMultipleAttributesMultipleFilters(t *testing.T) { //not found for both cases var replyIdx []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaAny, @@ -1830,7 +1831,7 @@ func testV1FIdxSetMultipleAttributesMultipleFilters(t *testing.T) { // now we will ComputeFilterIndexes by IDs for *sessions context(but just only 1 profile, not both) var expIdx []string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexIDs, &utils.ArgsComputeFilterIndexIDs{ Tenant: "cgrates.org", Context: utils.MetaAny, @@ -1849,7 +1850,7 @@ func testV1FIdxSetMultipleAttributesMultipleFilters(t *testing.T) { "*string:*opts.*context:*chargers:TEST_ATTRIBUTES_new_fltr", "*string:*opts.*context:*sessions:TEST_ATTRIBUTE3", "*string:*req.Usage:123s:TEST_ATTRIBUTES_new_fltr"} - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaAny, @@ -1865,7 +1866,7 @@ func testV1FIdxSetMultipleAttributesMultipleFilters(t *testing.T) { } // compute for the last profile remain - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexIDs, &utils.ArgsComputeFilterIndexIDs{Tenant: "cgrates.org", Context: utils.MetaAny, AttributeIDs: []string{"TEST_ATTRIBUTES_IT_TEST"}, @@ -1893,7 +1894,7 @@ func testV1FIdxSetMultipleAttributesMultipleFilters(t *testing.T) { "*string:*req.Usage:123s:TEST_ATTRIBUTES_IT_TEST", "*string:*req.Usage:123s:TEST_ATTRIBUTES_new_fltr", } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaAny, @@ -1960,17 +1961,17 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { }, } var reply string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, fltr, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, fltr, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply returned") } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, fltr1, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, fltr1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply returned") } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, fltr2, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, fltr2, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply returned") @@ -1992,7 +1993,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { }, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetAttributeProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -2014,7 +2015,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { sort.Strings(expIdx) var result []string // same expecteded indexes for *sessions, *chargers and *thresholds - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaSessionS, ItemType: utils.MetaAttributes, @@ -2026,7 +2027,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { t.Errorf("Expected %+v received %+v", utils.ToJSON(expIdx), utils.ToJSON(result)) } } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaChargers, ItemType: utils.MetaAttributes, @@ -2038,7 +2039,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { t.Errorf("Expected %+v received %+v", utils.ToJSON(expIdx), utils.ToJSON(result)) } } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaThresholds, ItemType: utils.MetaAttributes, @@ -2052,21 +2053,21 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { } // remove indexes for all contexts - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaSessionS, ItemType: utils.MetaAttributes, }, &reply); err != nil { t.Error(err) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaChargers, ItemType: utils.MetaAttributes, }, &reply); err != nil { t.Error(err) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaThresholds, ItemType: utils.MetaAttributes, @@ -2076,7 +2077,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { // compute indexes by with different contexts and check them // firstly for *sessions context - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaSessionS, @@ -2100,7 +2101,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { } sort.Strings(expIdx) // same expected indexes for *sessions, *chargers and *thresholds - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaSessionS, ItemType: utils.MetaAttributes, @@ -2114,7 +2115,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { } // as for *sessions was computed, for *chargers and *thresaholds should not be computed, so NOT FOUND will be returned - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaChargers, ItemType: utils.MetaAttributes, @@ -2122,7 +2123,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err) } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaThresholds, ItemType: utils.MetaAttributes, @@ -2131,7 +2132,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { } // noe we will compute for *chargers, and the remain context for compute indexes will remain *thresholds - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaChargers, @@ -2141,7 +2142,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { } // check for *sesssions and for *chargers, and for *threshold will be NOT FOUND - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaSessionS, ItemType: utils.MetaAttributes, @@ -2153,7 +2154,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { t.Errorf("Expected %+v received %+v", utils.ToJSON(expIdx), utils.ToJSON(result)) } } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaChargers, ItemType: utils.MetaAttributes, @@ -2166,7 +2167,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { } } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaThresholds, ItemType: utils.MetaAttributes, @@ -2175,7 +2176,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { } // compute with the remain context *thresholds, so in the end, all indexes will be computed for all contexts - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaThresholds, @@ -2185,7 +2186,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { } // check again all the indexes for all contexts - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaSessionS, // *sesssions ItemType: utils.MetaAttributes, @@ -2197,7 +2198,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { t.Errorf("Expected %+v received %+v", utils.ToJSON(expIdx), utils.ToJSON(result)) } } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaChargers, // *chargers ItemType: utils.MetaAttributes, @@ -2209,7 +2210,7 @@ func testV1FIdxSetAttributeProfileMultipleContextsAndComputes(t *testing.T) { t.Errorf("Expected %+v received %+v", utils.ToJSON(expIdx), utils.ToJSON(result)) } } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: "cgrates.org", Context: utils.MetaThresholds, // *thresholds ItemType: utils.MetaAttributes, @@ -2239,7 +2240,7 @@ func testV1FIdxPopulateDatabase(t *testing.T) { "*string:~*req.Account:1002"}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -2258,7 +2259,7 @@ func testV1FIdxPopulateDatabase(t *testing.T) { "*string:~*req.Account:1002"}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -2277,7 +2278,7 @@ func testV1FIdxPopulateDatabase(t *testing.T) { "*string:~*req.Account:1003"}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -2313,7 +2314,7 @@ func testV1FIdxGetFilterIndexes1(t *testing.T) { "*prefix:*req.Account:10:ResProfile3"} sort.Strings(expectedIndexes) var reply []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil { t.Error(err) } else if sort.Strings(reply); !reflect.DeepEqual(expectedIndexes, reply) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(reply)) @@ -2343,7 +2344,7 @@ func testV1FIdxGetFilterIndexes2(t *testing.T) { "*string:*req.Account:2002:ResProfile2"} sort.Strings(expectedIndexes) var reply []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil { t.Error(err) } else if sort.Strings(reply); !reflect.DeepEqual(expectedIndexes, reply) { t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, reply) @@ -2366,7 +2367,7 @@ func testV1FIdxGetFilterIndexes3(t *testing.T) { "*prefix:*req.Destination:1001:ResProfile3"} sort.Strings(expectedIndexes) var reply []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil { t.Error(err) } else if sort.Strings(reply); !reflect.DeepEqual(expectedIndexes, reply) { t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, reply) @@ -2391,7 +2392,7 @@ func testV1FIdxGetFilterIndexes4(t *testing.T) { "*string:*req.Account:2002:ResProfile2"} sort.Strings(expectedIndexes) var reply []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil { t.Error(err) } else if sort.Strings(reply); !reflect.DeepEqual(expectedIndexes, reply) { t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, reply) @@ -2423,7 +2424,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { }, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -2440,7 +2441,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetDispatcherProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil { t.Error(err) @@ -2461,7 +2462,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { } sort.Strings(expectedIndexes) var idx []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { t.Error(err) } else if sort.Strings(idx); !reflect.DeepEqual(len(expectedIndexes), len(idx)) { t.Errorf("Expecting: %+v, received: %+v", len(expectedIndexes), len(idx)) @@ -2479,7 +2480,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { "*string:*req.Subject:2012:DSP_Test1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { t.Error(err) } else if sort.Strings(idx); !reflect.DeepEqual(len(expectedIndexes), len(idx)) { t.Errorf("Expecting: %+v, received: %+v", len(expectedIndexes), len(idx)) @@ -2497,7 +2498,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { "*string:*req.Subject:2012:DSP_Test1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { t.Error(err) } else if sort.Strings(idx); !reflect.DeepEqual(expectedIndexes, idx) { t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, idx) @@ -2522,7 +2523,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { }, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -2539,7 +2540,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { "*string:*req.Usage:1s:DSP_Test1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: tenant, Context: utils.MetaAttributes, ItemType: utils.MetaDispatchers, }, &idx); err != nil { t.Error(err) @@ -2558,7 +2559,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { "*string:*req.Usage:1s:DSP_Test1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ Tenant: tenant, Context: utils.MetaSessionS, ItemType: utils.MetaDispatchers, }, &idx); err != nil { t.Error(err) @@ -2590,14 +2591,14 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { }, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } //remove the indexes for *sessions subsystem - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaDispatchers, Tenant: tenant, Context: utils.MetaSessionS}, &reply); err != nil { @@ -2608,7 +2609,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { //verify if was removed var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, AttrGetFilterIndexes{ Tenant: tenant, Context: utils.MetaSessionS, ItemType: utils.MetaDispatchers, }, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -2626,7 +2627,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { "*string:*req.Subject:2012:DSP_Test1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { t.Error(err) } else if sort.Strings(idx); !reflect.DeepEqual(len(expectedIndexes), len(idx)) { t.Errorf("Expecting: %+v, received: %+v", len(expectedIndexes), len(idx)) @@ -2637,7 +2638,7 @@ func testV1FIdxSetDispatcherProfile(t *testing.T) { func testV1FIdxComputeDispatcherProfileIndexes(t *testing.T) { var result string //recompute indexes for dispatcherProfile for *sessions subsystem - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, Context: utils.MetaSessionS, @@ -2654,7 +2655,7 @@ func testV1FIdxComputeDispatcherProfileIndexes(t *testing.T) { } sort.Strings(expectedIndexes) var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaDispatchers, Tenant: tenant, Context: utils.MetaSessionS}, &indexes); err != nil { @@ -2677,7 +2678,7 @@ func testV1FIdxSetDispatcherProfile2(t *testing.T) { }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetDispatcherProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil { t.Error(err) @@ -2696,7 +2697,7 @@ func testV1FIdxSetDispatcherProfile2(t *testing.T) { }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetDispatcherProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile2, &reply); err != nil { t.Error(err) @@ -2718,7 +2719,7 @@ func testV1FIdxSetDispatcherProfile2(t *testing.T) { } sort.Strings(expectedIndexes) var idx []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { t.Error(err) } else if sort.Strings(idx); !reflect.DeepEqual(expectedIndexes, idx) { t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, idx) @@ -2737,13 +2738,13 @@ func testV1FIdxSetDispatcherProfile2(t *testing.T) { "*string:*req.Subject:2012:DSP_Test1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { t.Error(err) } else if sort.Strings(idx); !reflect.DeepEqual(expectedIndexes, idx) { t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, idx) } //remove the indexes for *sessions subsystem - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaDispatchers, Tenant: tenant, Context: utils.MetaSessionS}, &reply); err != nil { @@ -2754,13 +2755,13 @@ func testV1FIdxSetDispatcherProfile2(t *testing.T) { //verify if indexes was removed for *sessions var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } //remove the indexes for *attribute subsystem - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaDispatchers, Tenant: tenant, Context: utils.MetaAttributes}, &reply); err != nil { @@ -2775,7 +2776,7 @@ func testV1FIdxSetDispatcherProfile2(t *testing.T) { Context: utils.MetaAttributes, ItemType: utils.MetaDispatchers, } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &idx); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -2784,7 +2785,7 @@ func testV1FIdxSetDispatcherProfile2(t *testing.T) { func testV1FIdxComputeDispatcherProfileIndexes2(t *testing.T) { var result string //recompute indexes for dispatcherProfile for *sessions subsystem - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, Context: utils.MetaSessionS, @@ -2802,7 +2803,7 @@ func testV1FIdxComputeDispatcherProfileIndexes2(t *testing.T) { } sort.Strings(expectedIndexes) var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaDispatchers, Tenant: tenant, Context: utils.MetaSessionS}, &indexes); err != nil { @@ -2812,7 +2813,7 @@ func testV1FIdxComputeDispatcherProfileIndexes2(t *testing.T) { } //recompute indexes for dispatcherProfile for *attributes subsystem - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, Context: utils.MetaAttributes, @@ -2829,7 +2830,7 @@ func testV1FIdxComputeDispatcherProfileIndexes2(t *testing.T) { "*string:*req.Subject:2012:DSP_Test1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaDispatchers, Tenant: tenant, Context: utils.MetaAttributes}, &indexes); err != nil { @@ -2841,7 +2842,7 @@ func testV1FIdxComputeDispatcherProfileIndexes2(t *testing.T) { func testV1FIdxClearCache(t *testing.T) { var reply string - if err := tFIdxRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := tFIdxRpc.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ CacheIDs: nil, }, &reply); err != nil { t.Error(err) @@ -2875,7 +2876,7 @@ func testV1FIdxSetDispatcherComputeIDs(t *testing.T) { }, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -2892,7 +2893,7 @@ func testV1FIdxSetDispatcherComputeIDs(t *testing.T) { }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetDispatcherProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil { t.Error(err) @@ -2901,7 +2902,7 @@ func testV1FIdxSetDispatcherComputeIDs(t *testing.T) { } //remove the indexes for *sessions subsystem - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaDispatchers, Tenant: tenant, Context: utils.MetaSessionS}, &reply); err != nil { @@ -2911,7 +2912,7 @@ func testV1FIdxSetDispatcherComputeIDs(t *testing.T) { } //verify if was removed var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, AttrGetFilterIndexes{ Tenant: tenant, Context: utils.MetaSessionS, ItemType: utils.MetaDispatchers, }, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -2930,13 +2931,13 @@ func testV1FIdxSetDispatcherComputeIDs(t *testing.T) { } var idx []string sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { t.Error(err) } else if sort.Strings(idx); !reflect.DeepEqual(len(expectedIndexes), len(idx)) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(idx)) } - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, Context: utils.MetaSessionS, @@ -2952,7 +2953,7 @@ func testV1FIdxSetDispatcherComputeIDs(t *testing.T) { "*string:*req.Subject:2012:DSP_Test1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaDispatchers, Tenant: tenant, Context: utils.MetaSessionS}, &indexes); err != nil { @@ -2973,7 +2974,7 @@ func testV1FIdxSetDispatcherComputeIDs(t *testing.T) { "*string:*req.Subject:2012:DSP_Test1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { t.Error(err) } else if sort.Strings(idx); !reflect.DeepEqual(len(expectedIndexes), len(idx)) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(idx)) @@ -2990,7 +2991,7 @@ func testV1FIdxSetDispatcherComputeIDs(t *testing.T) { }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetDispatcherProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil { t.Error(err) @@ -3009,7 +3010,7 @@ func testV1FIdxSetDispatcherComputeIDs(t *testing.T) { }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetDispatcherProfile, + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile2, &reply); err != nil { t.Error(err) @@ -3030,7 +3031,7 @@ func testV1FIdxSetDispatcherComputeIDs(t *testing.T) { "*string:*req.Subject:2012:DSP_Test1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil { t.Error(err) } else if sort.Strings(idx); !reflect.DeepEqual(expectedIndexes, idx) { t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, idx) @@ -3050,7 +3051,7 @@ func testV1FIdxSetResourceComputeIDs(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -3070,27 +3071,27 @@ func testV1FIdxSetResourceComputeIDs(t *testing.T) { ThresholdIDs: []string{"Val1", "Val2"}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var indexes []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } var reply2 string - if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{ Tenant: tenant, ResourceS: true, }, &reply2); err != nil { @@ -3100,7 +3101,7 @@ func testV1FIdxSetResourceComputeIDs(t *testing.T) { t.Errorf("Error: %+v", reply2) } expectedIDX := []string{"*string:*req.Account:1001:RCFG1"} - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -3122,7 +3123,7 @@ func testV1FIdxSetResourceComputeIDs(t *testing.T) { }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -3142,12 +3143,12 @@ func testV1FIdxSetResourceComputeIDs(t *testing.T) { ThresholdIDs: []string{"Val1", "Val2"}, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -3157,7 +3158,7 @@ func testV1FIdxSetResourceComputeIDs(t *testing.T) { "*string:*req.Account:1001:RCFG1", "*string:*req.Account:1001:RCFG2", } - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -3203,12 +3204,12 @@ func testSetProfilesWithFltrsAndOverwriteThemFIdx(t *testing.T) { }, } var result string - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter1, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter1, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter2, &result); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -3260,12 +3261,12 @@ func testSetProfilesWithFltrsAndOverwriteThemFIdx(t *testing.T) { }, } var reply string - if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, stat1, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, stat1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } - if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, stat2, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, stat2, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -3283,7 +3284,7 @@ func testSetProfilesWithFltrsAndOverwriteThemFIdx(t *testing.T) { Async: true, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl1, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -3309,7 +3310,7 @@ func testSetProfilesWithFltrsAndOverwriteThemFIdx(t *testing.T) { } sort.Strings(expectedIndexes) var replyIDx []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil { t.Error(err) } else if sort.Strings(replyIDx); !reflect.DeepEqual(expectedIndexes, replyIDx) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(replyIDx)) @@ -3347,12 +3348,12 @@ func testSetProfilesWithFltrsAndOverwriteThemFIdx(t *testing.T) { }, }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter1, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } - if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter2, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter2, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -3375,7 +3376,7 @@ func testSetProfilesWithFltrsAndOverwriteThemFIdx(t *testing.T) { "*prefix:*req.Subject:1002:Stats2", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil { t.Error(err) } else if sort.Strings(replyIDx); !reflect.DeepEqual(expectedIndexes, replyIDx) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(replyIDx)) @@ -3427,12 +3428,12 @@ func testSetAndChangeFiltersOnProfiles(t *testing.T) { }, } var reply string - if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, stat1, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, stat1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } - if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, stat2, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, stat2, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -3452,7 +3453,7 @@ func testSetAndChangeFiltersOnProfiles(t *testing.T) { }, } - if err := tFIdxRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl1, &reply); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -3468,7 +3469,7 @@ func testSetAndChangeFiltersOnProfiles(t *testing.T) { } sort.Strings(expectedIndexes) var replyIDx []string - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil { t.Error(err) } else if sort.Strings(replyIDx); !reflect.DeepEqual(expectedIndexes, replyIDx) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(replyIDx)) @@ -3485,7 +3486,7 @@ func testSetAndChangeFiltersOnProfiles(t *testing.T) { "*prefix:*req.Subject:1002:TEST_PROFILE1", } sort.Strings(expectedIndexes) - if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil { + if err := tFIdxRpc.Call(context.Background(), utils.APIerSv1GetFilterIndexes, arg, &replyIDx); err != nil { t.Error(err) } else if sort.Strings(replyIDx); !reflect.DeepEqual(expectedIndexes, replyIDx) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(replyIDx)) diff --git a/apier/v1/filterindexecache_it_test.go b/apier/v1/filterindexecache_it_test.go index 16ad96afb..28180ae94 100644 --- a/apier/v1/filterindexecache_it_test.go +++ b/apier/v1/filterindexecache_it_test.go @@ -21,19 +21,20 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) var ( - tFIdxCaRpc *rpc.Client + tFIdxCaRpc *birpc.Client sTestsFilterIndexesSV1Ca = []func(t *testing.T){ testV1FIdxCaLoadConfig, testV1FIdxCaInitDataDb, @@ -136,7 +137,7 @@ func testV1FIdxCaRpcConn(t *testing.T) { func testV1FIdxCaFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} - if err := tFIdxCaRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -156,7 +157,7 @@ func testV1FIdxCaProcessEventWithNotFound(t *testing.T) { }, } var thIDs []string - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err.Error() != utils.ErrNotFound.Error() { + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } @@ -184,7 +185,7 @@ func testV1FIdxCaSetThresholdProfile(t *testing.T) { }, } var result string - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -206,7 +207,7 @@ func testV1FIdxCaSetThresholdProfile(t *testing.T) { }, } - if err := tFIdxCaRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -228,7 +229,7 @@ func testV1FIdxCaSetThresholdProfile(t *testing.T) { eIDs := []string{"TEST_PROFILE1"} //Testing ProcessEvent on set thresholdprofile using apier - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(thIDs, eIDs) { t.Errorf("Expecting hits: %s, received: %s", eIDs, thIDs) @@ -254,7 +255,7 @@ func testV1FIdxCaGetThresholdFromTP(t *testing.T) { var thIDs []string eIDs := []string{"THD_ACNT_BALANCE_1"} //Testing ProcessEvent on set thresholdprofile using apier - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(thIDs, eIDs) { @@ -285,7 +286,7 @@ func testV1FIdxCaUpdateThresholdProfile(t *testing.T) { }, }, } - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -305,7 +306,7 @@ func testV1FIdxCaUpdateThresholdProfile(t *testing.T) { Async: true, }, } - if err := tFIdxCaRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -325,7 +326,7 @@ func testV1FIdxCaUpdateThresholdProfile(t *testing.T) { var thIDs []string eIDs := []string{} //Testing ProcessEvent on set thresholdprofile after update making sure there are no hits - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -343,7 +344,7 @@ func testV1FIdxCaUpdateThresholdProfile(t *testing.T) { } eIDs = []string{"TEST_PROFILE1"} //Testing ProcessEvent on set thresholdprofile after update - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(thIDs, eIDs) { t.Errorf("Expecting : %s, received: %s", eIDs, thIDs) @@ -373,14 +374,14 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { }, }, } - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.ThresholdProfile - if err := tFIdxCaRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}, &reply); err != nil { t.Error(err) } @@ -393,7 +394,7 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { } reply.FilterIDs = []string{"TestFilter3"} - if err := tFIdxCaRpc.Call(utils.APIerSv1SetThresholdProfile, &engine.ThresholdProfileWithAPIOpts{ThresholdProfile: reply}, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, &engine.ThresholdProfileWithAPIOpts{ThresholdProfile: reply}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -411,7 +412,7 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { } var thIDs []string //Testing ProcessEvent on set thresholdprofile using apier - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -428,7 +429,7 @@ func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) { } eIDs := []string{"THD_ACNT_BALANCE_1"} //Testing ProcessEvent on set thresholdprofile using apier - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(thIDs, eIDs) { t.Errorf("Expecting : %s, received: %s", eIDs, thIDs) @@ -450,7 +451,7 @@ func testV1FIdxCaRemoveThresholdProfile(t *testing.T) { } var thIDs []string eIDs := []string{"TEST_PROFILE1"} - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(thIDs, eIDs) { t.Errorf("Expecting : %s, received: %s", eIDs, thIDs) @@ -468,13 +469,13 @@ func testV1FIdxCaRemoveThresholdProfile(t *testing.T) { }, } eIDs = []string{"THD_ACNT_BALANCE_1"} - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err != nil { t.Error(err) } else if !reflect.DeepEqual(thIDs, eIDs) { t.Errorf("Expecting : %s, received: %s", eIDs, thIDs) } //Remove threshold profile that was set form api - if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -482,29 +483,29 @@ func testV1FIdxCaRemoveThresholdProfile(t *testing.T) { } var sqp *engine.ThresholdProfile //Test the remove - if err := tFIdxCaRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } //Remove threshold profile that was set form tariffplan - if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } //Test the remove - if err := tFIdxCaRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -524,13 +525,13 @@ func testV1FIdxCaGetStatQueuesWithNotFound(t *testing.T) { utils.MetaEventType: utils.AccountUpdate, }, } - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv, &reply); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, tEv, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } tEv.Tenant = utils.EmptyString - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv, &reply); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, tEv, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -561,7 +562,7 @@ func testV1FIdxCaSetStatQueueProfile(t *testing.T) { } var result string - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -588,7 +589,7 @@ func testV1FIdxCaSetStatQueueProfile(t *testing.T) { MinItems: 1, }, } - if err := tFIdxCaRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -608,7 +609,7 @@ func testV1FIdxCaSetStatQueueProfile(t *testing.T) { } var reply []string expected := []string{"TEST_PROFILE1"} - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, tEv, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { @@ -629,7 +630,7 @@ func testV1FIdxCaGetStatQueuesFromTP(t *testing.T) { utils.Cost: 12.1, }, } - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, ev2, &reply); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev2, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -644,7 +645,7 @@ func testV1FIdxCaGetStatQueuesFromTP(t *testing.T) { utils.Cost: 12.1, }, } - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, &ev3, &reply); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &ev3, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -664,7 +665,7 @@ func testV1FIdxCaGetStatQueuesFromTP(t *testing.T) { utils.MetaEventType: utils.AccountUpdate, }, } - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, &tEv, &reply); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &tEv, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -683,7 +684,7 @@ func testV1FIdxCaGetStatQueuesFromTP(t *testing.T) { utils.MetaEventType: utils.AccountUpdate, }, } - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, &tEv2, &reply); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &tEv2, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -713,7 +714,7 @@ func testV1FIdxCaUpdateStatQueueProfile(t *testing.T) { }, } var result string - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -740,7 +741,7 @@ func testV1FIdxCaUpdateStatQueueProfile(t *testing.T) { MinItems: 1, }, } - if err := tFIdxCaRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -759,7 +760,7 @@ func testV1FIdxCaUpdateStatQueueProfile(t *testing.T) { utils.MetaEventType: utils.BalanceUpdate, }, } - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv, &reply); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, tEv, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -789,19 +790,19 @@ func testV1FIdxCaUpdateStatQueueProfileFromTP(t *testing.T) { }, } var result string - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply engine.StatQueueProfile - if err := tFIdxCaRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}, &reply); err != nil { t.Error(err) } reply.FilterIDs = []string{"FLTR_3"} reply.ActivationInterval = &utils.ActivationInterval{ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)} - if err := tFIdxCaRpc.Call(utils.APIerSv1SetStatQueueProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, &engine.StatQueueProfileWithAPIOpts{StatQueueProfile: &reply}, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -823,7 +824,7 @@ func testV1FIdxCaUpdateStatQueueProfileFromTP(t *testing.T) { } var ids []string expected := []string{"Stats1"} - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, tEv, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, expected) { @@ -846,7 +847,7 @@ func testV1FIdxCaRemoveStatQueueProfile(t *testing.T) { utils.MetaEventType: utils.BalanceUpdate, }, } - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv, &reply); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, tEv, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -866,14 +867,14 @@ func testV1FIdxCaRemoveStatQueueProfile(t *testing.T) { utils.MetaEventType: utils.AccountUpdate, }, } - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv2, &reply); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, tEv2, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) } var result string //Remove threshold profile that was set form api - if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -881,30 +882,30 @@ func testV1FIdxCaRemoveStatQueueProfile(t *testing.T) { } var sqp *engine.StatQueueProfile //Test the remove - if err := tFIdxCaRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } //Remove threshold profile that was set form tariffplan - if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //Test the remove - if err := tFIdxCaRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv, &reply); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, tEv, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv2, &reply); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.StatSv1ProcessEvent, tEv2, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -924,7 +925,7 @@ func testV1FIdxCaProcessAttributeProfileEventWithNotFound(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -953,7 +954,7 @@ func testV1FIdxCaSetAttributeProfile(t *testing.T) { }, } var result string - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -980,7 +981,7 @@ func testV1FIdxCaSetAttributeProfile(t *testing.T) { Weight: 20, }, } - if err := tFIdxCaRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -998,7 +999,7 @@ func testV1FIdxCaSetAttributeProfile(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, + if err := tFIdxCaRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } @@ -1018,7 +1019,7 @@ func testV1FIdxCaGetAttributeProfileFromTP(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } } @@ -1046,7 +1047,7 @@ func testV1FIdxCaUpdateAttributeProfile(t *testing.T) { }, } var result string - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1073,7 +1074,7 @@ func testV1FIdxCaUpdateAttributeProfile(t *testing.T) { Weight: 20, }, } - if err := tFIdxCaRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1091,7 +1092,7 @@ func testV1FIdxCaUpdateAttributeProfile(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } } @@ -1119,19 +1120,19 @@ func testV1FIdxCaUpdateAttributeProfileFromTP(t *testing.T) { }, } var result string - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply engine.AttributeProfile - if err := tFIdxCaRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1"}}, &reply); err != nil { t.Error(err) } reply.FilterIDs = []string{"TestFilter3"} - if err := tFIdxCaRpc.Call(utils.APIerSv1SetAttributeProfile, &engine.AttributeProfileWithAPIOpts{AttributeProfile: &reply}, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, &engine.AttributeProfileWithAPIOpts{AttributeProfile: &reply}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1149,7 +1150,7 @@ func testV1FIdxCaUpdateAttributeProfileFromTP(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } } @@ -1168,7 +1169,7 @@ func testV1FIdxCaRemoveAttributeProfile(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) } @@ -1183,11 +1184,11 @@ func testV1FIdxCaRemoveAttributeProfile(t *testing.T) { utils.OptsContext: utils.MetaSessionS, }, } - if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev2, &rplyEv); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev2, &rplyEv); err != nil { t.Error(err) } //Remove threshold profile that was set form api - if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -1195,31 +1196,31 @@ func testV1FIdxCaRemoveAttributeProfile(t *testing.T) { } var sqp *engine.AttributeProfile //Test the remove - if err := tFIdxCaRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } //Remove threshold profile that was set form tariffplan - if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1"}}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } //Test the remove - if err := tFIdxCaRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1"}}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev2, &rplyEv); err == nil || + if err := tFIdxCaRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev2, &rplyEv); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -1241,21 +1242,21 @@ func testV1FIdxCaGetResourceProfileWithNotFound(t *testing.T) { utils.OptsResourcesUnits: 6, }, } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AllocateResources, + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AllocateResources, cgrEv, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &cgrEv, &reply); err.Error() != utils.ErrNotFound.Error() { t.Error(err) } cgrEv.Tenant = utils.EmptyString - if err := tFIdxCaRpc.Call(utils.ResourceSv1AllocateResources, + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AllocateResources, cgrEv, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &cgrEv, &reply); err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -1289,7 +1290,7 @@ func testV1FIdxCaSetResourceProfile(t *testing.T) { }, } var result string - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1311,7 +1312,7 @@ func testV1FIdxCaSetResourceProfile(t *testing.T) { ThresholdIDs: []string{utils.MetaNone}, }, } - if err := tFIdxCaRpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1329,14 +1330,14 @@ func testV1FIdxCaSetResourceProfile(t *testing.T) { utils.OptsResourcesUnits: 6, }, } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AllocateResources, + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AllocateResources, cgrEv, &result); err != nil { t.Error(err) } else if result != "Approved" { t.Error("Unexpected reply returned", result) } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &cgrEv, &result); err != nil { t.Error(err) } else if result != "Approved" { @@ -1359,13 +1360,13 @@ func testV1FIdxCaGetResourceProfileFromTP(t *testing.T) { utils.OptsResourcesUnits: 6, }, } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AllocateResources, + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AllocateResources, cgrEv, &reply); err != nil { t.Error(err) } else if reply != "Approved" { t.Error("Unexpected reply returned", reply) } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &cgrEv, &reply); err != nil { t.Error(err) } else if reply != "Approved" { @@ -1385,7 +1386,7 @@ func testV1FIdxCaGetResourceProfileFromTP(t *testing.T) { utils.OptsResourcesUnits: 6, }, } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &ev, &reply); err != nil { t.Error(err) } else if reply != "ResGroup1" { @@ -1421,7 +1422,7 @@ func testV1FIdxCaUpdateResourceProfile(t *testing.T) { }, } var result string - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1443,7 +1444,7 @@ func testV1FIdxCaUpdateResourceProfile(t *testing.T) { ThresholdIDs: []string{utils.MetaNone}, }, } - if err := tFIdxCaRpc.Call(utils.APIerSv1SetResourceProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -1462,7 +1463,7 @@ func testV1FIdxCaUpdateResourceProfile(t *testing.T) { utils.OptsResourcesUnits: 6, }, } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &cgrEv, &result); err != nil { t.Error(err) } else if result != "MessageAllocation" { @@ -1498,20 +1499,20 @@ func testV1FIdxCaUpdateResourceProfileFromTP(t *testing.T) { }, } var result string - if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply engine.ResourceProfile - if err := tFIdxCaRpc.Call(utils.APIerSv1GetResourceProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}, &reply); err != nil { t.Error(err) } reply.FilterIDs = []string{"FLTR_RES_RCFG3"} reply.ActivationInterval = &utils.ActivationInterval{ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)} - if err := tFIdxCaRpc.Call(utils.APIerSv1SetResourceProfile, &engine.ResourceProfileWithAPIOpts{ResourceProfile: &reply}, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, &engine.ResourceProfileWithAPIOpts{ResourceProfile: &reply}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1529,7 +1530,7 @@ func testV1FIdxCaUpdateResourceProfileFromTP(t *testing.T) { utils.OptsResourcesUnits: 6, }, } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, &ev, &result); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &ev, &result); err != nil { t.Error(err) } else if result != "ResGroup1" { t.Error("Unexpected reply returned", result) @@ -1551,12 +1552,12 @@ func testV1FIdxCaRemoveResourceProfile(t *testing.T) { utils.OptsResourcesUnits: 6, }, } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AllocateResources, ev, &resp); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &resp); err != nil { t.Error(err) } else if resp != "MessageAllocation" { t.Error("Unexpected reply returned", resp) } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, &ev, &resp); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &ev, &resp); err != nil { t.Error(err) } else if resp != "MessageAllocation" { t.Error("Unexpected reply returned", resp) @@ -1574,31 +1575,31 @@ func testV1FIdxCaRemoveResourceProfile(t *testing.T) { utils.OptsResourcesUnits: 6, }, } - if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, &ev2, &resp); err != nil { + if err := tFIdxCaRpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &ev2, &resp); err != nil { t.Error(err) } else if resp != "ResGroup1" { t.Error("Unexpected reply returned", resp) } - if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveResourceProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1RemoveResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RCFG1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveResourceProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1RemoveResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } var sqp *engine.ThresholdProfile - if err := tFIdxCaRpc.Call(utils.APIerSv1GetResourceProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RCFG1"}, &sqp); err == nil && err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := tFIdxCaRpc.Call(utils.APIerSv1GetResourceProfile, + if err := tFIdxCaRpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}, &sqp); err == nil && err.Error() != utils.ErrNotFound.Error() { t.Error(err) diff --git a/apier/v1/filters.go b/apier/v1/filters.go index 15a7a98c6..a03098987 100644 --- a/apier/v1/filters.go +++ b/apier/v1/filters.go @@ -21,12 +21,13 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // SetFilter add a new Filter -func (apierSv1 *APIerSv1) SetFilter(arg *engine.FilterWithAPIOpts, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetFilter(ctx *context.Context, arg *engine.FilterWithAPIOpts, reply *string) (err error) { if missing := utils.MissingStructFields(arg.Filter, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -65,7 +66,7 @@ func (apierSv1 *APIerSv1) SetFilter(arg *engine.FilterWithAPIOpts, reply *string } // GetFilter returns a Filter -func (apierSv1 *APIerSv1) GetFilter(arg *utils.TenantID, reply *engine.Filter) error { +func (apierSv1 *APIerSv1) GetFilter(ctx *context.Context, arg *utils.TenantID, reply *engine.Filter) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -82,7 +83,7 @@ func (apierSv1 *APIerSv1) GetFilter(arg *utils.TenantID, reply *engine.Filter) e } // GetFilterIDs returns list of Filter IDs registered for a tenant -func (apierSv1 *APIerSv1) GetFilterIDs(args *utils.PaginatorWithTenant, fltrIDs *[]string) error { +func (apierSv1 *APIerSv1) GetFilterIDs(ctx *context.Context, args *utils.PaginatorWithTenant, fltrIDs *[]string) error { tnt := args.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -104,7 +105,7 @@ func (apierSv1 *APIerSv1) GetFilterIDs(args *utils.PaginatorWithTenant, fltrIDs } // RemoveFilter remove a specific filter -func (apierSv1 *APIerSv1) RemoveFilter(arg *utils.TenantIDWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) RemoveFilter(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/filters_it_test.go b/apier/v1/filters_it_test.go index bd332b983..a0feb85cc 100644 --- a/apier/v1/filters_it_test.go +++ b/apier/v1/filters_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" "os" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( filterCfgPath string filterCfg *config.CGRConfig - filterRPC *rpc.Client + filterRPC *birpc.Client filter *engine.FilterWithAPIOpts filterConfigDIR string //run tests for specific configuration @@ -118,7 +119,7 @@ func testFilterStartCPUProfiling(t *testing.T) { DirPath: "/tmp", } var reply string - if err := filterRPC.Call(utils.CoreSv1StartCPUProfiling, + if err := filterRPC.Call(context.Background(), utils.CoreSv1StartCPUProfiling, argPath, &reply); err != nil { t.Error(err) } @@ -126,7 +127,7 @@ func testFilterStartCPUProfiling(t *testing.T) { func testFilterGetFilterBeforeSet(t *testing.T) { var reply *engine.Filter - if err := filterRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || + if err := filterRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -152,7 +153,7 @@ func testFilterSetFilter(t *testing.T) { } var result string - if err := filterRPC.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := filterRPC.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -162,12 +163,12 @@ func testFilterSetFilter(t *testing.T) { func testFilterGetFilterIDs(t *testing.T) { expected := []string{"Filter1"} var result []string - if err := filterRPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &result); err != nil { + if err := filterRPC.Call(context.Background(), utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } - if err := filterRPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { + if err := filterRPC.Call(context.Background(), utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) @@ -176,7 +177,7 @@ func testFilterGetFilterIDs(t *testing.T) { func testFilterGetFilterAfterSet(t *testing.T) { var reply *engine.Filter - if err := filterRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil { + if err := filterRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(filter.Filter, reply) { t.Errorf("Expecting : %+v, received: %+v", filter.Filter, reply) @@ -197,7 +198,7 @@ func testFilterUpdateFilter(t *testing.T) { }, } var result string - if err := filterRPC.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := filterRPC.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -206,7 +207,7 @@ func testFilterUpdateFilter(t *testing.T) { func testFilterGetFilterAfterUpdate(t *testing.T) { var reply *engine.Filter - if err := filterRPC.Call(utils.APIerSv1GetFilter, + if err := filterRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(filter.Filter, reply) { @@ -216,7 +217,7 @@ func testFilterGetFilterAfterUpdate(t *testing.T) { func testFilterRemoveFilter(t *testing.T) { var resp string - if err := filterRPC.Call(utils.APIerSv1RemoveFilter, + if err := filterRPC.Call(context.Background(), utils.APIerSv1RemoveFilter, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -226,7 +227,7 @@ func testFilterRemoveFilter(t *testing.T) { func testFilterGetFilterAfterRemove(t *testing.T) { var reply *engine.Filter - if err := filterRPC.Call(utils.APIerSv1GetFilter, + if err := filterRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -257,14 +258,14 @@ func testFilterSetFilterWithoutTenant(t *testing.T) { }, } var reply string - if err := filterRPC.Call(utils.APIerSv1SetFilter, filter, &reply); err != nil { + if err := filterRPC.Call(context.Background(), utils.APIerSv1SetFilter, filter, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } var result *engine.Filter filter.Filter.Tenant = "cgrates.org" - if err := filterRPC.Call(utils.APIerSv1GetFilter, + if err := filterRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{ID: "FilterWithoutTenant"}, &result); err != nil { t.Error(err) @@ -275,7 +276,7 @@ func testFilterSetFilterWithoutTenant(t *testing.T) { func testFilterRemoveFilterWithoutTenant(t *testing.T) { var reply string - if err := filterRPC.Call(utils.APIerSv1RemoveFilter, + if err := filterRPC.Call(context.Background(), utils.APIerSv1RemoveFilter, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "FilterWithoutTenant"}}, &reply); err != nil { t.Error(err) @@ -283,7 +284,7 @@ func testFilterRemoveFilterWithoutTenant(t *testing.T) { t.Error("Unexpected reply returned", reply) } var result *engine.Filter - if err := filterRPC.Call(utils.APIerSv1GetFilter, + if err := filterRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{ID: "FilterWithoutTenant"}, &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -292,7 +293,7 @@ func testFilterRemoveFilterWithoutTenant(t *testing.T) { func testFilterStopCPUProfiling(t *testing.T) { var reply string - if err := filterRPC.Call(utils.CoreSv1StopCPUProfiling, + if err := filterRPC.Call(context.Background(), utils.CoreSv1StopCPUProfiling, new(utils.DirectoryArgs), &reply); err != nil { t.Error(err) } diff --git a/apier/v1/filters_test.go b/apier/v1/filters_test.go index 93cbca4ff..35ebaf582 100644 --- a/apier/v1/filters_test.go +++ b/apier/v1/filters_test.go @@ -24,6 +24,8 @@ import ( "sort" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -34,7 +36,7 @@ type ccMock struct { calls map[string]func(args any, reply any) error } -func (ccM *ccMock) Call(serviceMethod string, args any, reply any) (err error) { +func (ccM *ccMock) Call(ctx *context.Context, serviceMethod string, args any, reply any) (err error) { if call, has := ccM.calls[serviceMethod]; !has { return rpcclient.ErrUnsupporteServiceMethod } else { @@ -65,9 +67,9 @@ func TestFiltersSetFilterReloadCache(t *testing.T) { }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM - cM := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + cM := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) apierSv1 := &APIerSv1{ @@ -92,7 +94,7 @@ func TestFiltersSetFilterReloadCache(t *testing.T) { } var reply string - if err := apierSv1.SetFilter(arg, &reply); err != nil { + if err := apierSv1.SetFilter(context.Background(), arg, &reply); err != nil { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) } @@ -115,7 +117,7 @@ func TestFiltersSetFilterReloadCache(t *testing.T) { }, } - if err := apierSv1.SetAttributeProfile(attrPrf, &reply); err != nil { + if err := apierSv1.SetAttributeProfile(context.Background(), attrPrf, &reply); err != nil { t.Error(err) } @@ -131,7 +133,7 @@ func TestFiltersSetFilterReloadCache(t *testing.T) { }, } - if err := apierSv1.SetThresholdProfile(thPrf, &reply); err != nil { + if err := apierSv1.SetThresholdProfile(context.Background(), thPrf, &reply); err != nil { t.Error(err) } @@ -146,7 +148,7 @@ func TestFiltersSetFilterReloadCache(t *testing.T) { }, } - if err := apierSv1.SetResourceProfile(rsPrf, &reply); err != nil { + if err := apierSv1.SetResourceProfile(context.Background(), rsPrf, &reply); err != nil { t.Error(err) } @@ -161,7 +163,7 @@ func TestFiltersSetFilterReloadCache(t *testing.T) { }, } - if err := apierSv1.SetStatQueueProfile(sqPrf, &reply); err != nil { + if err := apierSv1.SetStatQueueProfile(context.Background(), sqPrf, &reply); err != nil { t.Error(err) } @@ -176,7 +178,7 @@ func TestFiltersSetFilterReloadCache(t *testing.T) { }, } - if err := apierSv1.SetDispatcherProfile(dpPrf, &reply); err != nil { + if err := apierSv1.SetDispatcherProfile(context.Background(), dpPrf, &reply); err != nil { t.Error(err) } @@ -191,7 +193,7 @@ func TestFiltersSetFilterReloadCache(t *testing.T) { }, } - if err := apierSv1.SetChargerProfile(chgPrf, &reply); err != nil { + if err := apierSv1.SetChargerProfile(context.Background(), chgPrf, &reply); err != nil { t.Error(err) } @@ -224,7 +226,7 @@ func TestFiltersSetFilterReloadCache(t *testing.T) { ThresholdFilterIndexIDs: []string{"cgrates.org:*string:*req.Account:1001", "cgrates.org:*string:*req.Account:1002"}, } - if err := apierSv1.SetFilter(arg, &reply); err != nil { + if err := apierSv1.SetFilter(context.Background(), arg, &reply); err != nil { t.Error(err) } @@ -256,9 +258,9 @@ func TestFiltersSetFilterClearCache(t *testing.T) { }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM - cM := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + cM := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) apierSv1 := &APIerSv1{ @@ -283,7 +285,7 @@ func TestFiltersSetFilterClearCache(t *testing.T) { } var reply string - if err := apierSv1.SetFilter(arg, &reply); err != nil { + if err := apierSv1.SetFilter(context.Background(), arg, &reply); err != nil { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) } @@ -306,7 +308,7 @@ func TestFiltersSetFilterClearCache(t *testing.T) { }, } - if err := apierSv1.SetAttributeProfile(attrPrf, &reply); err != nil { + if err := apierSv1.SetAttributeProfile(context.Background(), attrPrf, &reply); err != nil { t.Error(err) } @@ -322,7 +324,7 @@ func TestFiltersSetFilterClearCache(t *testing.T) { }, } - if err := apierSv1.SetThresholdProfile(thPrf, &reply); err != nil { + if err := apierSv1.SetThresholdProfile(context.Background(), thPrf, &reply); err != nil { t.Error(err) } @@ -337,7 +339,7 @@ func TestFiltersSetFilterClearCache(t *testing.T) { }, } - if err := apierSv1.SetResourceProfile(rsPrf, &reply); err != nil { + if err := apierSv1.SetResourceProfile(context.Background(), rsPrf, &reply); err != nil { t.Error(err) } @@ -352,7 +354,7 @@ func TestFiltersSetFilterClearCache(t *testing.T) { }, } - if err := apierSv1.SetStatQueueProfile(sqPrf, &reply); err != nil { + if err := apierSv1.SetStatQueueProfile(context.Background(), sqPrf, &reply); err != nil { t.Error(err) } @@ -367,7 +369,7 @@ func TestFiltersSetFilterClearCache(t *testing.T) { }, } - if err := apierSv1.SetDispatcherProfile(dpPrf, &reply); err != nil { + if err := apierSv1.SetDispatcherProfile(context.Background(), dpPrf, &reply); err != nil { t.Error(err) } @@ -382,7 +384,7 @@ func TestFiltersSetFilterClearCache(t *testing.T) { }, } - if err := apierSv1.SetChargerProfile(chgPrf, &reply); err != nil { + if err := apierSv1.SetChargerProfile(context.Background(), chgPrf, &reply); err != nil { t.Error(err) } @@ -412,7 +414,7 @@ func TestFiltersSetFilterClearCache(t *testing.T) { } sort.Strings(expArgs.CacheIDs) - if err := apierSv1.SetFilter(arg, &reply); err != nil { + if err := apierSv1.SetFilter(context.Background(), arg, &reply); err != nil { t.Error(err) } diff --git a/apier/v1/full_remote_it_test.go b/apier/v1/full_remote_it_test.go index 1a433a630..d0a8a2c25 100644 --- a/apier/v1/full_remote_it_test.go +++ b/apier/v1/full_remote_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,12 +38,12 @@ var ( fullRemInternalCfgPath string fullRemInternalCfgDirPath string fullRemInternalCfg *config.CGRConfig - fullRemInternalRPC *rpc.Client + fullRemInternalRPC *birpc.Client fullRemEngineOneCfgPath string fullRemEngineOneCfgDirPath string fullRemEngineOneCfg *config.CGRConfig - fullRemEngineOneRPC *rpc.Client + fullRemEngineOneRPC *birpc.Client sTestsFullRemoteIT = []func(t *testing.T){ testFullRemoteITInitCfg, @@ -122,7 +123,7 @@ func testFullRemoteITRPCConn(t *testing.T) { func testFullRemoteITAttribute(t *testing.T) { // verify for not found in internal var reply *engine.AttributeProfile - if err := fullRemInternalRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -145,13 +146,13 @@ func testFullRemoteITAttribute(t *testing.T) { } alsPrf.Compile() // add an attribute profile in engine1 and verify it internal - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}}, &reply); err != nil { t.Fatal(err) @@ -163,13 +164,13 @@ func testFullRemoteITAttribute(t *testing.T) { // update the attribute profile and verify it to be updated alsPrf.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"} alsPrf.Compile() - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}}, &reply); err != nil { t.Fatal(err) @@ -183,7 +184,7 @@ func testFullRemoteITAttribute(t *testing.T) { func testFullRemoteITStatQueue(t *testing.T) { // verify for not found in internal var reply *engine.StatQueueProfile - if err := fullRemInternalRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -217,13 +218,13 @@ func testFullRemoteITStatQueue(t *testing.T) { }, } // add a statQueue profile in engine1 and verify it internal - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetStatQueueProfile, stat, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, stat, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &reply); err != nil { t.Fatal(err) @@ -232,13 +233,13 @@ func testFullRemoteITStatQueue(t *testing.T) { } // update the statQueue profile and verify it to be updated stat.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"} - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetStatQueueProfile, stat, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, stat, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &reply); err != nil { t.Fatal(err) @@ -250,7 +251,7 @@ func testFullRemoteITStatQueue(t *testing.T) { func testFullRemoteITThreshold(t *testing.T) { // verify for not found in internal var reply *engine.ThresholdProfile - if err := fullRemInternalRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -275,13 +276,13 @@ func testFullRemoteITThreshold(t *testing.T) { }, } // add a threshold profile in engine1 and verify it internal - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &reply); err != nil { t.Fatal(err) @@ -290,13 +291,13 @@ func testFullRemoteITThreshold(t *testing.T) { } // update the threshold profile and verify it to be updated tPrfl.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"} - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &reply); err != nil { t.Fatal(err) @@ -308,7 +309,7 @@ func testFullRemoteITThreshold(t *testing.T) { func testFullRemoteITResource(t *testing.T) { // verify for not found in internal var reply *engine.ResourceProfile - if err := fullRemInternalRPC.Call(utils.APIerSv1GetResourceProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -332,13 +333,13 @@ func testFullRemoteITResource(t *testing.T) { }, } // add a threshold profile in engine1 and verify it internal - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetResourceProfile, rlsPrf, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsPrf, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetResourceProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}}, &reply); err != nil { t.Fatal(err) @@ -347,13 +348,13 @@ func testFullRemoteITResource(t *testing.T) { } // update the threshold profile and verify it to be updated rlsPrf.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"} - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetResourceProfile, rlsPrf, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsPrf, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetResourceProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}}, &reply); err != nil { t.Fatal(err) @@ -365,7 +366,7 @@ func testFullRemoteITResource(t *testing.T) { func testFullRemoteITRoute(t *testing.T) { // verify for not found in internal var reply *engine.RouteProfile - if err := fullRemInternalRPC.Call(utils.APIerSv1GetRouteProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -390,13 +391,13 @@ func testFullRemoteITRoute(t *testing.T) { Weight: 20, } // add a threshold profile in engine1 and verify it internal - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetRouteProfile, routePrf, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetRouteProfile, routePrf, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetRouteProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}}, &reply); err != nil { t.Fatal(err) @@ -405,13 +406,13 @@ func testFullRemoteITRoute(t *testing.T) { } // update the threshold profile and verify it to be updated routePrf.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"} - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetRouteProfile, routePrf, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetRouteProfile, routePrf, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetRouteProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}}, &reply); err != nil { t.Fatal(err) @@ -423,7 +424,7 @@ func testFullRemoteITRoute(t *testing.T) { func testFullRemoteITFilter(t *testing.T) { // verify for not found in internal var reply *engine.Filter - if err := fullRemInternalRPC.Call(utils.APIerSv1GetFilter, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetFilter, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ACNT_1001"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -445,13 +446,13 @@ func testFullRemoteITFilter(t *testing.T) { }, } // add a threshold profile in engine1 and verify it internal - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetFilter, fltr, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetFilter, fltr, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetFilter, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetFilter, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ACNT_1001"}}, &reply); err != nil { t.Fatal(err) @@ -471,13 +472,13 @@ func testFullRemoteITFilter(t *testing.T) { Values: []string{"10", "20"}, }, } - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetFilter, fltr, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetFilter, fltr, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetFilter, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetFilter, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ACNT_1001"}}, &reply); err != nil { t.Fatal(err) @@ -489,7 +490,7 @@ func testFullRemoteITFilter(t *testing.T) { func testFullRemoteITCharger(t *testing.T) { // verify for not found in internal var reply *engine.ChargerProfile - if err := fullRemInternalRPC.Call(utils.APIerSv1GetChargerProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -504,13 +505,13 @@ func testFullRemoteITCharger(t *testing.T) { Weight: 0, } // add a threshold profile in engine1 and verify it internal - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetChargerProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}}, &reply); err != nil { t.Fatal(err) @@ -519,13 +520,13 @@ func testFullRemoteITCharger(t *testing.T) { } // update the threshold profile and verify it to be updated chargerProfile.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"} - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetChargerProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}}, &reply); err != nil { t.Fatal(err) @@ -537,7 +538,7 @@ func testFullRemoteITCharger(t *testing.T) { func testFullRemoteITDispatcher(t *testing.T) { // verify for not found in internal var reply *engine.DispatcherProfile - if err := fullRemInternalRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Fatal(err) @@ -555,13 +556,13 @@ func testFullRemoteITDispatcher(t *testing.T) { }, } // add a threshold profile in engine1 and verify it internal - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &reply); err != nil { t.Fatal(err) @@ -570,13 +571,13 @@ func testFullRemoteITDispatcher(t *testing.T) { } // update the threshold profile and verify it to be updated dispatcherProfile.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"} - if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &replySet); err != nil { + if err := fullRemEngineOneRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &replySet); err != nil { t.Error(err) } else if replySet != utils.OK { t.Error("Unexpected reply returned", replySet) } - if err := fullRemInternalRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := fullRemInternalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &reply); err != nil { t.Fatal(err) diff --git a/apier/v1/guardian.go b/apier/v1/guardian.go index 6b260b8a7..15a0064ca 100644 --- a/apier/v1/guardian.go +++ b/apier/v1/guardian.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" @@ -31,25 +32,25 @@ func NewGuardianSv1() *GuardianSv1 { type GuardianSv1 struct{} // RemoteLock will lock a key from remote -func (self *GuardianSv1) RemoteLock(attr *dispatchers.AttrRemoteLockWithAPIOpts, reply *string) (err error) { +func (self *GuardianSv1) RemoteLock(ctx *context.Context, attr *dispatchers.AttrRemoteLockWithAPIOpts, reply *string) (err error) { *reply = guardian.Guardian.GuardIDs(attr.ReferenceID, attr.Timeout, attr.LockIDs...) return } // RemoteUnlock will unlock a key from remote based on reference ID -func (self *GuardianSv1) RemoteUnlock(refID *dispatchers.AttrRemoteUnlockWithAPIOpts, reply *[]string) (err error) { +func (self *GuardianSv1) RemoteUnlock(ctx *context.Context, refID *dispatchers.AttrRemoteUnlockWithAPIOpts, reply *[]string) (err error) { *reply = guardian.Guardian.UnguardIDs(refID.RefID) return } // Ping return pong if the service is active -func (self *GuardianSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (self *GuardianSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (self *GuardianSv1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (self *GuardianSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(self, serviceMethod, args, reply) } diff --git a/apier/v1/guardian_it_test.go b/apier/v1/guardian_it_test.go index ed431d7a5..6f24f8d50 100644 --- a/apier/v1/guardian_it_test.go +++ b/apier/v1/guardian_it_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/engine" @@ -80,11 +81,11 @@ func TestGuardianSIT(t *testing.T) { Timeout: 500 * time.Millisecond, } var reply string - if err = guardianRPC.Call(utils.GuardianSv1RemoteLock, &args, &reply); err != nil { + if err = guardianRPC.Call(context.Background(), utils.GuardianSv1RemoteLock, &args, &reply); err != nil { t.Error(err) } var unlockReply []string - if err = guardianRPC.Call(utils.GuardianSv1RemoteUnlock, &dispatchers.AttrRemoteUnlockWithAPIOpts{RefID: reply}, &unlockReply); err != nil { + if err = guardianRPC.Call(context.Background(), utils.GuardianSv1RemoteUnlock, &dispatchers.AttrRemoteUnlockWithAPIOpts{RefID: reply}, &unlockReply); err != nil { t.Error(err) } if !reflect.DeepEqual(args.LockIDs, unlockReply) { @@ -93,7 +94,7 @@ func TestGuardianSIT(t *testing.T) { // ping var resp string - if err = guardianRPC.Call(utils.GuardianSv1Ping, new(utils.CGREvent), &resp); err != nil { + if err = guardianRPC.Call(context.Background(), utils.GuardianSv1Ping, new(utils.CGREvent), &resp); err != nil { t.Error(err) } else if resp != utils.Pong { t.Error("Unexpected reply returned", resp) diff --git a/apier/v1/lib_test.go b/apier/v1/lib_test.go index e7d7c2efc..21e3f57ec 100644 --- a/apier/v1/lib_test.go +++ b/apier/v1/lib_test.go @@ -21,9 +21,9 @@ package v1 import ( "errors" "flag" - "net/rpc" - "net/rpc/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -35,12 +35,12 @@ var ( dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/apier/v1/libapier.go b/apier/v1/libapier.go index 1411c93d1..e90711984 100644 --- a/apier/v1/libapier.go +++ b/apier/v1/libapier.go @@ -21,6 +21,7 @@ package v1 import ( "strings" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -90,7 +91,7 @@ func (apierSv1 *APIerSv1) CallCache(cacheopt string, tnt, cacheID, itemID, group } } - return apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + return apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, method, args, &reply) } @@ -190,7 +191,7 @@ func (apierSv1 *APIerSv1) callCacheForRemoveIndexes(cacheopt string, tnt, cacheI APIOpts: opts, } } - return apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + return apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, method, args, &reply) } @@ -219,7 +220,7 @@ func (apierSv1 *APIerSv1) callCacheForComputeIndexes(cacheopt, tnt string, APIOpts: opts, } } - return apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + return apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, method, args, &reply) } @@ -250,7 +251,7 @@ func (apierSv1 *APIerSv1) callCacheMultiple(cacheopt, tnt, cacheID string, itemI APIOpts: opts, } } - return apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + return apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, method, args, &reply) } @@ -349,5 +350,5 @@ func callCacheForFilter(connMgr *engine.ConnManager, cacheConns []string, cacheo APIOpts: opts, } } - return connMgr.Call(cacheConns, nil, method, args, &reply) + return connMgr.Call(context.TODO(), cacheConns, method, args, &reply) } diff --git a/apier/v1/libapier_test.go b/apier/v1/libapier_test.go index be8231b59..3a7ac20d5 100644 --- a/apier/v1/libapier_test.go +++ b/apier/v1/libapier_test.go @@ -22,10 +22,11 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestComposeArgsReload(t *testing.T) { @@ -97,7 +98,7 @@ type rpcRequest struct { } type rpcMock chan *rpcRequest -func (r rpcMock) Call(method string, args, _ any) error { +func (r rpcMock) Call(_ *context.Context, method string, args, _ any) error { r <- &rpcRequest{ Method: method, Params: args, @@ -107,9 +108,9 @@ func (r rpcMock) Call(method string, args, _ any) error { func TestCallCache(t *testing.T) { cache := make(rpcMock, 1) - ch := make(chan rpcclient.ClientConnector, 1) + ch := make(chan birpc.ClientConnector, 1) ch <- cache - cn := engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{ + cn := engine.NewConnManager(config.CgrConfig(), map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): ch, }) cn.Reload() diff --git a/apier/v1/loaders.go b/apier/v1/loaders.go index a4999ca02..5d09ab219 100644 --- a/apier/v1/loaders.go +++ b/apier/v1/loaders.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/loaders" "github.com/cgrates/cgrates/utils" ) @@ -32,23 +33,23 @@ type LoaderSv1 struct { ldrS *loaders.LoaderService } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (ldrSv1 *LoaderSv1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (ldrSv1 *LoaderSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(ldrSv1, serviceMethod, args, reply) } -func (ldrSv1 *LoaderSv1) Load(args *loaders.ArgsProcessFolder, +func (ldrSv1 *LoaderSv1) Load(ctx *context.Context, args *loaders.ArgsProcessFolder, rply *string) error { - return ldrSv1.ldrS.V1Load(args, rply) + return ldrSv1.ldrS.V1Load(ctx, args, rply) } -func (ldrSv1 *LoaderSv1) Remove(args *loaders.ArgsProcessFolder, +func (ldrSv1 *LoaderSv1) Remove(ctx *context.Context, args *loaders.ArgsProcessFolder, rply *string) error { - return ldrSv1.ldrS.V1Remove(args, rply) + return ldrSv1.ldrS.V1Remove(ctx, args, rply) } -func (rsv1 *LoaderSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (rsv1 *LoaderSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } diff --git a/apier/v1/precache_it_test.go b/apier/v1/precache_it_test.go index d8d7fe051..f56f406f7 100644 --- a/apier/v1/precache_it_test.go +++ b/apier/v1/precache_it_test.go @@ -23,12 +23,13 @@ package v1 import ( "flag" - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ import ( var ( precacheCfgPath string precacheCfg *config.CGRConfig - precacheRPC *rpc.Client + precacheRPC *birpc.Client precacheConfigDIR string //run tests for specific configuration // use this flag to test the APIBan implementation for precache @@ -115,7 +116,7 @@ func testPrecacheGetItemIDs(t *testing.T) { CacheID: utils.MetaDefault, } var reply *[]string - if err := precacheRPC.Call(utils.CacheSv1GetItemIDs, args, &reply); err == nil || + if err := precacheRPC.Call(context.Background(), utils.CacheSv1GetItemIDs, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -128,7 +129,7 @@ func testPrecacheGetCacheStatsBeforeLoad(t *testing.T) { } dfltStats := engine.GetDefaultEmptyCacheStats() expectedStats := &dfltStats - if err := precacheRPC.Call(utils.CacheSv1GetCacheStats, args, &reply); err != nil { + if err := precacheRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, args, &reply); err != nil { t.Error(err.Error()) } else if !reflect.DeepEqual(reply, expectedStats) { t.Errorf("Expecting : %+v,\n received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(reply)) @@ -138,7 +139,7 @@ func testPrecacheGetCacheStatsBeforeLoad(t *testing.T) { func testPrecacheFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "precache")} - if err := precacheRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := precacheRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -230,7 +231,7 @@ func testPrecacheGetCacheStatsAfterRestart(t *testing.T) { if *apiBan { (*expectedStats)[utils.MetaAPIBan] = <cache.CacheStats{Items: 254} } - if err := precacheRPC.Call(utils.CacheSv1GetCacheStats, args, &reply); err != nil { + if err := precacheRPC.Call(context.Background(), utils.CacheSv1GetCacheStats, args, &reply); err != nil { t.Error(err.Error()) } else if !reflect.DeepEqual(reply, expectedStats) { t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(reply)) diff --git a/apier/v1/preload_it_test.go b/apier/v1/preload_it_test.go index 78a1a6e44..7c9bfb068 100644 --- a/apier/v1/preload_it_test.go +++ b/apier/v1/preload_it_test.go @@ -22,8 +22,6 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "os" "os/exec" "path" @@ -32,6 +30,9 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/utils" "github.com/cgrates/cgrates/config" @@ -42,7 +43,7 @@ var ( preloadCfgPath string preloadCfgDIR string preloadCfg *config.CGRConfig - preloadRPC *rpc.Client + preloadRPC *birpc.Client preloadTests = []func(t *testing.T){ testCreateDirs, @@ -148,7 +149,7 @@ func testPreloadITVerifyAttributes(t *testing.T) { } var reply *engine.AttributeProfile - if err := preloadRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := preloadRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ALS1"}}, &reply); err != nil { t.Fatal(err) } diff --git a/apier/v1/rals.go b/apier/v1/rals.go index ac1554d6f..68f85f765 100644 --- a/apier/v1/rals.go +++ b/apier/v1/rals.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/engine" @@ -33,13 +34,13 @@ func NewRALsV1() *RALsV1 { type RALsV1 struct { } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (rsv1 *RALsV1) Call(serviceMethod string, args any, reply any) error { +// Call implements birpc.ClientConnector interface for internal RPC +func (rsv1 *RALsV1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(rsv1, serviceMethod, args, reply) } // GetRatingPlansCost returns EventCosts matching RatingPlanIDs -func (rsv1 *RALsV1) GetRatingPlansCost(arg *utils.RatingPlanCostArg, reply *dispatchers.RatingPlanCost) error { +func (rsv1 *RALsV1) GetRatingPlansCost(ctx *context.Context, arg *utils.RatingPlanCostArg, reply *dispatchers.RatingPlanCost) error { if missing := utils.MissingStructFields(arg, []string{utils.RatingPlanIDs, utils.Destination, utils.SetupTime, utils.Usage}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) @@ -107,7 +108,7 @@ func (rsv1 *RALsV1) GetRatingPlansCost(arg *utils.RatingPlanCostArg, reply *disp return nil } -func (rsv1 *RALsV1) Ping(ign *utils.CGREvent, reply *string) error { +func (rsv1 *RALsV1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } diff --git a/apier/v1/rating_profile_late_it_test.go b/apier/v1/rating_profile_late_it_test.go index 70257c737..f54a26380 100644 --- a/apier/v1/rating_profile_late_it_test.go +++ b/apier/v1/rating_profile_late_it_test.go @@ -22,19 +22,21 @@ along with this program. If not, see package v1 import ( - "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/utils" - "net/rpc" "path" "testing" "time" + + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" ) var ( rpLateCfGPath string rpLateCfg *config.CGRConfig - rpLateRPC *rpc.Client + rpLateRPC *birpc.Client rpLateConfigDIR string //run tests for specific configuration rpLateAPIer = []func(t *testing.T){ @@ -110,7 +112,7 @@ func testRpLateRPCConn(t *testing.T) { func testRpLateLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := rpLateRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := rpLateRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -134,7 +136,7 @@ func testRpLateCDRProcessEvent(t *testing.T) { }, } var reply string - if err := rpLateRPC.Call(utils.CDRsV1ProcessCDR, args, &reply); err != nil { + if err := rpLateRPC.Call(context.Background(), utils.CDRsV1ProcessCDR, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("UNexpected reply returned") @@ -151,7 +153,7 @@ func testRpLateCDRProcessEvent(t *testing.T) { */ }} - if err := rpLateRPC.Call(utils.CDRsV1GetCDRs, &req, &replyy); err != nil { + if err := rpLateRPC.Call(context.Background(), utils.CDRsV1GetCDRs, &req, &replyy); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(replyy) != 2 { t.Error("Unexpected number of CDRs returned: ", len(replyy), "and CDRS: ", utils.ToJSON(replyy)) diff --git a/apier/v1/remote_it_test.go b/apier/v1/remote_it_test.go index a85cdcd3c..b5d4e08e3 100644 --- a/apier/v1/remote_it_test.go +++ b/apier/v1/remote_it_test.go @@ -21,13 +21,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,17 +38,17 @@ var ( internalCfgPath string internalCfgDirPath string internalCfg *config.CGRConfig - internalRPC *rpc.Client + internalRPC *birpc.Client engineOneCfgPath string engineOneCfgDirPath string engineOneCfg *config.CGRConfig - engineOneRPC *rpc.Client + engineOneRPC *birpc.Client engineTwoCfgPath string engineTwoCfgDirPath string engineTwoCfg *config.CGRConfig - engineTwoRPC *rpc.Client + engineTwoRPC *birpc.Client sTestsInternalRemoteIT = []func(t *testing.T){ testInternalRemoteITInitCfg, @@ -180,7 +181,7 @@ func testInternalRemoteITRPCConn(t *testing.T) { func testInternalRemoteLoadDataInEngineTwo(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := engineTwoRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -205,7 +206,7 @@ func testInternalRemoteITGetAccount(t *testing.T) { Account: "1001", } // make sure account exist in engine2 - if err := engineTwoRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.ID != expAcc.ID { t.Errorf("expecting: %+v, received: %+v", expAcc.ID, acnt.ID) @@ -213,7 +214,7 @@ func testInternalRemoteITGetAccount(t *testing.T) { t.Errorf("unexpected number of balances received: %+v", utils.ToJSON(acnt)) } // check the account in internal - if err := internalRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.ID != expAcc.ID { t.Errorf("expecting: %+v, received: %+v", expAcc.ID, acnt.ID) @@ -225,7 +226,7 @@ func testInternalRemoteITGetAccount(t *testing.T) { Tenant: "cgrates.org", Account: "nonexistAccount", } - if err := internalRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err == nil || + if err := internalRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expecting: %+v, received: %+v", utils.ErrNotFound, err) } @@ -248,7 +249,7 @@ func testInternalRemoteITGetAttribute(t *testing.T) { } alsPrf.Compile() var reply *engine.AttributeProfile - if err := internalRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}}, &reply); err != nil { t.Fatal(err) } @@ -264,7 +265,7 @@ func testInternalRemoteITGetAttribute(t *testing.T) { func testInternalRemoteITGetThreshold(t *testing.T) { var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1001"} - if err := internalRPC.Call(utils.ThresholdSv1GetThreshold, + if err := internalRPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd, td) { @@ -290,7 +291,7 @@ func testInternalRemoteITGetThresholdProfile(t *testing.T) { Async: true, }, } - if err := internalRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { @@ -305,14 +306,14 @@ func testInternalRemoteITGetResource(t *testing.T) { ID: "ResGroup1", Usages: map[string]*engine.ResourceUsage{}, } - if err := internalRPC.Call(utils.ResourceSv1GetResource, + if err := internalRPC.Call(context.Background(), utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expectedResources) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedResources), utils.ToJSON(reply)) } - if err := internalRPC.Call(utils.ResourceSv1GetResource, + if err := internalRPC.Call(context.Background(), utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "ResGroup1"}}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expectedResources) { @@ -338,7 +339,7 @@ func testInternalRemoteITGetResourceProfile(t *testing.T) { }, } var reply *engine.ResourceProfile - if err := internalRPC.Call(utils.APIerSv1GetResourceProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rlsPrf.ID}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, rlsPrf.ResourceProfile) { @@ -395,7 +396,7 @@ func testInternalRemoteITGetStatQueueProfile(t *testing.T) { ThresholdIDs: []string{utils.MetaNone}, } var reply *engine.StatQueueProfile - if err := internalRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats2"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expStq, reply) && !reflect.DeepEqual(reply, expStq2) { @@ -449,7 +450,7 @@ func testInternalRemoteITGetRoute(t *testing.T) { routePrf2.SortingParameters = nil } - if err := internalRPC.Call(utils.APIerSv1GetRouteProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(routePrf, reply) && !reflect.DeepEqual(routePrf2, reply) { @@ -473,7 +474,7 @@ func testInternalRemoteITGetFilter(t *testing.T) { }, } var reply *engine.Filter - if err := internalRPC.Call(utils.APIerSv1GetFilter, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ACNT_1001"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expFltr, reply) { @@ -483,7 +484,7 @@ func testInternalRemoteITGetFilter(t *testing.T) { func testInternalRemoteITGetRatingPlan(t *testing.T) { var reply engine.RatingPlan - if err := internalRPC.Call(utils.APIerSv1GetRatingPlan, utils.StringPointer("RP_1001"), &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetRatingPlan, utils.StringPointer("RP_1001"), &reply); err != nil { t.Error(err.Error()) } else if reply.Id != "RP_1001" { t.Errorf("Expected: %+v, received: %+v", "RP_1001", reply.Id) @@ -515,7 +516,7 @@ func testInternalRemoteITGetRatingProfile(t *testing.T) { }, }, } - if err := internalRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rpl) { t.Errorf("Expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) @@ -529,7 +530,7 @@ func testInternalRemoteITGetAction(t *testing.T) { BalanceDisabled: "false", ExpiryTime: utils.MetaUnlimited, Weight: 10.0}} var reply []*utils.TPAction - if err := internalRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACT_TOPUP_RST_10"), &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACT_TOPUP_RST_10"), &reply); err != nil { t.Error("Got error on APIerSv1.GetActions: ", err.Error()) } else if !reflect.DeepEqual(expectActs, reply) { t.Errorf("Expected: %v,\n received: %v", utils.ToJSON(expectActs), utils.ToJSON(reply)) @@ -538,7 +539,7 @@ func testInternalRemoteITGetAction(t *testing.T) { func testInternalRemoteITGetActionPlan(t *testing.T) { var aps []*engine.ActionPlan - if err := internalRPC.Call(utils.APIerSv1GetActionPlan, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, &AttrGetActionPlan{ID: "AP_PACKAGE_10"}, &aps); err != nil { t.Error(err) } else if len(aps) != 1 { @@ -546,7 +547,7 @@ func testInternalRemoteITGetActionPlan(t *testing.T) { } else if aps[0].Id != "AP_PACKAGE_10" { t.Errorf("Expected: %v,\n received: %v", "AP_PACKAGE_10", aps[0].Id) } - if err := internalRPC.Call(utils.APIerSv1GetActionPlan, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, &AttrGetActionPlan{ID: utils.EmptyString}, &aps); err != nil { t.Error(err) } else if len(aps) != 1 { @@ -562,7 +563,7 @@ func testInternalRemoteITGetDestination(t *testing.T) { Id: "DST_1002", Prefixes: []string{"1002"}, } - if err := internalRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("DST_1002"), &dst); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetDestination, utils.StringPointer("DST_1002"), &dst); err != nil { t.Error(err) } else if !reflect.DeepEqual(eDst, dst) { t.Errorf("Expected: %v,\n received: %v", eDst, dst) @@ -572,7 +573,7 @@ func testInternalRemoteITGetDestination(t *testing.T) { func testInternalRemoteITGetReverseDestination(t *testing.T) { var ids []string eIDs := []string{"DST_1002"} - if err := internalRPC.Call(utils.APIerSv1GetReverseDestination, utils.StringPointer("1002"), &ids); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetReverseDestination, utils.StringPointer("1002"), &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(eIDs, ids) { t.Errorf("Expected: %v,\n received: %v", eIDs, ids) @@ -591,7 +592,7 @@ func testInternalRemoteITGetChargerProfile(t *testing.T) { chargerProfile.FilterIDs = nil } var reply *engine.ChargerProfile - if err := internalRPC.Call(utils.APIerSv1GetChargerProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile, reply) { @@ -601,7 +602,7 @@ func testInternalRemoteITGetChargerProfile(t *testing.T) { func testInternalRemoteITGetDispatcherProfile(t *testing.T) { var reply string - if err := internalRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Error(err) @@ -618,7 +619,7 @@ func testInternalRemoteITGetDispatcherProfile(t *testing.T) { }, } - if err := engineTwoRPC.Call(utils.APIerSv1SetDispatcherProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil { t.Error(err) @@ -627,7 +628,7 @@ func testInternalRemoteITGetDispatcherProfile(t *testing.T) { } var dsp *engine.DispatcherProfile - if err := internalRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err != nil { t.Error(err) @@ -638,7 +639,7 @@ func testInternalRemoteITGetDispatcherProfile(t *testing.T) { func testInternalRemoteITGetDispatcherHost(t *testing.T) { var reply string - if err := internalRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { t.Error(err) @@ -654,7 +655,7 @@ func testInternalRemoteITGetDispatcherHost(t *testing.T) { }, } - if err := engineTwoRPC.Call(utils.APIerSv1SetDispatcherHost, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1SetDispatcherHost, dispatcherHost, &reply); err != nil { t.Error(err) @@ -663,7 +664,7 @@ func testInternalRemoteITGetDispatcherHost(t *testing.T) { } var dsp *engine.DispatcherHost - if err := internalRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}, &dsp); err != nil { t.Error(err) @@ -675,7 +676,7 @@ func testInternalRemoteITGetDispatcherHost(t *testing.T) { func testInternalReplicationSetThreshold(t *testing.T) { var reply *engine.ThresholdProfile var result string - if err := internalRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -684,7 +685,7 @@ func testInternalReplicationSetThreshold(t *testing.T) { var indexes []string expectedIDX := []string{"*string:*req.Account:1001:THD_ACNT_1001", "*string:*req.Account:1002:THD_ACNT_1002"} - if err := engineTwoRPC.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: "cgrates.org", FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -695,7 +696,7 @@ func testInternalReplicationSetThreshold(t *testing.T) { expectedIDX, utils.ToJSON(indexes)) } //verify indexes on internal before adding new threshold profile - if err := internalRPC.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: "cgrates.org", FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -722,13 +723,13 @@ func testInternalReplicationSetThreshold(t *testing.T) { Async: true, }, } - if err := internalRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } time.Sleep(50 * time.Millisecond) - if err := internalRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { @@ -742,7 +743,7 @@ func testInternalReplicationSetThreshold(t *testing.T) { } // verify index on internal sort.Strings(expectedIDX) - if err := internalRPC.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: "cgrates.org", FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -753,7 +754,7 @@ func testInternalReplicationSetThreshold(t *testing.T) { expectedIDX, utils.ToJSON(indexes)) } // verify data on engine1 - if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { @@ -765,7 +766,7 @@ func testInternalReplicationSetThreshold(t *testing.T) { "*string:*req.CustomField:CustomValue:THD_Replication", } // verify indexes on engine1 (should be the same as internal) - if err := engineOneRPC.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: "cgrates.org", FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -776,7 +777,7 @@ func testInternalReplicationSetThreshold(t *testing.T) { expectedIDX2, utils.ToJSON(indexes)) } // verify data on engine2 - if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { @@ -788,7 +789,7 @@ func testInternalReplicationSetThreshold(t *testing.T) { "*string:*req.CustomField:CustomValue:THD_Replication", } // check if indexes was created correctly on engine2 - if err := engineTwoRPC.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{ ItemType: utils.MetaThresholds, Tenant: "cgrates.org", FilterType: utils.MetaString}, &indexes); err != nil { t.Error(err) @@ -811,7 +812,7 @@ func testInternalMatchThreshold(t *testing.T) { } var ids []string eIDs := []string{"THD_ACNT_1002"} - if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { + if err := internalRPC.Call(context.Background(), utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -824,7 +825,7 @@ func testInternalMatchThreshold(t *testing.T) { }, } eIDs = []string{"THD_ACNT_1001"} - if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { + if err := internalRPC.Call(context.Background(), utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -836,7 +837,7 @@ func testInternalMatchThreshold(t *testing.T) { utils.AccountField: "1001", }, } - if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, ev2, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := internalRPC.Call(context.Background(), utils.ThresholdSv1ProcessEvent, ev2, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -853,7 +854,7 @@ func testInternalAccountBalanceOperations(t *testing.T) { utils.ID: "testAccSetBalance", }, } - if err := internalRPC.Call(utils.APIerSv1SetBalance, attrs, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetBalance, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -863,7 +864,7 @@ func testInternalAccountBalanceOperations(t *testing.T) { Account: "testAccount1", } // verify account on engineOne - if err := engineOneRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaMonetary]) != 1 { t.Errorf("Expecting: %+v, received: %+v", @@ -874,7 +875,7 @@ func testInternalAccountBalanceOperations(t *testing.T) { } // verify account on engineTwo - if err := engineTwoRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaMonetary]) != 1 { t.Errorf("Expecting: %+v, received: %+v", @@ -885,7 +886,7 @@ func testInternalAccountBalanceOperations(t *testing.T) { } // debit balance on internal and the account should be replicated to other engines - if err := internalRPC.Call(utils.APIerSv1DebitBalance, &AttrAddBalance{ + if err := internalRPC.Call(context.Background(), utils.APIerSv1DebitBalance, &AttrAddBalance{ Tenant: "cgrates.org", Account: "testAccount1", BalanceType: utils.MetaMonetary, @@ -897,7 +898,7 @@ func testInternalAccountBalanceOperations(t *testing.T) { } time.Sleep(50 * time.Millisecond) // verify debited account on engineOne - if err := engineOneRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaMonetary]) != 1 { t.Errorf("Expecting: %+v, received: %+v", @@ -908,7 +909,7 @@ func testInternalAccountBalanceOperations(t *testing.T) { } // verify debited account on engineTwo - if err := engineTwoRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaMonetary]) != 1 { t.Errorf("Expecting: %+v, received: %+v", @@ -925,12 +926,12 @@ func testInternalAccountBalanceOperations(t *testing.T) { Value: 12.765, } // add balance for the account on internal and this should be replicated to other engines - if err := internalRPC.Call(utils.APIerSv1AddBalance, addBal, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1AddBalance, addBal, &reply); err != nil { t.Error(err) } time.Sleep(50 * time.Millisecond) // verify account on engineOne - if err := engineOneRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaMonetary]) != 1 { t.Errorf("Expecting: %+v, received: %+v", @@ -941,7 +942,7 @@ func testInternalAccountBalanceOperations(t *testing.T) { } // verify account on engineTwo - if err := engineTwoRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaMonetary]) != 1 { t.Errorf("Expecting: %+v, received: %+v", @@ -956,7 +957,7 @@ func testInternalAccountBalanceOperations(t *testing.T) { func testInternalSetAccount(t *testing.T) { var reply string - if err := internalRPC.Call(utils.APIerSv1SetAccount, + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetAccount, utils.AttrSetAccount{ Tenant: "cgrates.org", Account: "testSetAccount", @@ -974,7 +975,7 @@ func testInternalSetAccount(t *testing.T) { Account: "testSetAccount", } // verify account on engineOne - if err := engineOneRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaMonetary]) != 1 { t.Errorf("Expecting: %+v, received: %+v", @@ -985,7 +986,7 @@ func testInternalSetAccount(t *testing.T) { } // verify account on engineTwo - if err := engineTwoRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap[utils.MetaMonetary]) != 1 { t.Errorf("Expecting: %+v, received: %+v", @@ -1023,20 +1024,20 @@ func testInternalReplicateStats(t *testing.T) { }, } - if err := internalRPC.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } var rcv *engine.StatQueueProfile - if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "StatsToReplicate"}, &rcv); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, rcv) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(rcv)) } - if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "StatsToReplicate"}, &rcv); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, rcv) { diff --git a/apier/v1/replicate_it_test.go b/apier/v1/replicate_it_test.go index 90ccef2da..394bb5ee8 100644 --- a/apier/v1/replicate_it_test.go +++ b/apier/v1/replicate_it_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -148,7 +149,7 @@ func testInternalReplicateITRPCConn(t *testing.T) { func testInternalReplicateLoadDataInInternalEngine(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := internalRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -157,16 +158,16 @@ func testInternalReplicateLoadDataInInternalEngine(t *testing.T) { func testInternalReplicateITDestination(t *testing.T) { //check rpl := &engine.Destination{} - if err := engineOneRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } //set attrs := utils.AttrSetDestination{Id: "testDestination", Prefixes: []string{"004", "005"}} var reply string - if err := internalRPC.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetDestination, &attrs, &reply); err != nil { t.Error("Unexpected error", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -176,12 +177,12 @@ func testInternalReplicateITDestination(t *testing.T) { Prefixes: []string{"004", "005"}, } // check - if err := engineOneRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(eDst, rpl) { t.Errorf("Expected: %v,\n received: %v", eDst, rpl) } - if err := engineTwoRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(eDst, rpl) { t.Errorf("Expected: %v,\n received: %v", eDst, rpl) @@ -189,16 +190,16 @@ func testInternalReplicateITDestination(t *testing.T) { // remove attr := &AttrRemoveDestination{DestinationIDs: []string{"testDestination"}, Prefixes: []string{"004", "005"}} - if err := internalRPC.Call(utils.APIerSv1RemoveDestination, &attr, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveDestination, &attr, &reply); err != nil { t.Error("Unexpected error", err.Error()) } else if reply != utils.OK { t.Errorf("Unexpected reply returned: %+v", reply) } // check - if err := engineOneRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } @@ -230,14 +231,14 @@ func testInternalReplicateITAttributeProfile(t *testing.T) { } alsPrf.Compile() var result string - if err := internalRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } // check var reply *engine.AttributeProfile - if err := engineOneRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err != nil { t.Fatal(err) } @@ -245,7 +246,7 @@ func testInternalReplicateITAttributeProfile(t *testing.T) { if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) { t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply) } - if err := engineTwoRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err != nil { t.Fatal(err) } @@ -255,18 +256,18 @@ func testInternalReplicateITAttributeProfile(t *testing.T) { } reply = &engine.AttributeProfile{} //remove - if err := internalRPC.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //check again - if err := engineOneRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err) } @@ -279,10 +280,10 @@ func testInternalReplicateITRatingProfile(t *testing.T) { Tenant: "cgrates.org", Category: "call", Subject: "Subject"} - if err := engineOneRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err) } // set @@ -298,13 +299,13 @@ func testInternalReplicateITRatingProfile(t *testing.T) { RatingPlanId: "RP_1001", FallbackSubjects: "FallbackSubjects"}, }} - if err := internalRPC.Call(utils.APIerSv1SetRatingProfile, &attrSetRatingProfile, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetRatingProfile, &attrSetRatingProfile, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(reply) } // Calling the second time should not raise EXISTS - if err := internalRPC.Call(utils.APIerSv1SetRatingProfile, &attrSetRatingProfile, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetRatingProfile, &attrSetRatingProfile, &reply); err != nil { t.Error(err) } //check @@ -322,12 +323,12 @@ func testInternalReplicateITRatingProfile(t *testing.T) { }, }, } - if err := engineOneRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rpl) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) } - if err := engineTwoRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingProfile, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rpl) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) @@ -337,12 +338,12 @@ func testInternalReplicateITRatingProfile(t *testing.T) { func testInternalReplicateITRouteProfile(t *testing.T) { // check var reply *engine.RouteProfile - if err := engineOneRPC.Call(utils.APIerSv1GetRouteProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetRouteProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -370,19 +371,19 @@ func testInternalReplicateITRouteProfile(t *testing.T) { } // set var result string - if err := internalRPC.Call(utils.APIerSv1SetRouteProfile, rPrf, &result); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetRouteProfile, rPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } // check - if err := engineOneRPC.Call(utils.APIerSv1GetRouteProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rPrf.RouteProfile, reply) { t.Errorf("Expecting: %+v, received: %+v", rPrf.RouteProfile, reply) } - if err := engineTwoRPC.Call(utils.APIerSv1GetRouteProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rPrf.RouteProfile, reply) { @@ -390,19 +391,19 @@ func testInternalReplicateITRouteProfile(t *testing.T) { } // remove var resp string - if err := internalRPC.Call(utils.APIerSv1RemoveRouteProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveRouteProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } // check - if err := engineOneRPC.Call(utils.APIerSv1GetRouteProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetRouteProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -412,12 +413,12 @@ func testInternalReplicateITRouteProfile(t *testing.T) { func testInternalReplicateITStatQueueProfile(t *testing.T) { // check var reply *engine.StatQueueProfile - if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -449,38 +450,38 @@ func testInternalReplicateITStatQueueProfile(t *testing.T) { }, } var result string - if err := internalRPC.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //check - if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { t.Errorf("Expecting: %+v, received: %+v", statConfig.StatQueueProfile, reply) } - if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { t.Errorf("Expecting: %+v, received: %+v", statConfig.StatQueueProfile, reply) } //remove - if err := internalRPC.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } // check - if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -490,12 +491,12 @@ func testInternalReplicateITStatQueueProfile(t *testing.T) { func testInternalReplicateITDispatcherProfile(t *testing.T) { // check var reply string - if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Error(err) @@ -511,7 +512,7 @@ func testInternalReplicateITDispatcherProfile(t *testing.T) { Weight: 20, }, } - if err := internalRPC.Call(utils.APIerSv1SetDispatcherProfile, dispatcherProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -519,14 +520,14 @@ func testInternalReplicateITDispatcherProfile(t *testing.T) { } // check var dsp *engine.DispatcherProfile - if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err != nil { t.Error(err) } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, dsp) { t.Errorf("Expecting : %+v, received: %+v", dispatcherProfile.DispatcherProfile, dsp) } - if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err != nil { t.Error(err) @@ -535,23 +536,23 @@ func testInternalReplicateITDispatcherProfile(t *testing.T) { } // remove var result string - if err := internalRPC.Call(utils.APIerSv1RemoveDispatcherProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Errorf("Expecting : %+v, received: %+v", utils.OK, result) } // remove again - if err := internalRPC.Call(utils.APIerSv1RemoveDispatcherProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &result); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Error(err) } // check again - if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Error(err) } @@ -560,11 +561,11 @@ func testInternalReplicateITDispatcherProfile(t *testing.T) { func testInternalReplicateITChargerProfile(t *testing.T) { // check var reply *engine.ChargerProfile - if err := engineOneRPC.Call(utils.APIerSv1GetChargerProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetChargerProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -584,38 +585,38 @@ func testInternalReplicateITChargerProfile(t *testing.T) { }, } var result string - if err := internalRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } // check - if err := engineOneRPC.Call(utils.APIerSv1GetChargerProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) { t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, reply) } - if err := engineTwoRPC.Call(utils.APIerSv1GetChargerProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) { t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, reply) } // remove - if err := internalRPC.Call(utils.APIerSv1RemoveChargerProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //check - if err := engineOneRPC.Call(utils.APIerSv1GetChargerProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetChargerProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -625,12 +626,12 @@ func testInternalReplicateITChargerProfile(t *testing.T) { func testInternalReplicateITDispatcherHost(t *testing.T) { // check var reply string - if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { t.Error(err) @@ -645,7 +646,7 @@ func testInternalReplicateITDispatcherHost(t *testing.T) { }, } //set - if err := internalRPC.Call(utils.APIerSv1SetDispatcherHost, + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetDispatcherHost, dispatcherHost, &reply); err != nil { t.Error(err) @@ -654,14 +655,14 @@ func testInternalReplicateITDispatcherHost(t *testing.T) { } // check var dsp *engine.DispatcherHost - if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}, &dsp); err != nil { t.Error(err) } else if !reflect.DeepEqual(dispatcherHost.DispatcherHost, dsp) { t.Errorf("Expecting : %+v, received: %+v", dispatcherHost.DispatcherHost, dsp) } - if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}, &dsp); err != nil { t.Error(err) @@ -669,7 +670,7 @@ func testInternalReplicateITDispatcherHost(t *testing.T) { t.Errorf("Expecting : %+v, received: %+v", dispatcherHost.DispatcherHost, dsp) } // remove - if err := internalRPC.Call(utils.APIerSv1RemoveDispatcherHost, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherHost, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}}, &reply); err != nil { t.Error(err) @@ -677,12 +678,12 @@ func testInternalReplicateITDispatcherHost(t *testing.T) { t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply) } //check - if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}, &dsp); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}, &dsp); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { t.Error(err) @@ -692,10 +693,10 @@ func testInternalReplicateITDispatcherHost(t *testing.T) { func testInternalReplicateITFilter(t *testing.T) { // check var reply *engine.Filter - if err := engineOneRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } //set @@ -717,35 +718,35 @@ func testInternalReplicateITFilter(t *testing.T) { }, } var rcv string - if err := internalRPC.Call(utils.APIerSv1SetFilter, filter, &rcv); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetFilter, filter, &rcv); err != nil { t.Error(err) } else if rcv != utils.OK { t.Error("Unexpected reply returned", rcv) } // check - if err := engineOneRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(filter.Filter, reply) { t.Errorf("Expecting : %+v, received: %+v", filter.Filter, reply) } - if err := engineTwoRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(filter.Filter, reply) { t.Errorf("Expecting : %+v, received: %+v", filter.Filter, reply) } // remove var resp string - if err := internalRPC.Call(utils.APIerSv1RemoveFilter, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveFilter, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } // check again - if err := engineOneRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } @@ -753,11 +754,11 @@ func testInternalReplicateITFilter(t *testing.T) { func testInternalReplicateITResourceProfile(t *testing.T) { // check var reply *engine.ResourceProfile - if err := engineOneRPC.Call(utils.APIerSv1GetResourceProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetResourceProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -782,37 +783,37 @@ func testInternalReplicateITResourceProfile(t *testing.T) { } var result string - if err := internalRPC.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } // check - if err := engineOneRPC.Call(utils.APIerSv1GetResourceProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, rlsConfig.ResourceProfile) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(rlsConfig.ResourceProfile), utils.ToJSON(reply)) } - if err := engineTwoRPC.Call(utils.APIerSv1GetResourceProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, rlsConfig.ResourceProfile) { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(rlsConfig.ResourceProfile), utils.ToJSON(reply)) } // remove - if err := internalRPC.Call(utils.APIerSv1RemoveResourceProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } // check again - if err := engineOneRPC.Call(utils.APIerSv1GetResourceProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetResourceProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -821,10 +822,10 @@ func testInternalReplicateITResourceProfile(t *testing.T) { func testInternalReplicateITActions(t *testing.T) { // check var reply1 []*utils.TPAction - if err := engineOneRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { t.Error(err) } // set @@ -837,12 +838,12 @@ func testInternalReplicateITActions(t *testing.T) { ExpiryTime: utils.MetaUnlimited, Weight: 20.0}}} var reply string - if err := internalRPC.Call(utils.APIerSv1SetActions, &attrs1, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetActions, &attrs1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply returned: %s", reply) } - if err := internalRPC.Call(utils.APIerSv1SetActions, &attrs1, &reply); err == nil || err.Error() != "EXISTS" { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetActions, &attrs1, &reply); err == nil || err.Error() != "EXISTS" { t.Error("Unexpected result on duplication: ", err) } // check @@ -856,23 +857,23 @@ func testInternalReplicateITActions(t *testing.T) { ExpiryTime: utils.MetaUnlimited, Weight: 20.0, }} - if err := internalRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil { t.Error("Got error on APIerSv1.GetActions: ", err.Error()) } else if !reflect.DeepEqual(eOut, reply1) { t.Errorf("Expected: %v, received: %v", utils.ToJSON(eOut), utils.ToJSON(reply1)) } - if err := engineOneRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil { t.Error("Got error on APIerSv1.GetActions: ", err.Error()) } else if !reflect.DeepEqual(eOut, reply1) { t.Errorf("Expected: %v, received: %v", utils.ToJSON(eOut), utils.ToJSON(reply1)) } - if err := engineTwoRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil { t.Error("Got error on APIerSv1.GetActions: ", err.Error()) } else if !reflect.DeepEqual(eOut, reply1) { t.Errorf("Expected: %v, received: %v", utils.ToJSON(eOut), utils.ToJSON(reply1)) } // remove - if err := internalRPC.Call(utils.APIerSv1RemoveActions, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveActions, &AttrRemoveActions{ ActionIDs: []string{"ACTS_1"}}, &reply); err != nil { t.Error("Got error on APIerSv1.RemoveActions: ", err.Error()) @@ -880,10 +881,10 @@ func testInternalReplicateITActions(t *testing.T) { t.Error("Unexpected reply when calling APIerSv1.RemoveActions: ", err.Error()) } // check again - if err := engineOneRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { t.Error(err) } @@ -891,7 +892,7 @@ func testInternalReplicateITActions(t *testing.T) { func testInternalReplicateITActionPlan(t *testing.T) { var reply string - if err := internalRPC.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{ + if err := internalRPC.Call(context.Background(), utils.APIerSv2SetActions, &utils.AttrSetActions{ ActionsId: "ACTS_1", Actions: []*utils.TPAction{{Identifier: utils.MetaLog}}, }, &reply); err != nil && err.Error() != utils.ErrExists.Error() { @@ -901,11 +902,11 @@ func testInternalReplicateITActionPlan(t *testing.T) { } // check var aps []*engine.ActionPlan - if err := engineOneRPC.Call(utils.APIerSv1GetActionPlan, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error at APIerSv1.GetActionPlan: %+v", err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetActionPlan, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error at APIerSv1.GetActionPlan: %+v", err) } @@ -920,13 +921,13 @@ func testInternalReplicateITActionPlan(t *testing.T) { }, } var reply1 string - if err := internalRPC.Call(utils.APIerSv1SetActionPlan, &atms1, &reply1); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &atms1, &reply1); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply1 != utils.OK { t.Errorf("Unexpected reply returned: %s", reply1) } // check - if err := engineOneRPC.Call(utils.APIerSv1GetActionPlan, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err != nil { t.Error(err) } else if len(aps) != 1 { @@ -938,7 +939,7 @@ func testInternalReplicateITActionPlan(t *testing.T) { } else if aps[0].ActionTimings[0].Weight != 20.0 { t.Errorf("Expected: 20.0,\n received: %v", aps[0].ActionTimings[0].Weight) } - if err := engineTwoRPC.Call(utils.APIerSv1GetActionPlan, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err != nil { t.Error(err) } else if len(aps) != 1 { @@ -951,18 +952,18 @@ func testInternalReplicateITActionPlan(t *testing.T) { t.Errorf("Expected: 20.0,\n received: %v", aps[0].ActionTimings[0].Weight) } // remove - if err := internalRPC.Call(utils.APIerSv1RemoveActionPlan, &AttrGetActionPlan{ + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveActionPlan, &AttrGetActionPlan{ ID: "ATMS_1"}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } //check again - if err := engineOneRPC.Call(utils.APIerSv1GetActionPlan, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error: %+v, rcv: %+v", err, utils.ToJSON(aps)) } - if err := engineTwoRPC.Call(utils.APIerSv1GetActionPlan, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, &AttrGetActionPlan{ID: "ATMS_1"}, &aps); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error: %+v, rcv: %+v", err, utils.ToJSON(aps)) } @@ -971,12 +972,12 @@ func testInternalReplicateITActionPlan(t *testing.T) { func testInternalReplicateITThresholdProfile(t *testing.T) { // check var reply *engine.ThresholdProfile - if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -998,7 +999,7 @@ func testInternalReplicateITThresholdProfile(t *testing.T) { }, } var result string - if err := internalRPC.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1020,38 +1021,38 @@ func testInternalReplicateITThresholdProfile(t *testing.T) { Async: true, }, } - if err := internalRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } // check - if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply) } - if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply) } // remove - if err := internalRPC.Call(utils.APIerSv1RemoveThresholdProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } // check again - if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1067,12 +1068,12 @@ func testInternalReplicateITSetAccount(t *testing.T) { } //check var reply string - if err := engineOneRPC.Call(utils.APIerSv1GetAccount, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetAccount, &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetAccount, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetAccount, &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1081,7 +1082,7 @@ func testInternalReplicateITSetAccount(t *testing.T) { attrSetAccount := &utils.AttrSetAccount{ Account: "AccountTest", Tenant: tenant} - if err := internalRPC.Call(utils.APIerSv1SetAccount, attrSetAccount, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetAccount, attrSetAccount, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -1089,28 +1090,28 @@ func testInternalReplicateITSetAccount(t *testing.T) { //check tmp := engine.Account{} rcvAccount := tmp.AsOldStructure() - if err := engineOneRPC.Call(utils.APIerSv1GetAccount, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetAccount, &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &rcvAccount); err != nil { t.Errorf("Unexpected error : %+v\nRCV: %+v", err, rcvAccount) } - if err := engineTwoRPC.Call(utils.APIerSv1GetAccount, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetAccount, &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &rcvAccount); err != nil { t.Errorf("Unexpected error : %+v", err) } //remove - if err := internalRPC.Call(utils.APIerSv1RemoveAccount, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ Account: "AccountTest", Tenant: tenant}, &reply); err != nil { t.Errorf("Unexpected error : %+v", err) } //check - if err := engineOneRPC.Call(utils.APIerSv1GetAccount, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetAccount, &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetAccount, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetAccount, &utils.AttrGetAccount{Account: "AccountTest", Tenant: tenant}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1120,11 +1121,11 @@ func testInternalReplicateITSetAccount(t *testing.T) { func testInternalReplicateITActionTrigger(t *testing.T) { // check var atrs engine.ActionTriggers - if err := engineOneRPC.Call(utils.APIerSv1GetActionTriggers, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error("Got error on APIerSv1.GetActionTriggers: ", err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetActionTriggers, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error("Got error on APIerSv1.GetActionTriggers: ", err) } @@ -1137,13 +1138,13 @@ func testInternalReplicateITActionTrigger(t *testing.T) { utils.BalanceID: utils.StringPointer("BalanceIDtest1"), }} - if err := internalRPC.Call(utils.APIerSv1SetActionTrigger, attrSet, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetActionTrigger, attrSet, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling v1.SetActionTrigger got: %v", reply) } // check - if err := engineOneRPC.Call(utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err != nil { t.Error("Got error on APIerSv1.GetActionTriggers: ", err) } else if len(atrs) != 1 { t.Errorf("Calling v1.GetActionTriggers got: %v", atrs) @@ -1154,7 +1155,7 @@ func testInternalReplicateITActionTrigger(t *testing.T) { } else if *atrs[0].Balance.ID != "BalanceIDtest1" { t.Errorf("Expecting BalanceIDtest1, received: %+v", atrs[0].Balance.ID) } - if err := engineTwoRPC.Call(utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err != nil { t.Error("Got error on APIerSv1.GetActionTriggers: ", err) } else if len(atrs) != 1 { t.Errorf("Calling v1.GetActionTriggers got: %v", atrs) @@ -1170,17 +1171,17 @@ func testInternalReplicateITActionTrigger(t *testing.T) { GroupID: "TestATR", UniqueID: "UniqueID", } - if err := internalRPC.Call(utils.APIerSv1RemoveActionTrigger, asttrRemove, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveActionTrigger, asttrRemove, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Calling v1.RemoveActionTrigger got: %v", reply) } //check - if err := engineOneRPC.Call(utils.APIerSv1GetActionTriggers, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Got error on APIerSv1.GetActionTriggers: %+v", err) } - if err := engineTwoRPC.Call(utils.APIerSv1GetActionTriggers, + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetActionTriggers, &AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error("Got error on APIerSv1.GetActionTriggers: ", err) } @@ -1189,7 +1190,7 @@ func testInternalReplicateITActionTrigger(t *testing.T) { func testInternalReplicateITThreshold(t *testing.T) { // get threshold var td engine.Threshold - if err := engineOneRPC.Call(utils.ThresholdSv1GetThreshold, + if err := engineOneRPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: tenant, @@ -1198,7 +1199,7 @@ func testInternalReplicateITThreshold(t *testing.T) { err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.ThresholdSv1GetThreshold, + if err := engineTwoRPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: tenant, @@ -1222,7 +1223,7 @@ func testInternalReplicateITThreshold(t *testing.T) { } //set Actions var reply string - if err := internalRPC.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{ + if err := internalRPC.Call(context.Background(), utils.APIerSv2SetActions, &utils.AttrSetActions{ ActionsId: "ACT_LOG", Actions: []*utils.TPAction{{Identifier: utils.MetaLog}}, }, &reply); err != nil && err.Error() != utils.ErrExists.Error() { @@ -1241,13 +1242,13 @@ func testInternalReplicateITThreshold(t *testing.T) { }, } // set Threshold - if err := internalRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } //get - if err := internalRPC.Call(utils.ThresholdSv1GetThreshold, + if err := internalRPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: tenant, @@ -1263,7 +1264,7 @@ func testInternalReplicateITThreshold(t *testing.T) { Tenant: tenant, ExtraOptions: map[string]bool{ utils.AllowNegative: true}} - if err := internalRPC.Call(utils.APIerSv1SetAccount, attrSetAccount, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetAccount, attrSetAccount, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -1279,13 +1280,13 @@ func testInternalReplicateITThreshold(t *testing.T) { utils.Weight: 10.0, }, } - if err := internalRPC.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } // processEvent var ids []string //eIDs := []string{} - if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, &tEvs, &ids); err != nil { + if err := internalRPC.Call(context.Background(), utils.ThresholdSv1ProcessEvent, &tEvs, &ids); err != nil { t.Error(err) } else if len(ids) != 1 { t.Errorf("Expecting 1: ,received %+v", len(ids)) @@ -1293,7 +1294,7 @@ func testInternalReplicateITThreshold(t *testing.T) { t.Errorf("Expecting: THD_Test, received %q", ids[0]) } //get - if err := internalRPC.Call(utils.ThresholdSv1GetThreshold, + if err := internalRPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: tenant, @@ -1306,14 +1307,14 @@ func testInternalReplicateITThreshold(t *testing.T) { // remove var result string - if err := internalRPC.Call(utils.APIerSv1RemoveThresholdProfile, + if err := internalRPC.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantID{Tenant: tenant, ID: "THD_Test"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := engineOneRPC.Call(utils.ThresholdSv1GetThreshold, + if err := engineOneRPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: tenant, @@ -1322,7 +1323,7 @@ func testInternalReplicateITThreshold(t *testing.T) { err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := engineTwoRPC.Call(utils.ThresholdSv1GetThreshold, + if err := engineTwoRPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: tenant, @@ -1337,11 +1338,11 @@ func testInternalReplicateITThreshold(t *testing.T) { func testInternalReplicateITLoadIds(t *testing.T) { // get LoadIDs var rcv1e1 map[string]int64 - if err := engineOneRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv1e1); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv1e1); err != nil { t.Error(err) } var rcv1e2 map[string]int64 - if err := engineTwoRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv1e2); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv1e2); err != nil { t.Error(err) } if !reflect.DeepEqual(rcv1e1, rcv1e2) { @@ -1374,14 +1375,14 @@ func testInternalReplicateITLoadIds(t *testing.T) { } alsPrf.Compile() var result string - if err := internalRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := internalRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } // check AttributeProfile var reply *engine.AttributeProfile - if err := engineOneRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err != nil { t.Fatal(err) } @@ -1391,11 +1392,11 @@ func testInternalReplicateITLoadIds(t *testing.T) { } // check again the LoadIDs var rcv2e1 map[string]int64 - if err := engineOneRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv2e1); err != nil { + if err := engineOneRPC.Call(context.Background(), utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv2e1); err != nil { t.Error(err) } var rcv2e2 map[string]int64 - if err := engineTwoRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv2e2); err != nil { + if err := engineTwoRPC.Call(context.Background(), utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv2e2); err != nil { t.Error(err) } diff --git a/apier/v1/replicator.go b/apier/v1/replicator.go index 875eedf49..19916448c 100644 --- a/apier/v1/replicator.go +++ b/apier/v1/replicator.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -37,13 +38,13 @@ type ReplicatorSv1 struct { v1 *APIerSv1 // needed for CallCache only } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (rplSv1 *ReplicatorSv1) Call(serviceMethod string, args any, reply any) error { +// Call implements birpc.ClientConnector interface for internal RPC +func (rplSv1 *ReplicatorSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(rplSv1, serviceMethod, args, reply) } // GetAccount is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetAccount(args *utils.StringWithAPIOpts, reply *engine.Account) error { +func (rplSv1 *ReplicatorSv1) GetAccount(ctx *context.Context, args *utils.StringWithAPIOpts, reply *engine.Account) error { engine.UpdateReplicationFilters(utils.AccountPrefix, args.Arg, utils.IfaceAsString(args.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.GetAccount(args.Arg) if err != nil { @@ -54,7 +55,7 @@ func (rplSv1 *ReplicatorSv1) GetAccount(args *utils.StringWithAPIOpts, reply *en } // GetDestination is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetDestination(key *utils.StringWithAPIOpts, reply *engine.Destination) error { +func (rplSv1 *ReplicatorSv1) GetDestination(ctx *context.Context, key *utils.StringWithAPIOpts, reply *engine.Destination) error { engine.UpdateReplicationFilters(utils.DestinationPrefix, key.Arg, utils.IfaceAsString(key.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetDestinationDrv(key.Arg, utils.NonTransactional) if err != nil { @@ -65,7 +66,7 @@ func (rplSv1 *ReplicatorSv1) GetDestination(key *utils.StringWithAPIOpts, reply } // GetReverseDestination is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetReverseDestination(key *utils.StringWithAPIOpts, reply *[]string) error { +func (rplSv1 *ReplicatorSv1) GetReverseDestination(ctx *context.Context, key *utils.StringWithAPIOpts, reply *[]string) error { rcv, err := rplSv1.dm.DataDB().GetReverseDestinationDrv(key.Arg, utils.NonTransactional) if err != nil { return err @@ -78,7 +79,7 @@ func (rplSv1 *ReplicatorSv1) GetReverseDestination(key *utils.StringWithAPIOpts, } // GetStatQueue is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetStatQueue(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) error { +func (rplSv1 *ReplicatorSv1) GetStatQueue(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) error { engine.UpdateReplicationFilters(utils.StatQueuePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetStatQueueDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -89,7 +90,7 @@ func (rplSv1 *ReplicatorSv1) GetStatQueue(tntID *utils.TenantIDWithAPIOpts, repl } // GetFilter is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetFilter(tntID *utils.TenantIDWithAPIOpts, reply *engine.Filter) error { +func (rplSv1 *ReplicatorSv1) GetFilter(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.Filter) error { engine.UpdateReplicationFilters(utils.FilterPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetFilterDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -100,7 +101,7 @@ func (rplSv1 *ReplicatorSv1) GetFilter(tntID *utils.TenantIDWithAPIOpts, reply * } // GetThreshold is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetThreshold(tntID *utils.TenantIDWithAPIOpts, reply *engine.Threshold) error { +func (rplSv1 *ReplicatorSv1) GetThreshold(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.Threshold) error { engine.UpdateReplicationFilters(utils.ThresholdPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetThresholdDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -111,7 +112,7 @@ func (rplSv1 *ReplicatorSv1) GetThreshold(tntID *utils.TenantIDWithAPIOpts, repl } // GetThresholdProfile is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetThresholdProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) error { +func (rplSv1 *ReplicatorSv1) GetThresholdProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) error { engine.UpdateReplicationFilters(utils.ThresholdProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetThresholdProfileDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -122,7 +123,7 @@ func (rplSv1 *ReplicatorSv1) GetThresholdProfile(tntID *utils.TenantIDWithAPIOpt } // GetStatQueueProfile is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetStatQueueProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) error { +func (rplSv1 *ReplicatorSv1) GetStatQueueProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) error { engine.UpdateReplicationFilters(utils.StatQueueProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetStatQueueProfileDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -133,7 +134,7 @@ func (rplSv1 *ReplicatorSv1) GetStatQueueProfile(tntID *utils.TenantIDWithAPIOpt } // GetTiming is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetTiming(id *utils.StringWithAPIOpts, reply *utils.TPTiming) error { +func (rplSv1 *ReplicatorSv1) GetTiming(ctx *context.Context, id *utils.StringWithAPIOpts, reply *utils.TPTiming) error { engine.UpdateReplicationFilters(utils.TimingsPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetTimingDrv(id.Arg) if err != nil { @@ -144,7 +145,7 @@ func (rplSv1 *ReplicatorSv1) GetTiming(id *utils.StringWithAPIOpts, reply *utils } // GetResource is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetResource(tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error { +func (rplSv1 *ReplicatorSv1) GetResource(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error { engine.UpdateReplicationFilters(utils.ResourcesPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetResourceDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -155,7 +156,7 @@ func (rplSv1 *ReplicatorSv1) GetResource(tntID *utils.TenantIDWithAPIOpts, reply } // GetResourceProfile is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetResourceProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error { +func (rplSv1 *ReplicatorSv1) GetResourceProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error { engine.UpdateReplicationFilters(utils.ResourceProfilesPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetResourceProfileDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -166,7 +167,7 @@ func (rplSv1 *ReplicatorSv1) GetResourceProfile(tntID *utils.TenantIDWithAPIOpts } // GetActionTriggers is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetActionTriggers(id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error { +func (rplSv1 *ReplicatorSv1) GetActionTriggers(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.ActionTriggers) error { engine.UpdateReplicationFilters(utils.ActionTriggerPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetActionTriggersDrv(id.Arg) if err != nil { @@ -177,7 +178,7 @@ func (rplSv1 *ReplicatorSv1) GetActionTriggers(id *utils.StringWithAPIOpts, repl } // GetSharedGroup is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetSharedGroup(id *utils.StringWithAPIOpts, reply *engine.SharedGroup) error { +func (rplSv1 *ReplicatorSv1) GetSharedGroup(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.SharedGroup) error { engine.UpdateReplicationFilters(utils.SharedGroupPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetSharedGroupDrv(id.Arg) if err != nil { @@ -188,7 +189,7 @@ func (rplSv1 *ReplicatorSv1) GetSharedGroup(id *utils.StringWithAPIOpts, reply * } // GetActions is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetActions(id *utils.StringWithAPIOpts, reply *engine.Actions) error { +func (rplSv1 *ReplicatorSv1) GetActions(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.Actions) error { engine.UpdateReplicationFilters(utils.ActionPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetActionsDrv(id.Arg) if err != nil { @@ -199,7 +200,7 @@ func (rplSv1 *ReplicatorSv1) GetActions(id *utils.StringWithAPIOpts, reply *engi } // GetActionPlan is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetActionPlan(id *utils.StringWithAPIOpts, reply *engine.ActionPlan) error { +func (rplSv1 *ReplicatorSv1) GetActionPlan(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.ActionPlan) error { engine.UpdateReplicationFilters(utils.ActionPlanPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetActionPlanDrv(id.Arg) if err != nil { @@ -210,7 +211,7 @@ func (rplSv1 *ReplicatorSv1) GetActionPlan(id *utils.StringWithAPIOpts, reply *e } // GetAllActionPlans is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetAllActionPlans(id *utils.StringWithAPIOpts, reply *map[string]*engine.ActionPlan) error { +func (rplSv1 *ReplicatorSv1) GetAllActionPlans(ctx *context.Context, id *utils.StringWithAPIOpts, reply *map[string]*engine.ActionPlan) error { rcv, err := rplSv1.dm.DataDB().GetAllActionPlansDrv() if err != nil { return err @@ -223,7 +224,7 @@ func (rplSv1 *ReplicatorSv1) GetAllActionPlans(id *utils.StringWithAPIOpts, repl } // GetAccountActionPlans is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetAccountActionPlans(id *utils.StringWithAPIOpts, reply *[]string) error { +func (rplSv1 *ReplicatorSv1) GetAccountActionPlans(ctx *context.Context, id *utils.StringWithAPIOpts, reply *[]string) error { engine.UpdateReplicationFilters(utils.AccountActionPlansPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetAccountActionPlansDrv(id.Arg) if err != nil { @@ -234,7 +235,7 @@ func (rplSv1 *ReplicatorSv1) GetAccountActionPlans(id *utils.StringWithAPIOpts, } // GetRatingPlan is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetRatingPlan(id *utils.StringWithAPIOpts, reply *engine.RatingPlan) error { +func (rplSv1 *ReplicatorSv1) GetRatingPlan(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.RatingPlan) error { engine.UpdateReplicationFilters(utils.RatingPlanPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetRatingPlanDrv(id.Arg) if err != nil { @@ -245,7 +246,7 @@ func (rplSv1 *ReplicatorSv1) GetRatingPlan(id *utils.StringWithAPIOpts, reply *e } // GetRatingProfile is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetRatingProfile(id *utils.StringWithAPIOpts, reply *engine.RatingProfile) error { +func (rplSv1 *ReplicatorSv1) GetRatingProfile(ctx *context.Context, id *utils.StringWithAPIOpts, reply *engine.RatingProfile) error { engine.UpdateReplicationFilters(utils.RatingProfilePrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetRatingProfileDrv(id.Arg) if err != nil { @@ -256,7 +257,7 @@ func (rplSv1 *ReplicatorSv1) GetRatingProfile(id *utils.StringWithAPIOpts, reply } // GetRouteProfile is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetRouteProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error { +func (rplSv1 *ReplicatorSv1) GetRouteProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error { engine.UpdateReplicationFilters(utils.RouteProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetRouteProfileDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -267,7 +268,7 @@ func (rplSv1 *ReplicatorSv1) GetRouteProfile(tntID *utils.TenantIDWithAPIOpts, r } // GetAttributeProfile is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetAttributeProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) error { +func (rplSv1 *ReplicatorSv1) GetAttributeProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) error { engine.UpdateReplicationFilters(utils.AttributeProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetAttributeProfileDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -278,7 +279,7 @@ func (rplSv1 *ReplicatorSv1) GetAttributeProfile(tntID *utils.TenantIDWithAPIOpt } // GetChargerProfile is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetChargerProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) error { +func (rplSv1 *ReplicatorSv1) GetChargerProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) error { engine.UpdateReplicationFilters(utils.ChargerProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetChargerProfileDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -289,7 +290,7 @@ func (rplSv1 *ReplicatorSv1) GetChargerProfile(tntID *utils.TenantIDWithAPIOpts, } // GetDispatcherProfile is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetDispatcherProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) error { +func (rplSv1 *ReplicatorSv1) GetDispatcherProfile(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) error { engine.UpdateReplicationFilters(utils.DispatcherProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetDispatcherProfileDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -300,7 +301,7 @@ func (rplSv1 *ReplicatorSv1) GetDispatcherProfile(tntID *utils.TenantIDWithAPIOp } // GetDispatcherHost is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetDispatcherHost(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) error { +func (rplSv1 *ReplicatorSv1) GetDispatcherHost(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) error { engine.UpdateReplicationFilters(utils.DispatcherHostPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetDispatcherHostDrv(tntID.Tenant, tntID.ID) if err != nil { @@ -311,7 +312,7 @@ func (rplSv1 *ReplicatorSv1) GetDispatcherHost(tntID *utils.TenantIDWithAPIOpts, } // GetItemLoadIDs is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetItemLoadIDs(itemID *utils.StringWithAPIOpts, reply *map[string]int64) error { +func (rplSv1 *ReplicatorSv1) GetItemLoadIDs(ctx *context.Context, itemID *utils.StringWithAPIOpts, reply *map[string]int64) error { engine.UpdateReplicationFilters(utils.LoadIDPrefix, itemID.Arg, utils.IfaceAsString(itemID.APIOpts[utils.RemoteHostOpt])) rcv, err := rplSv1.dm.DataDB().GetItemLoadIDsDrv(itemID.Arg) if err != nil { @@ -322,7 +323,7 @@ func (rplSv1 *ReplicatorSv1) GetItemLoadIDs(itemID *utils.StringWithAPIOpts, rep } // GetIndexes is the remote method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) GetIndexes(args *utils.GetIndexesArg, reply *map[string]utils.StringSet) error { +func (rplSv1 *ReplicatorSv1) GetIndexes(ctx *context.Context, args *utils.GetIndexesArg, reply *map[string]utils.StringSet) error { engine.UpdateReplicationFilters(utils.CacheInstanceToPrefix[args.IdxItmType], args.TntCtx, utils.IfaceAsString(args.APIOpts[utils.RemoteHostOpt])) indx, err := rplSv1.dm.DataDB().GetIndexesDrv(args.IdxItmType, args.TntCtx, args.IdxKey) if err != nil { @@ -333,7 +334,7 @@ func (rplSv1 *ReplicatorSv1) GetIndexes(args *utils.GetIndexesArg, reply *map[st } // SetAccount is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetAccount(acc *engine.AccountWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetAccount(ctx *context.Context, acc *engine.AccountWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetAccountDrv(acc.Account); err != nil { return } @@ -343,7 +344,7 @@ func (rplSv1 *ReplicatorSv1) SetAccount(acc *engine.AccountWithAPIOpts, reply *s } // SetDestination is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetDestination(dst *engine.DestinationWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetDestination(ctx *context.Context, dst *engine.DestinationWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetDestinationDrv(dst.Destination, utils.NonTransactional); err != nil { return } @@ -356,7 +357,7 @@ func (rplSv1 *ReplicatorSv1) SetDestination(dst *engine.DestinationWithAPIOpts, } // SetReverseDestination is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetReverseDestination(dst *engine.DestinationWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetReverseDestination(ctx *context.Context, dst *engine.DestinationWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetReverseDestinationDrv(dst.Destination.Id, dst.Destination.Prefixes, utils.NonTransactional); err != nil { return } @@ -369,7 +370,7 @@ func (rplSv1 *ReplicatorSv1) SetReverseDestination(dst *engine.DestinationWithAP } // SetThresholdProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetThresholdProfile(th *engine.ThresholdProfileWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetThresholdProfile(ctx *context.Context, th *engine.ThresholdProfileWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetThresholdProfileDrv(th.ThresholdProfile); err != nil { return } @@ -382,7 +383,7 @@ func (rplSv1 *ReplicatorSv1) SetThresholdProfile(th *engine.ThresholdProfileWith } // SetThreshold is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetThreshold(th *engine.ThresholdWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetThreshold(ctx *context.Context, th *engine.ThresholdWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetThresholdDrv(th.Threshold); err != nil { return } @@ -395,7 +396,7 @@ func (rplSv1 *ReplicatorSv1) SetThreshold(th *engine.ThresholdWithAPIOpts, reply } // SetStatQueueProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetStatQueueProfile(sq *engine.StatQueueProfileWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetStatQueueProfile(ctx *context.Context, sq *engine.StatQueueProfileWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetStatQueueProfileDrv(sq.StatQueueProfile); err != nil { return } @@ -408,7 +409,7 @@ func (rplSv1 *ReplicatorSv1) SetStatQueueProfile(sq *engine.StatQueueProfileWith } // SetStatQueue is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetStatQueue(sq *engine.StatQueueWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetStatQueue(ctx *context.Context, sq *engine.StatQueueWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetStatQueueDrv(nil, sq.StatQueue); err != nil { return } @@ -421,7 +422,7 @@ func (rplSv1 *ReplicatorSv1) SetStatQueue(sq *engine.StatQueueWithAPIOpts, reply } // SetFilter is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetFilter(fltr *engine.FilterWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetFilter(ctx *context.Context, fltr *engine.FilterWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetFilterDrv(fltr.Filter); err != nil { return } @@ -434,7 +435,7 @@ func (rplSv1 *ReplicatorSv1) SetFilter(fltr *engine.FilterWithAPIOpts, reply *st } // SetTiming is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetTiming(tm *utils.TPTimingWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetTiming(ctx *context.Context, tm *utils.TPTimingWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetTimingDrv(tm.TPTiming); err != nil { return } @@ -447,7 +448,7 @@ func (rplSv1 *ReplicatorSv1) SetTiming(tm *utils.TPTimingWithAPIOpts, reply *str } // SetResourceProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetResourceProfile(rs *engine.ResourceProfileWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetResourceProfile(ctx *context.Context, rs *engine.ResourceProfileWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetResourceProfileDrv(rs.ResourceProfile); err != nil { return } @@ -460,7 +461,7 @@ func (rplSv1 *ReplicatorSv1) SetResourceProfile(rs *engine.ResourceProfileWithAP } // SetResource is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetResource(rs *engine.ResourceWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetResource(ctx *context.Context, rs *engine.ResourceWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetResourceDrv(rs.Resource); err != nil { return } @@ -473,7 +474,7 @@ func (rplSv1 *ReplicatorSv1) SetResource(rs *engine.ResourceWithAPIOpts, reply * } // SetActionTriggers is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetActionTriggers(args *engine.SetActionTriggersArgWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetActionTriggers(ctx *context.Context, args *engine.SetActionTriggersArgWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetActionTriggersDrv(args.Key, args.Attrs); err != nil { return } @@ -486,7 +487,7 @@ func (rplSv1 *ReplicatorSv1) SetActionTriggers(args *engine.SetActionTriggersArg } // SetSharedGroup is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetSharedGroup(shg *engine.SharedGroupWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetSharedGroup(ctx *context.Context, shg *engine.SharedGroupWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetSharedGroupDrv(shg.SharedGroup); err != nil { return } @@ -499,7 +500,7 @@ func (rplSv1 *ReplicatorSv1) SetSharedGroup(shg *engine.SharedGroupWithAPIOpts, } // SetActions is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetActions(args *engine.SetActionsArgsWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetActions(ctx *context.Context, args *engine.SetActionsArgsWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetActionsDrv(args.Key, args.Acs); err != nil { return } @@ -512,7 +513,7 @@ func (rplSv1 *ReplicatorSv1) SetActions(args *engine.SetActionsArgsWithAPIOpts, } // SetRatingPlan is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetRatingPlan(rp *engine.RatingPlanWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetRatingPlan(ctx *context.Context, rp *engine.RatingPlanWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetRatingPlanDrv(rp.RatingPlan); err != nil { return } @@ -525,7 +526,7 @@ func (rplSv1 *ReplicatorSv1) SetRatingPlan(rp *engine.RatingPlanWithAPIOpts, rep } // SetRatingProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetRatingProfile(rp *engine.RatingProfileWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetRatingProfile(ctx *context.Context, rp *engine.RatingProfileWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetRatingProfileDrv(rp.RatingProfile); err != nil { return } @@ -538,7 +539,7 @@ func (rplSv1 *ReplicatorSv1) SetRatingProfile(rp *engine.RatingProfileWithAPIOpt } // SetRouteProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetRouteProfile(sp *engine.RouteProfileWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetRouteProfile(ctx *context.Context, sp *engine.RouteProfileWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetRouteProfileDrv(sp.RouteProfile); err != nil { return } @@ -551,7 +552,7 @@ func (rplSv1 *ReplicatorSv1) SetRouteProfile(sp *engine.RouteProfileWithAPIOpts, } // SetAttributeProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetAttributeProfile(ap *engine.AttributeProfileWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetAttributeProfile(ctx *context.Context, ap *engine.AttributeProfileWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetAttributeProfileDrv(ap.AttributeProfile); err != nil { return } @@ -564,7 +565,7 @@ func (rplSv1 *ReplicatorSv1) SetAttributeProfile(ap *engine.AttributeProfileWith } // SetChargerProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetChargerProfile(cp *engine.ChargerProfileWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetChargerProfile(ctx *context.Context, cp *engine.ChargerProfileWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetChargerProfileDrv(cp.ChargerProfile); err != nil { return } @@ -577,7 +578,7 @@ func (rplSv1 *ReplicatorSv1) SetChargerProfile(cp *engine.ChargerProfileWithAPIO } // SetDispatcherProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetDispatcherProfile(dpp *engine.DispatcherProfileWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetDispatcherProfile(ctx *context.Context, dpp *engine.DispatcherProfileWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetDispatcherProfileDrv(dpp.DispatcherProfile); err != nil { return } @@ -590,7 +591,7 @@ func (rplSv1 *ReplicatorSv1) SetDispatcherProfile(dpp *engine.DispatcherProfileW } // SetActionPlan is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetActionPlan(args *engine.SetActionPlanArgWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetActionPlan(ctx *context.Context, args *engine.SetActionPlanArgWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetActionPlanDrv(args.Key, args.Ats); err != nil { return } @@ -603,7 +604,7 @@ func (rplSv1 *ReplicatorSv1) SetActionPlan(args *engine.SetActionPlanArgWithAPIO } // SetAccountActionPlans is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetAccountActionPlans(args *engine.SetAccountActionPlansArgWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetAccountActionPlans(ctx *context.Context, args *engine.SetAccountActionPlansArgWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetAccountActionPlansDrv(args.AcntID, args.AplIDs); err != nil { return } @@ -616,7 +617,7 @@ func (rplSv1 *ReplicatorSv1) SetAccountActionPlans(args *engine.SetAccountAction } // SetDispatcherHost is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetDispatcherHost(dpp *engine.DispatcherHostWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetDispatcherHost(ctx *context.Context, dpp *engine.DispatcherHostWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetDispatcherHostDrv(dpp.DispatcherHost); err != nil { return } @@ -629,7 +630,7 @@ func (rplSv1 *ReplicatorSv1) SetDispatcherHost(dpp *engine.DispatcherHostWithAPI } // SetLoadIDs is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetLoadIDs(args *utils.LoadIDsWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetLoadIDs(ctx *context.Context, args *utils.LoadIDsWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetLoadIDsDrv(args.LoadIDs); err != nil { return } @@ -646,7 +647,7 @@ func (rplSv1 *ReplicatorSv1) SetLoadIDs(args *utils.LoadIDsWithAPIOpts, reply *s } // SetIndexes is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) SetIndexes(args *utils.SetIndexesArg, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) SetIndexes(ctx *context.Context, args *utils.SetIndexesArg, reply *string) (err error) { if err = rplSv1.dm.DataDB().SetIndexesDrv(args.IdxItmType, args.TntCtx, args.Indexes, true, utils.NonTransactional); err != nil { return } @@ -663,7 +664,7 @@ func (rplSv1 *ReplicatorSv1) SetIndexes(args *utils.SetIndexesArg, reply *string } // RemoveThreshold is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveThreshold(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveThreshold(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveThresholdDrv(args.Tenant, args.ID); err != nil { return } @@ -676,7 +677,7 @@ func (rplSv1 *ReplicatorSv1) RemoveThreshold(args *utils.TenantIDWithAPIOpts, re } // RemoveDestination is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveDestination(id *utils.StringWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveDestination(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveDestinationDrv(id.Arg, utils.NonTransactional); err != nil { return } @@ -689,7 +690,7 @@ func (rplSv1 *ReplicatorSv1) RemoveDestination(id *utils.StringWithAPIOpts, repl } // RemoveAccount is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveAccount(id *utils.StringWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveAccount(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveAccountDrv(id.Arg); err != nil { return } @@ -699,7 +700,7 @@ func (rplSv1 *ReplicatorSv1) RemoveAccount(id *utils.StringWithAPIOpts, reply *s } // RemoveStatQueue is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveStatQueue(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveStatQueue(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemStatQueueDrv(args.Tenant, args.ID); err != nil { return } @@ -712,7 +713,7 @@ func (rplSv1 *ReplicatorSv1) RemoveStatQueue(args *utils.TenantIDWithAPIOpts, re } // RemoveFilter is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveFilter(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveFilter(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveFilterDrv(args.Tenant, args.ID); err != nil { return } @@ -725,7 +726,7 @@ func (rplSv1 *ReplicatorSv1) RemoveFilter(args *utils.TenantIDWithAPIOpts, reply } // RemoveThresholdProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveThresholdProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemThresholdProfileDrv(args.Tenant, args.ID); err != nil { return } @@ -738,7 +739,7 @@ func (rplSv1 *ReplicatorSv1) RemoveThresholdProfile(args *utils.TenantIDWithAPIO } // RemoveStatQueueProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveStatQueueProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveStatQueueProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemStatQueueProfileDrv(args.Tenant, args.ID); err != nil { return } @@ -751,7 +752,7 @@ func (rplSv1 *ReplicatorSv1) RemoveStatQueueProfile(args *utils.TenantIDWithAPIO } // RemoveTiming is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveTiming(id *utils.StringWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveTiming(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveTimingDrv(id.Arg); err != nil { return } @@ -764,7 +765,7 @@ func (rplSv1 *ReplicatorSv1) RemoveTiming(id *utils.StringWithAPIOpts, reply *st } // RemoveResource is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveResource(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveResource(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveResourceDrv(args.Tenant, args.ID); err != nil { return } @@ -777,7 +778,7 @@ func (rplSv1 *ReplicatorSv1) RemoveResource(args *utils.TenantIDWithAPIOpts, rep } // RemoveResourceProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveResourceProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveResourceProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveResourceProfileDrv(args.Tenant, args.ID); err != nil { return } @@ -790,7 +791,7 @@ func (rplSv1 *ReplicatorSv1) RemoveResourceProfile(args *utils.TenantIDWithAPIOp } // RemoveActionTriggers is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveActionTriggers(id *utils.StringWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveActionTriggers(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveActionTriggersDrv(id.Arg); err != nil { return } @@ -803,7 +804,7 @@ func (rplSv1 *ReplicatorSv1) RemoveActionTriggers(id *utils.StringWithAPIOpts, r } // RemoveSharedGroup is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveSharedGroup(id *utils.StringWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveSharedGroup(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveSharedGroupDrv(id.Arg); err != nil { return } @@ -816,7 +817,7 @@ func (rplSv1 *ReplicatorSv1) RemoveSharedGroup(id *utils.StringWithAPIOpts, repl } // RemoveActions is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveActions(id *utils.StringWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveActions(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveActionsDrv(id.Arg); err != nil { return } @@ -829,7 +830,7 @@ func (rplSv1 *ReplicatorSv1) RemoveActions(id *utils.StringWithAPIOpts, reply *s } // RemoveActionPlan is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveActionPlan(id *utils.StringWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveActionPlan(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveActionPlanDrv(id.Arg); err != nil { return } @@ -842,7 +843,7 @@ func (rplSv1 *ReplicatorSv1) RemoveActionPlan(id *utils.StringWithAPIOpts, reply } // RemAccountActionPlans is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemAccountActionPlans(args *engine.RemAccountActionPlansArgsWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemAccountActionPlans(ctx *context.Context, args *engine.RemAccountActionPlansArgsWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemAccountActionPlansDrv(args.AcntID); err != nil { return } @@ -855,7 +856,7 @@ func (rplSv1 *ReplicatorSv1) RemAccountActionPlans(args *engine.RemAccountAction } // RemoveRatingPlan is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveRatingPlan(id *utils.StringWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveRatingPlan(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveRatingPlanDrv(id.Arg); err != nil { return } @@ -868,7 +869,7 @@ func (rplSv1 *ReplicatorSv1) RemoveRatingPlan(id *utils.StringWithAPIOpts, reply } // RemoveRatingProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveRatingProfile(id *utils.StringWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveRatingProfile(ctx *context.Context, id *utils.StringWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveRatingProfileDrv(id.Arg); err != nil { return } @@ -881,7 +882,7 @@ func (rplSv1 *ReplicatorSv1) RemoveRatingProfile(id *utils.StringWithAPIOpts, re } // RemoveRouteProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveRouteProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveRouteProfileDrv(args.Tenant, args.ID); err != nil { return } @@ -894,7 +895,7 @@ func (rplSv1 *ReplicatorSv1) RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, } // RemoveAttributeProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveAttributeProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveAttributeProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveAttributeProfileDrv(args.Tenant, args.ID); err != nil { return } @@ -907,7 +908,7 @@ func (rplSv1 *ReplicatorSv1) RemoveAttributeProfile(args *utils.TenantIDWithAPIO } // RemoveChargerProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveChargerProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveChargerProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveChargerProfileDrv(args.Tenant, args.ID); err != nil { return } @@ -920,7 +921,7 @@ func (rplSv1 *ReplicatorSv1) RemoveChargerProfile(args *utils.TenantIDWithAPIOpt } // RemoveDispatcherProfile is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveDispatcherProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveDispatcherProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveDispatcherProfileDrv(args.Tenant, args.ID); err != nil { return } @@ -933,7 +934,7 @@ func (rplSv1 *ReplicatorSv1) RemoveDispatcherProfile(args *utils.TenantIDWithAPI } // RemoveDispatcherHost is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveDispatcherHost(args *utils.TenantIDWithAPIOpts, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveDispatcherHost(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveDispatcherHostDrv(args.Tenant, args.ID); err != nil { return } @@ -946,7 +947,7 @@ func (rplSv1 *ReplicatorSv1) RemoveDispatcherHost(args *utils.TenantIDWithAPIOpt } // RemoveIndexes is the replication method coresponding to the dataDb driver method -func (rplSv1 *ReplicatorSv1) RemoveIndexes(args *utils.GetIndexesArg, reply *string) (err error) { +func (rplSv1 *ReplicatorSv1) RemoveIndexes(ctx *context.Context, args *utils.GetIndexesArg, reply *string) (err error) { if err = rplSv1.dm.DataDB().RemoveIndexesDrv(args.IdxItmType, args.TntCtx, args.IdxKey); err != nil { return } @@ -959,7 +960,7 @@ func (rplSv1 *ReplicatorSv1) RemoveIndexes(args *utils.GetIndexesArg, reply *str } // Ping used to determine if the RPC is active -func (rplSv1 *ReplicatorSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (rplSv1 *ReplicatorSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } diff --git a/apier/v1/resourcesv1.go b/apier/v1/resourcesv1.go index b7ee10082..2cc0722d4 100644 --- a/apier/v1/resourcesv1.go +++ b/apier/v1/resourcesv1.go @@ -21,6 +21,7 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -34,42 +35,42 @@ type ResourceSv1 struct { rls *engine.ResourceService } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (rsv1 *ResourceSv1) Call(serviceMethod string, args any, reply any) error { +// Call implements birpc.ClientConnector interface for internal RPC +func (rsv1 *ResourceSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(rsv1, serviceMethod, args, reply) } // GetResourcesForEvent returns Resources matching a specific event -func (rsv1 *ResourceSv1) GetResourcesForEvent(args *utils.CGREvent, reply *engine.Resources) error { - return rsv1.rls.V1ResourcesForEvent(args, reply) +func (rsv1 *ResourceSv1) GetResourcesForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.Resources) error { + return rsv1.rls.V1GetResourcesForEvent(ctx, args, reply) } // AuthorizeResources checks if there are limits imposed for event -func (rsv1 *ResourceSv1) AuthorizeResources(args *utils.CGREvent, reply *string) error { - return rsv1.rls.V1AuthorizeResources(args, reply) +func (rsv1 *ResourceSv1) AuthorizeResources(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return rsv1.rls.V1AuthorizeResources(ctx, args, reply) } // V1InitiateResourceUsage records usage for an event -func (rsv1 *ResourceSv1) AllocateResources(args *utils.CGREvent, reply *string) error { - return rsv1.rls.V1AllocateResources(args, reply) +func (rsv1 *ResourceSv1) AllocateResources(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return rsv1.rls.V1AllocateResources(ctx, args, reply) } // V1TerminateResourceUsage releases usage for an event -func (rsv1 *ResourceSv1) ReleaseResources(args *utils.CGREvent, reply *string) error { - return rsv1.rls.V1ReleaseResources(args, reply) +func (rsv1 *ResourceSv1) ReleaseResources(ctx *context.Context, args *utils.CGREvent, reply *string) error { + return rsv1.rls.V1ReleaseResources(ctx, args, reply) } // GetResource returns a resource configuration -func (rsv1 *ResourceSv1) GetResource(args *utils.TenantIDWithAPIOpts, reply *engine.Resource) error { - return rsv1.rls.V1GetResource(args, reply) +func (rsv1 *ResourceSv1) GetResource(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.Resource) error { + return rsv1.rls.V1GetResource(ctx, args, reply) } -func (rsv1 *ResourceSv1) GetResourceWithConfig(args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) error { - return rsv1.rls.V1GetResourceWithConfig(args, reply) +func (rsv1 *ResourceSv1) GetResourceWithConfig(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) error { + return rsv1.rls.V1GetResourceWithConfig(ctx, args, reply) } // GetResourceProfile returns a resource configuration -func (apierSv1 *APIerSv1) GetResourceProfile(arg *utils.TenantID, reply *engine.ResourceProfile) error { +func (apierSv1 *APIerSv1) GetResourceProfile(ctx *context.Context, arg *utils.TenantID, reply *engine.ResourceProfile) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -86,7 +87,7 @@ func (apierSv1 *APIerSv1) GetResourceProfile(arg *utils.TenantID, reply *engine. } // GetResourceProfileIDs returns list of resourceProfile IDs registered for a tenant -func (apierSv1 *APIerSv1) GetResourceProfileIDs(args *utils.PaginatorWithTenant, rsPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetResourceProfileIDs(ctx *context.Context, args *utils.PaginatorWithTenant, rsPrfIDs *[]string) error { tnt := args.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -108,7 +109,7 @@ func (apierSv1 *APIerSv1) GetResourceProfileIDs(args *utils.PaginatorWithTenant, } // SetResourceProfile adds a new resource configuration -func (apierSv1 *APIerSv1) SetResourceProfile(arg *engine.ResourceProfileWithAPIOpts, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetResourceProfile(ctx *context.Context, arg *engine.ResourceProfileWithAPIOpts, reply *string) (err error) { if missing := utils.MissingStructFields(arg.ResourceProfile, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -136,7 +137,7 @@ func (apierSv1 *APIerSv1) SetResourceProfile(arg *engine.ResourceProfileWithAPIO } // RemoveResourceProfile remove a specific resource configuration -func (apierSv1 *APIerSv1) RemoveResourceProfile(arg *utils.TenantIDWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) RemoveResourceProfile(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -162,7 +163,7 @@ func (apierSv1 *APIerSv1) RemoveResourceProfile(arg *utils.TenantIDWithAPIOpts, return nil } -func (rsv1 *ResourceSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (rsv1 *ResourceSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index d55b9054a..b5d47c864 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -21,7 +21,6 @@ along with this program. If not, see package v1 import ( - "net/rpc" "os" "path" "reflect" @@ -29,6 +28,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( rlsV1CfgPath string rlsV1Cfg *config.CGRConfig - rlsV1Rpc *rpc.Client + rlsV1Rpc *birpc.Client rlsV1ConfDIR string //run tests for specific configuration rlsConfig *engine.ResourceProfileWithAPIOpts @@ -165,7 +166,7 @@ func testV1ResourceStartCPUProfiling(t *testing.T) { DirPath: "/tmp", } var reply string - if err := rlsV1Rpc.Call(utils.CoreSv1StartCPUProfiling, + if err := rlsV1Rpc.Call(context.Background(), utils.CoreSv1StartCPUProfiling, argPath, &reply); err != nil { t.Error(err) } @@ -173,7 +174,7 @@ func testV1ResourceStartCPUProfiling(t *testing.T) { func testV1RsCacheResourceBeforeLoad(t *testing.T) { // cache it with not found var rplyRes *engine.Resource - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{ + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}, }, &rplyRes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -187,7 +188,7 @@ func testV1RsCacheResourceAfterLoad(t *testing.T) { // the APIerSv1LoadTariffPla ID: "ResGroup1", Usages: map[string]*engine.ResourceUsage{}, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{ + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}, }, &rplyRes); err != nil { t.Error(err) @@ -223,7 +224,7 @@ func testV1RsCacheResourceWithConfig(t *testing.T) { ThresholdIDs: []string{"*none"}, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourceWithConfig, &utils.TenantIDWithAPIOpts{ + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourceWithConfig, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}, }, &rplyRes); err != nil { t.Error(err) @@ -235,7 +236,7 @@ func testV1RsCacheResourceWithConfig(t *testing.T) { func testV1RsFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} - if err := rlsV1Rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -252,13 +253,13 @@ func testV1RsGetResourcesForEvent(t *testing.T) { utils.OptsResourcesUsageID: "RandomUsageID", }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } args.Event = map[string]any{"Destination": "10", "Account": "1001"} args.ID = utils.UUIDSha1Prefix() args.APIOpts[utils.OptsResourcesUsageID] = "RandomUsageID2" - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { t.Error(err) } if reply == nil { @@ -278,14 +279,14 @@ func testV1RsGetResourcesForEvent(t *testing.T) { args.Event = map[string]any{"Destination": "20"} args.ID = utils.UUIDSha1Prefix() args.APIOpts[utils.OptsResourcesUsageID] = "RandomUsageID3" - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } args.Event = map[string]any{"Account": "1002", "Subject": "test", "Destination": "1002"} args.ID = utils.UUIDSha1Prefix() args.APIOpts[utils.OptsResourcesUsageID] = "RandomUsageID5" - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { t.Error(err) } if len(*reply) != 1 { @@ -294,7 +295,7 @@ func testV1RsGetResourcesForEvent(t *testing.T) { args.Event = map[string]any{"Account": "1002", "Subject": "test", "Destination": "1001"} args.ID = utils.UUIDSha1Prefix() - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { t.Error(err) } if len(*reply) != 1 { @@ -306,7 +307,7 @@ func testV1RsGetResourcesForEvent(t *testing.T) { args.Tenant = utils.EmptyString args.ID = utils.UUIDSha1Prefix() - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { t.Error(err) } if len(*reply) != 1 { @@ -332,7 +333,7 @@ func testV1RsTTL0(t *testing.T) { }, } var reply string - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } @@ -349,7 +350,7 @@ func testV1RsTTL0(t *testing.T) { utils.OptsResourcesUnits: 2, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, ev, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } // too many units should be rejected @@ -365,7 +366,7 @@ func testV1RsTTL0(t *testing.T) { utils.OptsResourcesUnits: 4, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, ev, &reply); err == nil || + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err == nil || err.Error() != utils.ErrResourceUnavailable.Error() { t.Error(err) } @@ -398,7 +399,7 @@ func testV1RsTTL0(t *testing.T) { }, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) } else if len(*rs) != 1 { @@ -426,13 +427,13 @@ func testV1RsTTL0(t *testing.T) { utils.OptsResourcesUsageID: "651a8db2-4f67-4cf8-b622-169e8a482e25", // same ID should be accepted by first group since the previous resource should be expired }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1ReleaseResources, ev, &releaseReply); err != nil { t.Error(err) } ev.Tenant = utils.EmptyString - if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1ReleaseResources, ev, &releaseReply); err != nil { t.Error(err) } @@ -454,7 +455,7 @@ func testV1RsAllocateResource(t *testing.T) { utils.OptsResourcesUnits: 3, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } @@ -476,7 +477,7 @@ func testV1RsAllocateResource(t *testing.T) { utils.OptsResourcesUnits: 4, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } @@ -498,7 +499,7 @@ func testV1RsAllocateResource(t *testing.T) { utils.OptsResourcesUnits: 1, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } @@ -520,7 +521,7 @@ func testV1RsAllocateResource(t *testing.T) { utils.OptsResourcesUnits: 1, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err == nil || err.Error() != utils.ErrResourceUnavailable.Error() { t.Error(err) } @@ -540,7 +541,7 @@ func testV1RsAllocateResource(t *testing.T) { utils.OptsResourcesUnits: 1, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } @@ -565,7 +566,7 @@ func testV1RsAuthorizeResources(t *testing.T) { utils.OptsResourcesUsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61", }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, &argsRU, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &argsRU, &reply); err != nil { t.Error(err) } else if reply != "ResGroup1" { // already 3 usages active before allow call, we should have now more than allowed t.Error("Unexpected reply returned", reply) @@ -583,7 +584,7 @@ func testV1RsAuthorizeResources(t *testing.T) { utils.OptsResourcesUnits: 7, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &argsRU, &reply); err.Error() != utils.ErrResourceUnauthorized.Error() { t.Error(err) } @@ -604,7 +605,7 @@ func testV1RsReleaseResource(t *testing.T) { utils.OptsResourcesUsageID: "651a8db2-4f67-4cf8-b622-169e8a482e55", // same ID should be accepted by first group since the previous resource should be expired }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1ReleaseResources, argsRU, &reply); err != nil { t.Error(err) } @@ -623,7 +624,7 @@ func testV1RsReleaseResource(t *testing.T) { utils.OptsResourcesUnits: 7, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, &argsRU, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &argsRU, &reply); err != nil { t.Error(err) } else if reply != "ResGroup1" { t.Error("Unexpected reply returned", reply) @@ -641,7 +642,7 @@ func testV1RsReleaseResource(t *testing.T) { utils.OptsResourcesUsageID: utils.UUIDSha1Prefix(), }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) } else if len(*rs) != 2 { t.Errorf("Resources: %+v", rs) @@ -669,7 +670,7 @@ func testV1RsReleaseResource(t *testing.T) { utils.OptsResourcesUsageID: "651a8db2-4f67-4cf8-b622-169e8a482e55", // same ID should be accepted by first group since the previous resource should be expired }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1ReleaseResources, argsRU, &reply); err == nil || err.Error() != "cannot find usage record with id: 651a8db2-4f67-4cf8-b622-169e8a482e55" { t.Error(err) } @@ -694,7 +695,7 @@ func testV1RsDBStore(t *testing.T) { } var reply string eAllocationMsg := "ResGroup1" - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, argsRU, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, argsRU, &reply); err != nil { t.Error(err) } else if reply != eAllocationMsg { t.Errorf("Expecting: %+v, received: %+v", eAllocationMsg, reply) @@ -712,7 +713,7 @@ func testV1RsDBStore(t *testing.T) { utils.OptsResourcesUsageID: "651a8db2-4f67-4cf8-b622-169e8a482e71", }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) } else if len(*rs) != 2 { t.Errorf("Resources: %+v", rs) @@ -754,7 +755,7 @@ func testV1RsDBStore(t *testing.T) { utils.OptsResourcesUsageID: "651a8db2-4f67-4cf8-b622-169e8a482e71", }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) } else if len(*rs) != 2 { t.Errorf("Resources: %+v", rs) @@ -776,7 +777,7 @@ func testV1RsDBStore(t *testing.T) { func testV1RsGetResourceProfileBeforeSet(t *testing.T) { var reply *string - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -805,12 +806,12 @@ func testV1RsSetResourceProfile(t *testing.T) { var result string expErr := "SERVER_ERROR: broken reference to filter: <*wrong:inline> for item with ID: cgrates.org:RES_GR_TEST" - if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err == nil || err.Error() != expErr { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err == nil || err.Error() != expErr { t.Fatalf("Expected error: %q, received: %v", expErr, err) } rlsConfig.FilterIDs = []string{"*string:~*req.Account:1001"} - if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -821,10 +822,10 @@ func testV1RsGetResourceProfileIDs(t *testing.T) { expected := []string{"ResGroup2", "ResGroup1", "ResGroup3", "RES_GR_TEST"} sort.Strings(expected) var result []string - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfileIDs, utils.PaginatorWithTenant{}, &result); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfileIDs, utils.PaginatorWithTenant{}, &result); err != nil { t.Error(err) } - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { t.Error(err) } sort.Strings(result) @@ -835,7 +836,7 @@ func testV1RsGetResourceProfileIDs(t *testing.T) { func testV1RsGetResourceProfileAfterSet(t *testing.T) { var reply *engine.ResourceProfile - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, rlsConfig.ResourceProfile) { @@ -846,7 +847,7 @@ func testV1RsGetResourceProfileAfterSet(t *testing.T) { func testV1RsUpdateResourceProfile(t *testing.T) { var result string rlsConfig.FilterIDs = []string{"*string:~*req.Account:1001", "*prefix:~*req.DST:10"} - if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -855,7 +856,7 @@ func testV1RsUpdateResourceProfile(t *testing.T) { func testV1RsGetResourceProfileAfterUpdate(t *testing.T) { var reply *engine.ResourceProfile - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &reply); err != nil { t.Error(err) } else { @@ -869,13 +870,13 @@ func testV1RsGetResourceProfileAfterUpdate(t *testing.T) { func testV1RsRemResourceProfile(t *testing.T) { var resp string - if err := rlsV1Rpc.Call(utils.APIerSv1RemoveResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1RemoveResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } - if err := rlsV1Rpc.Call(utils.APIerSv1RemoveResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1RemoveResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &resp); err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err) } @@ -883,7 +884,7 @@ func testV1RsRemResourceProfile(t *testing.T) { func testV1RsGetResourceProfileAfterDelete(t *testing.T) { var reply *string - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -892,7 +893,7 @@ func testV1RsGetResourceProfileAfterDelete(t *testing.T) { func testV1RsResourcePing(t *testing.T) { var resp string - if err := rlsV1Rpc.Call(utils.ResourceSv1Ping, new(utils.CGREvent), &resp); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1Ping, new(utils.CGREvent), &resp); err != nil { t.Error(err) } else if resp != utils.Pong { t.Error("Unexpected reply returned", resp) @@ -916,7 +917,7 @@ func testV1RsMatchNotFound(t *testing.T) { var result string - if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -935,7 +936,7 @@ func testV1RsMatchNotFound(t *testing.T) { }, } var reply string - if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1ReleaseResources, argsRU, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -960,7 +961,7 @@ func testV1RsAllocateUnlimited(t *testing.T) { } var result string - if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -977,7 +978,7 @@ func testV1RsAllocateUnlimited(t *testing.T) { utils.OptsResourcesUnits: 1, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } else if reply != "CustomUnlimitedMessage" { @@ -995,7 +996,7 @@ func testV1RsAllocateUnlimited(t *testing.T) { }, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{ + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RES_ULTIMITED"}, }, &rplyRes); err != nil { t.Error(err) @@ -1030,14 +1031,14 @@ func testV1RsGetResourceProfileWithoutTenant(t *testing.T) { }, } var reply string - if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } rlsConfig.Tenant = "cgrates.org" var result *engine.ResourceProfile - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{ID: rlsConfig.ID}, &result); err != nil { t.Error(err) @@ -1048,7 +1049,7 @@ func testV1RsGetResourceProfileWithoutTenant(t *testing.T) { func testV1RsRemResourceProfileWithoutTenant(t *testing.T) { var reply string - if err := rlsV1Rpc.Call(utils.APIerSv1RemoveResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1RemoveResourceProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: rlsConfig.ID}}, &reply); err != nil { t.Error(err) @@ -1056,7 +1057,7 @@ func testV1RsRemResourceProfileWithoutTenant(t *testing.T) { t.Error("Unexpected reply returned", reply) } var result *engine.ResourceProfile - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{ID: rlsConfig.ID}, &result); err == nil || utils.ErrNotFound.Error() != err.Error() { t.Error(err) @@ -1077,14 +1078,14 @@ func testV1RsSetResourceProfileWithOpts(t *testing.T) { }, } var reply string - if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsCfg, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsCfg, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } var result *engine.ResourceProfile - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_WITH_OPTS"}, &result); err != nil { t.Error(err) @@ -1108,14 +1109,14 @@ func testV1RsAuthorizeResourcesWithOpts(t *testing.T) { utils.OptsResourcesUnits: 6, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &ev, &reply); err != nil { t.Error(err) } else if reply != "TEST_WITH_OPTS" { t.Error("Unexpected reply returned", reply) } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, &ev, &reply); err != nil { t.Error(err) @@ -1137,7 +1138,7 @@ func testV1RsCheckAuthorizeResourcesAfterRestart(t *testing.T) { }, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{ + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RES_ULTIMITED"}, }, &rplyRes); err != nil { t.Error(err) @@ -1151,7 +1152,7 @@ func testV1RsCheckAuthorizeResourcesAfterRestart(t *testing.T) { ID: "TEST_WITH_OPTS", Usages: map[string]*engine.ResourceUsage{}, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{ + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_WITH_OPTS"}, }, &rplyRes); err != nil { t.Error(err) @@ -1164,7 +1165,7 @@ func testV1RsCheckAuthorizeResourcesAfterRestart(t *testing.T) { func testV1ResourceStopCPUProfiling(t *testing.T) { argPath := "/tmp/cpu.prof" var reply string - if err := rlsV1Rpc.Call(utils.CoreSv1StopCPUProfiling, + if err := rlsV1Rpc.Call(context.Background(), utils.CoreSv1StopCPUProfiling, new(utils.DirectoryArgs), &reply); err != nil { t.Error(err) } @@ -1189,7 +1190,7 @@ func testV1ResourceStopCPUProfiling(t *testing.T) { func testResourceSCacheTestGetNotFound(t *testing.T) { var reply *engine.ChargerProfile - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RESOURCE_CACHE"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -1198,7 +1199,7 @@ func testResourceSCacheTestGetNotFound(t *testing.T) { func testResourceSCacheTestGetFound(t *testing.T) { var reply *engine.ChargerProfile - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RESOURCE_CACHE"}, &reply); err != nil { t.Fatal(err) } @@ -1215,7 +1216,7 @@ func testResourceSCacheTestSet(t *testing.T) { }, } var result string - if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1227,7 +1228,7 @@ func testResourceSCacheReload(t *testing.T) { ResourceProfileIDs: []string{"cgrates.org:RESOURCE_CACHE"}, } var reply string - if err := rlsV1Rpc.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.CacheSv1ReloadCache, cache, &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Error("Calling CacheSv1.ReloadCache got reply: ", reply) @@ -1244,7 +1245,7 @@ func testResourceSSetThresholdProfile(t *testing.T) { }, } var reply string - if err := rlsV1Rpc.Call(utils.APIerSv1SetThresholdProfile, ThdPrf, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, ThdPrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -1256,7 +1257,7 @@ func testResourceSSetThresholdProfile(t *testing.T) { ID: "THD_1", } var result *engine.ThresholdProfile - if err := rlsV1Rpc.Call(utils.APIerSv1GetThresholdProfile, args, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, args, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(result, ThdPrf.ThresholdProfile) { @@ -1274,7 +1275,7 @@ func testResourceSSetResourceProfile(t *testing.T) { ThresholdIDs: []string{"THD_1"}, } var reply string - if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, ResPrf, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, ResPrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -1282,7 +1283,7 @@ func testResourceSSetResourceProfile(t *testing.T) { } var result *engine.ResourceProfile - if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile, + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: ResPrf.ID}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(result, ResPrf) { @@ -1304,7 +1305,7 @@ func testResourceSCheckThresholdAfterResourceAllocate(t *testing.T) { utils.OptsResourcesUnits: 5, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, ev, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } else if reply != "Approved" { @@ -1316,7 +1317,7 @@ func testResourceSCheckThresholdAfterResourceAllocate(t *testing.T) { ID: "THD_1", } var result *engine.Threshold - if err := rlsV1Rpc.Call(utils.ThresholdSv1GetThreshold, args, + if err := rlsV1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, args, &result); err != nil { t.Error(err) } else if result.Hits != 1 { @@ -1336,7 +1337,7 @@ func testResourceSCheckThresholdAfterResourceRelease(t *testing.T) { }, } var reply string - if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources, ev, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1ReleaseResources, ev, &reply); err != nil { t.Error(err) } @@ -1346,7 +1347,7 @@ func testResourceSCheckThresholdAfterResourceRelease(t *testing.T) { ID: "THD_1", } var result *engine.Threshold - if err := rlsV1Rpc.Call(utils.ThresholdSv1GetThreshold, args, + if err := rlsV1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, args, &result); err != nil { t.Error(err) } else if result.Hits != 2 { diff --git a/apier/v1/routes.go b/apier/v1/routes.go index 10fe322ce..ab410c91c 100644 --- a/apier/v1/routes.go +++ b/apier/v1/routes.go @@ -21,12 +21,13 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // GetRouteProfile returns a Route configuration -func (apierSv1 *APIerSv1) GetRouteProfile(arg *utils.TenantID, reply *engine.RouteProfile) error { +func (apierSv1 *APIerSv1) GetRouteProfile(ctx *context.Context, arg *utils.TenantID, reply *engine.RouteProfile) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -43,7 +44,7 @@ func (apierSv1 *APIerSv1) GetRouteProfile(arg *utils.TenantID, reply *engine.Rou } // GetRouteProfileIDs returns list of routeProfile IDs registered for a tenant -func (apierSv1 *APIerSv1) GetRouteProfileIDs(args *utils.PaginatorWithTenant, sppPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetRouteProfileIDs(ctx *context.Context, args *utils.PaginatorWithTenant, sppPrfIDs *[]string) error { tnt := args.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -70,7 +71,7 @@ type RouteWithAPIOpts struct { } // SetRouteProfile add a new Route configuration -func (apierSv1 *APIerSv1) SetRouteProfile(args *RouteWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) SetRouteProfile(ctx *context.Context, args *RouteWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(args.RouteProfile, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -94,7 +95,7 @@ func (apierSv1 *APIerSv1) SetRouteProfile(args *RouteWithAPIOpts, reply *string) } // RemoveRouteProfile remove a specific Route configuration -func (apierSv1 *APIerSv1) RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) RemoveRouteProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -127,27 +128,27 @@ type RouteSv1 struct { rS *engine.RouteService } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (rS *RouteSv1) Call(serviceMethod string, args any, reply any) error { +// Call implements birpc.ClientConnector interface for internal RPC +func (rS *RouteSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(rS, serviceMethod, args, reply) } // GetRoutes returns sorted list of routes for Event -func (rS *RouteSv1) GetRoutes(args *utils.CGREvent, reply *engine.SortedRoutesList) error { - return rS.rS.V1GetRoutes(args, reply) +func (rS *RouteSv1) GetRoutes(ctx *context.Context, args *utils.CGREvent, reply *engine.SortedRoutesList) error { + return rS.rS.V1GetRoutes(ctx, args, reply) } // GetRouteProfilesForEvent returns a list of route profiles that match for Event -func (rS *RouteSv1) GetRouteProfilesForEvent(args *utils.CGREvent, reply *[]*engine.RouteProfile) error { - return rS.rS.V1GetRouteProfilesForEvent(args, reply) +func (rS *RouteSv1) GetRouteProfilesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*engine.RouteProfile) error { + return rS.rS.V1GetRouteProfilesForEvent(ctx, args, reply) } -func (rS *RouteSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (rS *RouteSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } // GetRoutesList returns sorted list of routes for Event as a string slice -func (rS *RouteSv1) GetRoutesList(args *utils.CGREvent, reply *[]string) error { - return rS.rS.V1GetRoutesList(args, reply) +func (rS *RouteSv1) GetRoutesList(ctx *context.Context, args *utils.CGREvent, reply *[]string) error { + return rS.rS.V1GetRoutesList(ctx, args, reply) } diff --git a/apier/v1/routes_it_test.go b/apier/v1/routes_it_test.go index 2bcc29296..99ccc3ee2 100644 --- a/apier/v1/routes_it_test.go +++ b/apier/v1/routes_it_test.go @@ -21,13 +21,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( routeSv1CfgPath string routeSv1Cfg *config.CGRConfig - routeSv1Rpc *rpc.Client + routeSv1Rpc *birpc.Client routePrf *RouteWithAPIOpts routeSv1ConfDIR string //run tests for specific configuration @@ -131,7 +132,7 @@ func testV1RouteInitDataDb(t *testing.T) { func testV1RouteClearCache(t *testing.T) { var reply string - if err := routeSv1Rpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil { t.Fatal(err) } } @@ -159,7 +160,7 @@ func testV1RouteRpcConn(t *testing.T) { func testV1RouteGetBeforeDataLoad(t *testing.T) { var suplsReply *engine.RouteProfile - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ Tenant: "cgrates.org", ID: "ROUTE_WEIGHT_1", @@ -171,7 +172,7 @@ func testV1RouteGetBeforeDataLoad(t *testing.T) { func testV1RouteFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := routeSv1Rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -206,7 +207,7 @@ func testV1RouteGetWeightRoutes(t *testing.T) { }, }} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -215,7 +216,7 @@ func testV1RouteGetWeightRoutes(t *testing.T) { } ev.Tenant = utils.EmptyString - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -268,7 +269,7 @@ func testV1RouteGetLeastCostRoutes(t *testing.T) { }, }} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -320,7 +321,7 @@ func testV1RouteGetLeastCostRoutesWithoutUsage(t *testing.T) { }, }} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -368,7 +369,7 @@ func testV1RouteGetLeastCostRoutesWithMaxCost(t *testing.T) { }, }} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -393,7 +394,7 @@ func testV1RouteGetLeastCostRoutesWithMaxCostNotFound(t *testing.T) { }, } var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil && err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -439,7 +440,7 @@ func testV1RouteGetLeastCostRoutesWithMaxCost2(t *testing.T) { }, }} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -492,7 +493,7 @@ func testV1RouteGetHighestCostRoutes(t *testing.T) { }, }} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -528,7 +529,7 @@ func testV1RouteGetLeastCostRoutesErr(t *testing.T) { }, }} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -550,7 +551,7 @@ func testV1RoutePolulateStatsForQOS(t *testing.T) { utils.Cost: 10.0, }, } - if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -567,7 +568,7 @@ func testV1RoutePolulateStatsForQOS(t *testing.T) { utils.Cost: 10.5, }, } - if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -584,7 +585,7 @@ func testV1RoutePolulateStatsForQOS(t *testing.T) { utils.Cost: 12.5, }, } - if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -601,7 +602,7 @@ func testV1RoutePolulateStatsForQOS(t *testing.T) { utils.Cost: 17.5, }, } - if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -618,7 +619,7 @@ func testV1RoutePolulateStatsForQOS(t *testing.T) { utils.Cost: 12.5, }, } - if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -636,7 +637,7 @@ func testV1RoutePolulateStatsForQOS(t *testing.T) { utils.PDD: 12 * time.Second, }, } - if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -654,7 +655,7 @@ func testV1RoutePolulateStatsForQOS(t *testing.T) { utils.PDD: 15 * time.Second, }, } - if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -671,7 +672,7 @@ func testV1RouteGetQOSRoutes(t *testing.T) { } expRouteIDs := []string{"route1", "route3", "route2"} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { @@ -700,7 +701,7 @@ func testV1RouteGetQOSRoutes2(t *testing.T) { } expRouteIDs := []string{"route3", "route2", "route1"} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { @@ -729,7 +730,7 @@ func testV1RouteGetQOSRoutes3(t *testing.T) { } expRouteIDs := []string{"route1", "route3", "route2"} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { @@ -758,7 +759,7 @@ func testV1RouteGetQOSRoutesFiltred(t *testing.T) { } expRouteIDs := []string{"route1", "route3"} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { @@ -791,7 +792,7 @@ func testV1RouteGetQOSRoutesFiltred2(t *testing.T) { } expRouteIDs := []string{"route3", "route2"} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { @@ -832,7 +833,7 @@ func testV1RouteGetRouteWithoutFilter(t *testing.T) { }, }} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -868,23 +869,23 @@ func testV1RouteSetRouteProfiles(t *testing.T) { var result string expErr := "SERVER_ERROR: broken reference to filter: for item with ID: cgrates.org:TEST_PROFILE1" - if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err == nil || err.Error() != expErr { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, routePrf, &result); err == nil || err.Error() != expErr { t.Fatalf("Expected error: %q, received: %v", expErr, err) } var reply *engine.RouteProfile - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } routePrf.FilterIDs = []string{"FLTR_1"} - if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(routePrf.RouteProfile, reply) { @@ -897,14 +898,14 @@ func testV1RouteGetRouteProfileIDs(t *testing.T) { "ROUTE_ACNT_1001", "ROUTE_LEASTCOST_1", "ROUTE_WEIGHT_2", "ROUTE_WEIGHT_1", "ROUTE_QOS_3", "TEST_PROFILE1", "ROUTE_LOAD_DIST", "ROUTE_LCR"} var result []string - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfileIDs, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfileIDs, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { @@ -962,13 +963,13 @@ func testV1RouteUpdateRouteProfiles(t *testing.T) { }, } var result string - if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.RouteProfile - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(routePrf.Routes, reply.Routes) && !reflect.DeepEqual(reverseRoutes, reply.Routes) { @@ -978,19 +979,19 @@ func testV1RouteUpdateRouteProfiles(t *testing.T) { func testV1RouteRemRouteProfiles(t *testing.T) { var resp string - if err := routeSv1Rpc.Call(utils.APIerSv1RemoveRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1RemoveRouteProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } var reply *engine.RouteProfile - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := routeSv1Rpc.Call(utils.APIerSv1RemoveRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1RemoveRouteProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &resp); err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err) } @@ -998,7 +999,7 @@ func testV1RouteRemRouteProfiles(t *testing.T) { func testV1RouteRoutePing(t *testing.T) { var resp string - if err := routeSv1Rpc.Call(utils.RouteSv1Ping, new(utils.CGREvent), &resp); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1Ping, new(utils.CGREvent), &resp); err != nil { t.Error(err) } else if resp != utils.Pong { t.Error("Unexpected reply returned", resp) @@ -1055,7 +1056,7 @@ func testV1RouteGetRouteForEvent(t *testing.T) { expected.SortingParameters = nil } var supProf []*engine.RouteProfile - if err := routeSv1Rpc.Call(utils.RouteSv1GetRouteProfilesForEvent, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRouteProfilesForEvent, ev, &supProf); err != nil { t.Fatal(err) } @@ -1071,7 +1072,7 @@ func testV1RouteGetRouteForEvent(t *testing.T) { supProf = nil ev.Tenant = utils.EmptyString - if err := routeSv1Rpc.Call(utils.RouteSv1GetRouteProfilesForEvent, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRouteProfilesForEvent, ev, &supProf); err != nil { t.Fatal(err) } @@ -1099,7 +1100,7 @@ func testV1RouteGetRouteForEvent(t *testing.T) { // route1 have attached RP_LOCAL and route2 have attach RP_MOBILE func testV1RoutesOneRouteWithoutDestination(t *testing.T) { var reply *engine.RouteProfile - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_DESTINATION"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1128,7 +1129,7 @@ func testV1RoutesOneRouteWithoutDestination(t *testing.T) { } var result string - if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1160,7 +1161,7 @@ func testV1RoutesOneRouteWithoutDestination(t *testing.T) { }, }} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -1171,7 +1172,7 @@ func testV1RoutesOneRouteWithoutDestination(t *testing.T) { func testV1RouteMultipleRouteSameID(t *testing.T) { var reply *engine.RouteProfile - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "MULTIPLE_ROUTES"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1201,7 +1202,7 @@ func testV1RouteMultipleRouteSameID(t *testing.T) { } var result string - if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1235,7 +1236,7 @@ func testV1RouteMultipleRouteSameID(t *testing.T) { }, }} var suplsReply engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -1270,7 +1271,7 @@ func testV1RouteMultipleRouteSameID(t *testing.T) { }, }, }} - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -1304,7 +1305,7 @@ func testV1RouteAccountWithRatingPlan(t *testing.T) { } var result string - if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1320,7 +1321,7 @@ func testV1RouteAccountWithRatingPlan(t *testing.T) { }, } var reply string - if err := routeSv1Rpc.Call(utils.APIerSv2SetBalance, &attrSetBalance, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv2SetBalance, &attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -1330,7 +1331,7 @@ func testV1RouteAccountWithRatingPlan(t *testing.T) { Tenant: "cgrates.org", Account: "AccWithVoice", } - if err := routeSv1Rpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 30*float64(time.Second) { t.Errorf("Unexpected balance received : %+v", acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) @@ -1397,7 +1398,7 @@ func testV1RouteAccountWithRatingPlan(t *testing.T) { } } var suplsReply *engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, suplsReply) { @@ -1467,7 +1468,7 @@ func testV1RouteAccountWithRatingPlan(t *testing.T) { } } var routeRply *engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &routeRply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, routeRply) { @@ -1537,7 +1538,7 @@ func testV1RouteAccountWithRatingPlan(t *testing.T) { } } var routeRply2 *engine.SortedRoutesList - if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := routeSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &routeRply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(eSpls, routeRply2) { @@ -1578,14 +1579,14 @@ func testV1RouteSetRouteProfilesWithoutTenant(t *testing.T) { }, } var reply string - if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, routePrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } routePrf.Tenant = "cgrates.org" var result *engine.RouteProfile - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ID: "TEST_PROFILE10"}, &result); err != nil { t.Error(err) @@ -1596,13 +1597,13 @@ func testV1RouteSetRouteProfilesWithoutTenant(t *testing.T) { func testV1RouteRemRouteProfilesWithoutTenant(t *testing.T) { var reply string - if err := routeSv1Rpc.Call(utils.APIerSv1RemoveRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1RemoveRouteProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "TEST_PROFILE10"}}, &reply); err != nil { t.Error(err) } var result *engine.RouteProfile - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ID: "TEST_PROFILE10"}, &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1611,7 +1612,7 @@ func testV1RouteRemRouteProfilesWithoutTenant(t *testing.T) { func testRouteSCacheTestGetNotFound(t *testing.T) { var suplsReply *engine.RouteProfile - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ Tenant: "cgrates.org", ID: "ROUTE_CACHE", @@ -1622,7 +1623,7 @@ func testRouteSCacheTestGetNotFound(t *testing.T) { func testRouteSCacheTestGetFound(t *testing.T) { var suplsReply *engine.RouteProfile - if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ Tenant: "cgrates.org", ID: "ROUTE_CACHE", @@ -1656,7 +1657,7 @@ func testRouteSCacheTestSet(t *testing.T) { } var result string - if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1668,7 +1669,7 @@ func testRouteSCacheReload(t *testing.T) { RouteProfileIDs: []string{"cgrates.org:ROUTE_CACHE"}, } var reply string - if err := routeSv1Rpc.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil { + if err := routeSv1Rpc.Call(context.Background(), utils.CacheSv1ReloadCache, cache, &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Error("Calling CacheSv1.ReloadCache got reply: ", reply) diff --git a/apier/v1/scheduler.go b/apier/v1/scheduler.go index c168ebdde..99c6c2dd7 100644 --- a/apier/v1/scheduler.go +++ b/apier/v1/scheduler.go @@ -21,6 +21,7 @@ package v1 import ( "errors" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/scheduler" "github.com/cgrates/cgrates/utils" ) @@ -96,7 +97,7 @@ import ( ] */ -func (apierSv1 *APIerSv1) GetScheduledActions(args *scheduler.ArgsGetScheduledActions, reply *[]*scheduler.ScheduledAction) error { +func (apierSv1 *APIerSv1) GetScheduledActions(ctx *context.Context, args *scheduler.ArgsGetScheduledActions, reply *[]*scheduler.ScheduledAction) error { sched := apierSv1.SchedulerService.GetScheduler() if sched == nil { return errors.New(utils.SchedulerNotRunningCaps) diff --git a/apier/v1/schedulers.go b/apier/v1/schedulers.go index 382a62e01..7bcc59b0c 100644 --- a/apier/v1/schedulers.go +++ b/apier/v1/schedulers.go @@ -22,6 +22,7 @@ import ( "sort" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -40,14 +41,14 @@ type SchedulerSv1 struct { } // Reload reloads scheduler instructions -func (schdSv1 *SchedulerSv1) Reload(arg *utils.CGREvent, reply *string) error { +func (schdSv1 *SchedulerSv1) Reload(ctx *context.Context, arg *utils.CGREvent, reply *string) error { schdSv1.cgrcfg.GetReloadChan(config.SCHEDULER_JSN) <- struct{}{} *reply = utils.OK return nil } // ExecuteActions execute an actionPlan or multiple actionsPlans between a time interval -func (schdSv1 *SchedulerSv1) ExecuteActions(attr *utils.AttrsExecuteActions, reply *string) error { +func (schdSv1 *SchedulerSv1) ExecuteActions(ctx *context.Context, attr *utils.AttrsExecuteActions, reply *string) error { if attr.ActionPlanID != utils.EmptyString { // execute by ActionPlanID apl, err := schdSv1.dm.GetActionPlan(attr.ActionPlanID, true, true, utils.NonTransactional) if err != nil { @@ -134,7 +135,7 @@ func (schdSv1 *SchedulerSv1) ExecuteActions(attr *utils.AttrsExecuteActions, rep } // ExecuteActionPlans execute multiple actionPlans one by one -func (schdSv1 *SchedulerSv1) ExecuteActionPlans(attr *utils.AttrsExecuteActionPlans, reply *string) (err error) { +func (schdSv1 *SchedulerSv1) ExecuteActionPlans(ctx *context.Context, attr *utils.AttrsExecuteActionPlans, reply *string) (err error) { // try get account // if not exist set in DM accID := utils.ConcatenatedKey(attr.Tenant, attr.AccountID) @@ -173,13 +174,13 @@ func (schdSv1 *SchedulerSv1) ExecuteActionPlans(attr *utils.AttrsExecuteActionPl } // Ping returns Pong -func (schdSv1 *SchedulerSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (schdSv1 *SchedulerSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (schdSv1 *SchedulerSv1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (schdSv1 *SchedulerSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(schdSv1, serviceMethod, args, reply) } diff --git a/apier/v1/schedulers_it_test.go b/apier/v1/schedulers_it_test.go index dce1086b3..6c2aa5fc6 100644 --- a/apier/v1/schedulers_it_test.go +++ b/apier/v1/schedulers_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" "github.com/cgrates/cgrates/engine" @@ -36,7 +37,7 @@ import ( var ( schedCfgPath string schedCfg *config.CGRConfig - schedRpc *rpc.Client + schedRpc *birpc.Client schedConfDIR string //run tests for specific configuration ) @@ -149,7 +150,7 @@ func testSchedRpcConn(t *testing.T) { func testSchedFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := schedRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -165,7 +166,7 @@ func testSchedVeifyAllAccounts(t *testing.T) { Tenant: "cgrates.org", Account: "1001", } - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != 10 { t.Errorf("Expecting: %v, received: %v", @@ -175,7 +176,7 @@ func testSchedVeifyAllAccounts(t *testing.T) { Tenant: "cgrates.org", Account: "1002", } - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != 10 { t.Errorf("Expecting: %v, received: %v", @@ -185,7 +186,7 @@ func testSchedVeifyAllAccounts(t *testing.T) { Tenant: "cgrates.org", Account: "1003", } - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != 10 { t.Errorf("Expecting: %v, received: %v", @@ -202,7 +203,7 @@ func testSchedVeifyAccount1001(t *testing.T) { Tenant: "cgrates.org", Account: "1001", } - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != 10 { t.Errorf("Expecting: %v, received: %v", @@ -214,7 +215,7 @@ func testSchedVeifyAccount1001(t *testing.T) { Tenant: "cgrates.org", Account: "1002", } - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if lenBal := len(acnt.BalanceMap[utils.MetaMonetary]); lenBal != 0 { t.Errorf("Expecting: %v, received: %v", @@ -225,7 +226,7 @@ func testSchedVeifyAccount1001(t *testing.T) { Tenant: "cgrates.org", Account: "1003", } - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if lenBal := len(acnt.BalanceMap[utils.MetaMonetary]); lenBal != 0 { t.Errorf("Expecting: %v, received: %v", @@ -243,7 +244,7 @@ func testSchedVeifyAccount1002and1003(t *testing.T) { Tenant: "cgrates.org", Account: "1001", } - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if lenBal := len(acnt.BalanceMap[utils.MetaMonetary]); lenBal != 0 { t.Errorf("Expecting: %v, received: %v", @@ -254,7 +255,7 @@ func testSchedVeifyAccount1002and1003(t *testing.T) { Tenant: "cgrates.org", Account: "1002", } - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != 10 { t.Errorf("Expecting: %v, received: %v", @@ -265,7 +266,7 @@ func testSchedVeifyAccount1002and1003(t *testing.T) { Tenant: "cgrates.org", Account: "1003", } - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != 10 { t.Errorf("Expecting: %v, received: %v", @@ -279,7 +280,7 @@ func testSchedExecuteAction(t *testing.T) { } // set a new ActionPlan var reply1 string - if err := schedRpc.Call(utils.APIerSv1SetActionPlan, &AttrSetActionPlan{ + if err := schedRpc.Call(context.Background(), utils.APIerSv1SetActionPlan, &AttrSetActionPlan{ Id: "CustomAP", ActionPlan: []*AttrActionPlan{ { @@ -293,7 +294,7 @@ func testSchedExecuteAction(t *testing.T) { t.Errorf("Unexpected reply returned: %s", reply1) } var reply string - if err := schedRpc.Call(utils.APIerSv1SetAccount, utils.AttrSetAccount{ + if err := schedRpc.Call(context.Background(), utils.APIerSv1SetAccount, utils.AttrSetAccount{ Tenant: "cgrates.org", Account: "CustomAccount", ActionPlanID: "CustomAP", @@ -307,18 +308,18 @@ func testSchedExecuteAction(t *testing.T) { Account: "CustomAccount", } expected := 0.0 - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != expected { t.Errorf("Expecting: %v, received: %v", expected, rply) } - if err := schedRpc.Call(utils.SchedulerSv1ExecuteActions, &utils.AttrsExecuteActions{ActionPlanID: "CustomAP"}, &reply); err != nil { + if err := schedRpc.Call(context.Background(), utils.SchedulerSv1ExecuteActions, &utils.AttrsExecuteActions{ActionPlanID: "CustomAP"}, &reply); err != nil { t.Error(err) } expected = 10.0 - if err := schedRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := schedRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != expected { t.Errorf("Expecting: %v, received: %v", diff --git a/apier/v1/servicemanager.go b/apier/v1/servicemanager.go index 34198eaff..53aa9cf50 100644 --- a/apier/v1/servicemanager.go +++ b/apier/v1/servicemanager.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" @@ -32,26 +33,26 @@ type ServiceManagerV1 struct { sm *servmanager.ServiceManager // Need to have them capitalize so we can export in V2 } -func (servManager *ServiceManagerV1) StartService(args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) (err error) { - return servManager.sm.V1StartService(args.ArgStartService, reply) +func (servManager *ServiceManagerV1) StartService(ctx *context.Context, args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) (err error) { + return servManager.sm.V1StartService(ctx, args.ArgStartService, reply) } -func (servManager *ServiceManagerV1) StopService(args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) (err error) { - return servManager.sm.V1StopService(args.ArgStartService, reply) +func (servManager *ServiceManagerV1) StopService(ctx *context.Context, args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) (err error) { + return servManager.sm.V1StopService(ctx, args.ArgStartService, reply) } -func (servManager *ServiceManagerV1) ServiceStatus(args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) (err error) { - return servManager.sm.V1ServiceStatus(args.ArgStartService, reply) +func (servManager *ServiceManagerV1) ServiceStatus(ctx *context.Context, args *dispatchers.ArgStartServiceWithAPIOpts, reply *string) (err error) { + return servManager.sm.V1ServiceStatus(ctx, args.ArgStartService, reply) } // Ping return pong if the service is active -func (servManager *ServiceManagerV1) Ping(ign *utils.CGREvent, reply *string) error { +func (servManager *ServiceManagerV1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (servManager *ServiceManagerV1) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (servManager *ServiceManagerV1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(servManager, serviceMethod, args, reply) } diff --git a/apier/v1/sessions.go b/apier/v1/sessions.go index 357d2aacf..7e15bad5f 100644 --- a/apier/v1/sessions.go +++ b/apier/v1/sessions.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" @@ -35,131 +36,138 @@ type SessionSv1 struct { sS *sessions.SessionS } -func (ssv1 *SessionSv1) AuthorizeEvent(args *sessions.V1AuthorizeArgs, +func (ssv1 *SessionSv1) AuthorizeEvent(ctx *context.Context, args *sessions.V1AuthorizeArgs, rply *sessions.V1AuthorizeReply) error { - return ssv1.sS.BiRPCv1AuthorizeEvent(nil, args, rply) + return ssv1.sS.BiRPCv1AuthorizeEvent(ctx, args, rply) } -func (ssv1 *SessionSv1) AuthorizeEventWithDigest(args *sessions.V1AuthorizeArgs, +func (ssv1 *SessionSv1) AuthorizeEventWithDigest(ctx *context.Context, args *sessions.V1AuthorizeArgs, rply *sessions.V1AuthorizeReplyWithDigest) error { - return ssv1.sS.BiRPCv1AuthorizeEventWithDigest(nil, args, rply) + return ssv1.sS.BiRPCv1AuthorizeEventWithDigest(ctx, args, rply) } -func (ssv1 *SessionSv1) InitiateSession(args *sessions.V1InitSessionArgs, +func (ssv1 *SessionSv1) InitiateSession(ctx *context.Context, args *sessions.V1InitSessionArgs, rply *sessions.V1InitSessionReply) error { - return ssv1.sS.BiRPCv1InitiateSession(nil, args, rply) + return ssv1.sS.BiRPCv1InitiateSession(ctx, args, rply) } -func (ssv1 *SessionSv1) InitiateSessionWithDigest(args *sessions.V1InitSessionArgs, +func (ssv1 *SessionSv1) InitiateSessionWithDigest(ctx *context.Context, args *sessions.V1InitSessionArgs, rply *sessions.V1InitReplyWithDigest) error { - return ssv1.sS.BiRPCv1InitiateSessionWithDigest(nil, args, rply) + return ssv1.sS.BiRPCv1InitiateSessionWithDigest(ctx, args, rply) } -func (ssv1 *SessionSv1) UpdateSession(args *sessions.V1UpdateSessionArgs, +func (ssv1 *SessionSv1) UpdateSession(ctx *context.Context, args *sessions.V1UpdateSessionArgs, rply *sessions.V1UpdateSessionReply) error { - return ssv1.sS.BiRPCv1UpdateSession(nil, args, rply) + return ssv1.sS.BiRPCv1UpdateSession(ctx, args, rply) } -func (ssv1 *SessionSv1) SyncSessions(args *utils.TenantWithAPIOpts, +func (ssv1 *SessionSv1) SyncSessions(ctx *context.Context, args *utils.TenantWithAPIOpts, rply *string) error { - return ssv1.sS.BiRPCv1SyncSessions(nil, &utils.TenantWithAPIOpts{}, rply) + return ssv1.sS.BiRPCv1SyncSessions(ctx, &utils.TenantWithAPIOpts{}, rply) } -func (ssv1 *SessionSv1) TerminateSession(args *sessions.V1TerminateSessionArgs, +func (ssv1 *SessionSv1) TerminateSession(ctx *context.Context, args *sessions.V1TerminateSessionArgs, rply *string) error { - return ssv1.sS.BiRPCv1TerminateSession(nil, args, rply) + return ssv1.sS.BiRPCv1TerminateSession(ctx, args, rply) } -func (ssv1 *SessionSv1) ProcessCDR(cgrEv *utils.CGREvent, rply *string) error { - return ssv1.sS.BiRPCv1ProcessCDR(nil, cgrEv, rply) +func (ssv1 *SessionSv1) ProcessCDR(ctx *context.Context, cgrEv *utils.CGREvent, rply *string) error { + return ssv1.sS.BiRPCv1ProcessCDR(ctx, cgrEv, rply) } -func (ssv1 *SessionSv1) ProcessMessage(args *sessions.V1ProcessMessageArgs, +func (ssv1 *SessionSv1) ProcessMessage(ctx *context.Context, args *sessions.V1ProcessMessageArgs, rply *sessions.V1ProcessMessageReply) error { - return ssv1.sS.BiRPCv1ProcessMessage(nil, args, rply) + return ssv1.sS.BiRPCv1ProcessMessage(ctx, args, rply) } -func (ssv1 *SessionSv1) ProcessEvent(args *sessions.V1ProcessEventArgs, +func (ssv1 *SessionSv1) ProcessEvent(ctx *context.Context, args *sessions.V1ProcessEventArgs, rply *sessions.V1ProcessEventReply) error { - return ssv1.sS.BiRPCv1ProcessEvent(nil, args, rply) + return ssv1.sS.BiRPCv1ProcessEvent(ctx, args, rply) } -func (ssv1 *SessionSv1) GetCost(args *sessions.V1ProcessEventArgs, +func (ssv1 *SessionSv1) GetCost(ctx *context.Context, args *sessions.V1ProcessEventArgs, rply *sessions.V1GetCostReply) error { - return ssv1.sS.BiRPCv1GetCost(nil, args, rply) + return ssv1.sS.BiRPCv1GetCost(ctx, args, rply) } -func (ssv1 *SessionSv1) GetActiveSessions(args *utils.SessionFilter, +func (ssv1 *SessionSv1) GetActiveSessions(ctx *context.Context, args *utils.SessionFilter, rply *[]*sessions.ExternalSession) error { - return ssv1.sS.BiRPCv1GetActiveSessions(nil, args, rply) + return ssv1.sS.BiRPCv1GetActiveSessions(ctx, args, rply) } -func (ssv1 *SessionSv1) GetActiveSessionsCount(args *utils.SessionFilter, +func (ssv1 *SessionSv1) GetActiveSessionsCount(ctx *context.Context, args *utils.SessionFilter, rply *int) error { - return ssv1.sS.BiRPCv1GetActiveSessionsCount(nil, args, rply) + return ssv1.sS.BiRPCv1GetActiveSessionsCount(ctx, args, rply) } -func (ssv1 *SessionSv1) ForceDisconnect(args *utils.SessionFilter, +func (ssv1 *SessionSv1) ForceDisconnect(ctx *context.Context, args *utils.SessionFilter, rply *string) error { - return ssv1.sS.BiRPCv1ForceDisconnect(nil, args, rply) + return ssv1.sS.BiRPCv1ForceDisconnect(ctx, args, rply) } -func (ssv1 *SessionSv1) GetPassiveSessions(args *utils.SessionFilter, +func (ssv1 *SessionSv1) GetPassiveSessions(ctx *context.Context, args *utils.SessionFilter, rply *[]*sessions.ExternalSession) error { - return ssv1.sS.BiRPCv1GetPassiveSessions(nil, args, rply) + return ssv1.sS.BiRPCv1GetPassiveSessions(ctx, args, rply) } -func (ssv1 *SessionSv1) GetPassiveSessionsCount(args *utils.SessionFilter, +func (ssv1 *SessionSv1) GetPassiveSessionsCount(ctx *context.Context, args *utils.SessionFilter, rply *int) error { - return ssv1.sS.BiRPCv1GetPassiveSessionsCount(nil, args, rply) + return ssv1.sS.BiRPCv1GetPassiveSessionsCount(ctx, args, rply) } -func (ssv1 *SessionSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (ssv1 *SessionSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } -func (ssv1 *SessionSv1) ReplicateSessions(args *dispatchers.ArgsReplicateSessionsWithAPIOpts, rply *string) error { - return ssv1.sS.BiRPCv1ReplicateSessions(nil, args.ArgsReplicateSessions, rply) +func (ssv1 *SessionSv1) ReplicateSessions(ctx *context.Context, args *dispatchers.ArgsReplicateSessionsWithAPIOpts, rply *string) error { + return ssv1.sS.BiRPCv1ReplicateSessions(ctx, args.ArgsReplicateSessions, rply) } -func (ssv1 *SessionSv1) SetPassiveSession(args *sessions.Session, +func (ssv1 *SessionSv1) SetPassiveSession(ctx *context.Context, args *sessions.Session, reply *string) error { - return ssv1.sS.BiRPCv1SetPassiveSession(nil, args, reply) + return ssv1.sS.BiRPCv1SetPassiveSession(ctx, args, reply) } // ActivateSessions is called to activate a list/all sessions -func (ssv1 *SessionSv1) ActivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error { - return ssv1.sS.BiRPCv1ActivateSessions(nil, args, reply) +func (ssv1 *SessionSv1) ActivateSessions(ctx *context.Context, args *utils.SessionIDsWithArgsDispatcher, reply *string) error { + return ssv1.sS.BiRPCv1ActivateSessions(ctx, args, reply) } // DeactivateSessions is called to deactivate a list/all active sessios -func (ssv1 *SessionSv1) DeactivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error { - return ssv1.sS.BiRPCv1DeactivateSessions(nil, args, reply) -} - -// Call implements rpcclient.ClientConnector interface for internal RPC -func (ssv1 *SessionSv1) Call(serviceMethod string, - args any, reply any) error { - return utils.APIerRPCCall(ssv1, serviceMethod, args, reply) +func (ssv1 *SessionSv1) DeactivateSessions(ctx *context.Context, args *utils.SessionIDsWithArgsDispatcher, reply *string) error { + return ssv1.sS.BiRPCv1DeactivateSessions(ctx, args, reply) } // ReAuthorize sends the RAR for filterd sessions -func (ssv1 *SessionSv1) ReAuthorize(args *utils.SessionFilter, reply *string) error { - return ssv1.sS.BiRPCv1ReAuthorize(nil, args, reply) +func (ssv1 *SessionSv1) ReAuthorize(ctx *context.Context, args *utils.SessionFilter, reply *string) error { + return ssv1.sS.BiRPCv1ReAuthorize(ctx, args, reply) } // DisconnectPeer sends the DPR for the OriginHost and OriginRealm -func (ssv1 *SessionSv1) DisconnectPeer(args *utils.DPRArgs, reply *string) error { - return ssv1.sS.BiRPCv1DisconnectPeer(nil, args, reply) +func (ssv1 *SessionSv1) DisconnectPeer(ctx *context.Context, args *utils.DPRArgs, reply *string) error { + return ssv1.sS.BiRPCv1DisconnectPeer(ctx, args, reply) } // STIRAuthenticate checks the identity using STIR/SHAKEN -func (ssv1 *SessionSv1) STIRAuthenticate(args *sessions.V1STIRAuthenticateArgs, reply *string) error { - return ssv1.sS.BiRPCv1STIRAuthenticate(nil, args, reply) +func (ssv1 *SessionSv1) STIRAuthenticate(ctx *context.Context, args *sessions.V1STIRAuthenticateArgs, reply *string) error { + return ssv1.sS.BiRPCv1STIRAuthenticate(ctx, args, reply) } // STIRIdentity creates the identity for STIR/SHAKEN -func (ssv1 *SessionSv1) STIRIdentity(args *sessions.V1STIRIdentityArgs, reply *string) error { - return ssv1.sS.BiRPCv1STIRIdentity(nil, args, reply) +func (ssv1 *SessionSv1) STIRIdentity(ctx *context.Context, args *sessions.V1STIRIdentityArgs, reply *string) error { + return ssv1.sS.BiRPCv1STIRIdentity(ctx, args, reply) +} + +// Sleep mimics a request whose process takes the given amount of time to process +func (ssv1 *SessionSv1) Sleep(ctx *context.Context, args *utils.DurationArgs, reply *string) (err error) { + return ssv1.sS.BiRPCv1Sleep(ctx, args, reply) +} + +func (ssv1 *SessionSv1) CapsError(ctx *context.Context, args any, reply *string) (err error) { + return ssv1.sS.BiRPCv1CapsError(ctx, args, reply) +} + +func (ssv1 *SessionSv1) RegisterInternalBiJSONConn(ctx *context.Context, args string, rply *string) (err error) { + return ssv1.sS.BiRPCv1RegisterInternalBiJSONConn(ctx, args, rply) } diff --git a/apier/v1/sessions_process_event_it_test.go b/apier/v1/sessions_process_event_it_test.go index 4101d8909..4a354469f 100644 --- a/apier/v1/sessions_process_event_it_test.go +++ b/apier/v1/sessions_process_event_it_test.go @@ -27,6 +27,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -181,7 +182,7 @@ func testSSv1ItProcessEventAuth(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, args, &rply); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Fatal(err) } expMaxUsage := map[string]time.Duration{ @@ -286,7 +287,7 @@ func testSSv1ItProcessEventInitiateSession(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Error(err) } @@ -338,7 +339,7 @@ func testSSv1ItProcessEventInitiateSession(t *testing.T) { utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes[utils.MetaRaw])) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) @@ -369,7 +370,7 @@ func testSSv1ItProcessEventUpdateSession(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Error(err) } @@ -416,7 +417,7 @@ func testSSv1ItProcessEventUpdateSession(t *testing.T) { t.Errorf("Expected %s received %s", expMaxUsage, rply.MaxUsage) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) @@ -445,12 +446,12 @@ func testSSv1ItProcessEventTerminateSession(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Error(err) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err == nil || + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -474,7 +475,7 @@ func testSSv1ItProcessCDRForSessionFromProcessEvent(t *testing.T) { }, } var rply string - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessCDR, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessCDR, args, &rply); err != nil { t.Error(err) } @@ -486,7 +487,7 @@ func testSSv1ItProcessCDRForSessionFromProcessEvent(t *testing.T) { func testSSv1ItGetCDRs(t *testing.T) { var cdrCnt int64 req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 3 { // 3 for each CDR t.Error("Unexpected number of CDRs returned: ", cdrCnt) @@ -494,7 +495,7 @@ func testSSv1ItGetCDRs(t *testing.T) { var cdrs []*engine.CDR args := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"raw"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -505,7 +506,7 @@ func testSSv1ItGetCDRs(t *testing.T) { } args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"testSSv1ItProcessEvent"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -516,7 +517,7 @@ func testSSv1ItGetCDRs(t *testing.T) { } args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}, OriginIDs: []string{"testSSv1ItProcessEvent"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -548,7 +549,7 @@ func testSSv1ItProcessEventWithGetCost(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Error(err) } @@ -587,7 +588,7 @@ func testSSv1ItProcessEventWithGetCost2(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Error(err) } @@ -628,7 +629,7 @@ func testSSv1ItProcessEventWithGetCost3(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Error(err) } @@ -666,7 +667,7 @@ func testSSv1ItProcessEventWithGetCost4(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err == nil || err.Error() != utils.ErrRatingPlanNotFound.Error() { t.Error(err) } @@ -694,7 +695,7 @@ func testSSv1ItGetCost(t *testing.T) { }, } var rply sessions.V1GetCostReply - if err := sSv1BiRpc.Call(utils.SessionSv1GetCost, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetCost, args, &rply); err != nil { t.Error(err) } @@ -735,7 +736,7 @@ func testSSv1ItProcessEventWithCDR(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Error(err) } @@ -745,7 +746,7 @@ func testSSv1ItGetCDRsFromProcessEvent(t *testing.T) { var cdrCnt int64 req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{ OriginIDs: []string{"testSSv1ItProcessEventWithCDR"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 3 { // 3 for each CDR t.Error("Unexpected number of CDRs returned: ", cdrCnt) @@ -755,7 +756,7 @@ func testSSv1ItGetCDRsFromProcessEvent(t *testing.T) { args := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{ OriginIDs: []string{"testSSv1ItProcessEventWithCDR"}, RunIDs: []string{"raw"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -767,7 +768,7 @@ func testSSv1ItGetCDRsFromProcessEvent(t *testing.T) { args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{ RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"testSSv1ItProcessEventWithCDR"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -779,7 +780,7 @@ func testSSv1ItGetCDRsFromProcessEvent(t *testing.T) { args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{ RunIDs: []string{"SupplierCharges"}, OriginIDs: []string{"testSSv1ItProcessEventWithCDR"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -812,7 +813,7 @@ func testSSv1ItProcessEventWithCDRResourceError(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err == nil || err.Error() != utils.ErrPartiallyExecuted.Error() { t.Error(err) } @@ -822,7 +823,7 @@ func testSSv1ItGetCDRsFromProcessEventResourceError(t *testing.T) { var cdrCnt int64 req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{ OriginIDs: []string{"testSSv1ItProcessEventWithCDRResourceError"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 3 { // 3 for each CDR t.Error("Unexpected number of CDRs returned: ", cdrCnt) @@ -832,7 +833,7 @@ func testSSv1ItGetCDRsFromProcessEventResourceError(t *testing.T) { args := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{ OriginIDs: []string{"testSSv1ItProcessEventWithCDRResourceError"}, RunIDs: []string{"raw"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -844,7 +845,7 @@ func testSSv1ItGetCDRsFromProcessEventResourceError(t *testing.T) { args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{ RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"testSSv1ItProcessEventWithCDRResourceError"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -856,7 +857,7 @@ func testSSv1ItGetCDRsFromProcessEventResourceError(t *testing.T) { args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{ RunIDs: []string{"SupplierCharges"}, OriginIDs: []string{"testSSv1ItProcessEventWithCDRResourceError"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -890,7 +891,7 @@ func testSSv1ItProcessEventWithCDRResourceErrorBlockError(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err == nil || err.Error() != "RESOURCES_ERROR:cannot find usage record with id: testSSv1ItProcessEventWithCDRResourceErrorBlockError" { t.Error(err) } @@ -900,7 +901,7 @@ func testSSv1ItGetCDRsFromProcessEventResourceErrorBlockError(t *testing.T) { var cdrCnt int64 req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{ OriginIDs: []string{"testSSv1ItProcessEventWithCDRResourceErrorBlockError"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 0 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) diff --git a/apier/v1/sessions_thresholds_it_test.go b/apier/v1/sessions_thresholds_it_test.go index a5dcfcf40..64506bda6 100644 --- a/apier/v1/sessions_thresholds_it_test.go +++ b/apier/v1/sessions_thresholds_it_test.go @@ -22,13 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "testing" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -38,8 +38,8 @@ import ( var ( sSv1CfgPath2 string sSv1Cfg2 *config.CGRConfig - sSv1BiRpc2 *rpc2.Client - sSApierRpc2 *rpc.Client + sSv1BiRpc2 *birpc.BirpcClient + sSApierRpc2 *birpc.Client disconnectEvChan2 = make(chan *utils.AttrDisconnectSession) sessionsConfDIR string @@ -83,7 +83,9 @@ func TestSessionSITtests(t *testing.T) { } } -func handleDisconnectSession2(clnt *rpc2.Client, +type smock2 struct{} + +func (*smock2) DisconnectSession(ctx *context.Context, args *utils.AttrDisconnectSession, reply *string) error { disconnectEvChan2 <- args *reply = utils.OK @@ -124,11 +126,12 @@ func testSessionSv1ItRpcConn(t *testing.T) { if err != nil { t.Fatal(err) } - clntHandlers := map[string]any{ - utils.SessionSv1DisconnectSession: handleDisconnectSession2, + srv, err := birpc.NewService(new(smock2), utils.SessionSv1, true) + if err != nil { + t.Fatal(err) } if sSv1BiRpc2, err = utils.NewBiJSONrpcClient(sSv1Cfg2.SessionSCfg().ListenBijson, - clntHandlers); err != nil { + srv); err != nil { t.Fatal(err) } if sSApierRpc2, err = newRPCClient(sSv1Cfg2.ListenCfg()); err != nil { @@ -142,7 +145,7 @@ func testSessionSv1ItTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{ FolderPath: path.Join(*dataDir, "tariffplans", "testit")} var loadInst utils.LoadInstance - if err := sSApierRpc2.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := sSApierRpc2.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -164,7 +167,7 @@ func testSessionSv1ItGetThreshold(t *testing.T) { Async: false, } var reply *engine.ThresholdProfile - if err := sSApierRpc2.Call(utils.APIerSv1GetThresholdProfile, + if err := sSApierRpc2.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &reply); err != nil { t.Error(err) @@ -187,7 +190,7 @@ func testSessionSv1ItGetThreshold(t *testing.T) { // Uuid will be generated // so we will compare ID from Account and Value from BalanceMap var reply2 *engine.Account - if err := sSApierRpc2.Call(utils.APIerSv2GetAccount, + if err := sSApierRpc2.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &reply2); err != nil { t.Error(err) @@ -221,7 +224,7 @@ func testSessionSv1ItAuth(t *testing.T) { }, } var rply sessions.V1AuthorizeReply - if err := sSv1BiRpc2.Call(utils.SessionSv1AuthorizeEvent, + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Error(err) } @@ -246,7 +249,7 @@ func testSessionSv1ItAuth(t *testing.T) { // Uuid will be generated // so we will compare ID from Account and Value from BalanceMap var reply *engine.Account - if err := sSApierRpc2.Call(utils.APIerSv2GetAccount, + if err := sSApierRpc2.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &reply); err != nil { t.Error(err) @@ -288,7 +291,7 @@ func testSessionSv1ItInitiateSession(t *testing.T) { }, } var rply sessions.V1InitSessionReply - if err := sSv1BiRpc2.Call(utils.SessionSv1InitiateSession, + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err != nil { t.Error(err) } @@ -309,7 +312,7 @@ func testSessionSv1ItInitiateSession(t *testing.T) { // Uuid will be generated // so we will compare ID from Account and Value from BalanceMap var reply *engine.Account - if err := sSApierRpc2.Call(utils.APIerSv2GetAccount, + if err := sSApierRpc2.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &reply); err != nil { t.Error(err) @@ -345,7 +348,7 @@ func testSessionSv1ItTerminateSession(t *testing.T) { }, } var rply string - if err := sSv1BiRpc2.Call(utils.SessionSv1TerminateSession, + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } @@ -366,7 +369,7 @@ func testSessionSv1ItTerminateSession(t *testing.T) { // Uuid will be generated // so we will compare ID from Account and Value from BalanceMap var reply2 *engine.Account - if err := sSApierRpc2.Call(utils.APIerSv2GetAccount, + if err := sSApierRpc2.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &reply2); err != nil { t.Error(err) @@ -401,7 +404,7 @@ func testSessionSv1ItAuthNotFoundThreshold(t *testing.T) { }, } var rply sessions.V1AuthorizeReply - if err := sSv1BiRpc2.Call(utils.SessionSv1AuthorizeEvent, + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Error(err) } @@ -441,7 +444,7 @@ func testSessionSv1ItInitNotFoundThreshold(t *testing.T) { }, } var rply sessions.V1InitSessionReply - if err := sSv1BiRpc2.Call(utils.SessionSv1InitiateSession, + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err != nil { t.Error(err) } @@ -458,7 +461,7 @@ func testSessionSv1ItInitNotFoundThreshold(t *testing.T) { } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc2.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) @@ -492,7 +495,7 @@ func testSessionSv1ItTerminateNotFoundThreshold(t *testing.T) { }, } var rply string - if err := sSv1BiRpc2.Call(utils.SessionSv1TerminateSession, + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Fatal(err) } @@ -500,7 +503,7 @@ func testSessionSv1ItTerminateNotFoundThreshold(t *testing.T) { t.Fatalf("Unexpected reply: %s", rply) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc2.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -508,7 +511,7 @@ func testSessionSv1ItTerminateNotFoundThreshold(t *testing.T) { func testSessionSv1ItAuthNotFoundThresholdAndStats(t *testing.T) { var resp string - if err := sSApierRpc2.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := sSApierRpc2.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_2"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -533,7 +536,7 @@ func testSessionSv1ItAuthNotFoundThresholdAndStats(t *testing.T) { }, } var rply sessions.V1AuthorizeReply - if err := sSv1BiRpc2.Call(utils.SessionSv1AuthorizeEvent, + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Error(err) } @@ -574,7 +577,7 @@ func testSessionSv1ItInitNotFoundThresholdAndStats(t *testing.T) { }, } var rply sessions.V1InitSessionReply - if err := sSv1BiRpc2.Call(utils.SessionSv1InitiateSession, + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err != nil { t.Error(err) } @@ -592,7 +595,7 @@ func testSessionSv1ItInitNotFoundThresholdAndStats(t *testing.T) { } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc2.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) @@ -626,7 +629,7 @@ func testSessionSv1ItTerminateNotFoundThresholdAndStats(t *testing.T) { }, } var rply string - if err := sSv1BiRpc2.Call(utils.SessionSv1TerminateSession, + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } @@ -634,7 +637,7 @@ func testSessionSv1ItTerminateNotFoundThresholdAndStats(t *testing.T) { t.Errorf("Unexpected reply: %s", rply) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc2.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || + if err := sSv1BiRpc2.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/apier/v1/sessionsbirpc.go b/apier/v1/sessionsbirpc.go deleted file mode 100644 index fbe7505c0..000000000 --- a/apier/v1/sessionsbirpc.go +++ /dev/null @@ -1,213 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package v1 - -import ( - "time" - - "github.com/cenkalti/rpc2" - "github.com/cgrates/cgrates/sessions" - "github.com/cgrates/cgrates/utils" -) - -// Bidirectional JSON methods following -func (ssv1 *SessionSv1) Handlers() map[string]any { - return map[string]any{ - utils.SessionSv1GetActiveSessions: ssv1.BiRPCv1GetActiveSessions, - utils.SessionSv1GetActiveSessionsCount: ssv1.BiRPCv1GetActiveSessionsCount, - utils.SessionSv1GetPassiveSessions: ssv1.BiRPCv1GetPassiveSessions, - utils.SessionSv1GetPassiveSessionsCount: ssv1.BiRPCv1GetPassiveSessionsCount, - - utils.SessionSv1AuthorizeEvent: ssv1.BiRPCv1AuthorizeEvent, - utils.SessionSv1AuthorizeEventWithDigest: ssv1.BiRPCv1AuthorizeEventWithDigest, - utils.SessionSv1InitiateSession: ssv1.BiRPCv1InitiateSession, - utils.SessionSv1InitiateSessionWithDigest: ssv1.BiRPCv1InitiateSessionWithDigest, - utils.SessionSv1UpdateSession: ssv1.BiRPCv1UpdateSession, - utils.SessionSv1SyncSessions: ssv1.BiRPCv1SyncSessions, - utils.SessionSv1TerminateSession: ssv1.BiRPCv1TerminateSession, - utils.SessionSv1ProcessCDR: ssv1.BiRPCv1ProcessCDR, - utils.SessionSv1ProcessMessage: ssv1.BiRPCv1ProcessMessage, - utils.SessionSv1ProcessEvent: ssv1.BiRPCv1ProcessEvent, - utils.SessionSv1GetCost: ssv1.BiRPCv1GetCost, - - utils.SessionSv1ForceDisconnect: ssv1.BiRPCv1ForceDisconnect, - utils.SessionSv1RegisterInternalBiJSONConn: ssv1.BiRPCv1RegisterInternalBiJSONConn, - utils.SessionSv1Ping: ssv1.BiRPCPing, - - utils.SessionSv1ReplicateSessions: ssv1.BiRPCv1ReplicateSessions, - utils.SessionSv1SetPassiveSession: ssv1.BiRPCv1SetPassiveSession, - utils.SessionSv1ActivateSessions: ssv1.BiRPCv1ActivateSessions, - utils.SessionSv1DeactivateSessions: ssv1.BiRPCv1DeactivateSessions, - - utils.SessionSv1ReAuthorize: ssv1.BiRPCV1ReAuthorize, - utils.SessionSv1DisconnectPeer: ssv1.BiRPCV1DisconnectPeer, - - utils.SessionSv1STIRAuthenticate: ssv1.BiRPCV1STIRAuthenticate, - utils.SessionSv1STIRIdentity: ssv1.BiRPCV1STIRIdentity, - - utils.SessionSv1Sleep: ssv1.BiRPCV1Sleep, // Sleep method is used to test the concurrent requests mechanism - utils.SessionSv1CapsError: ssv1.BiRPCV1CapsError, - } -} - -func (ssv1 *SessionSv1) BiRPCv1AuthorizeEvent(clnt *rpc2.Client, args *sessions.V1AuthorizeArgs, - rply *sessions.V1AuthorizeReply) (err error) { - return ssv1.sS.BiRPCv1AuthorizeEvent(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1AuthorizeEventWithDigest(clnt *rpc2.Client, args *sessions.V1AuthorizeArgs, - rply *sessions.V1AuthorizeReplyWithDigest) (err error) { - return ssv1.sS.BiRPCv1AuthorizeEventWithDigest(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1InitiateSession(clnt *rpc2.Client, args *sessions.V1InitSessionArgs, - rply *sessions.V1InitSessionReply) (err error) { - return ssv1.sS.BiRPCv1InitiateSession(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1InitiateSessionWithDigest(clnt *rpc2.Client, args *sessions.V1InitSessionArgs, - rply *sessions.V1InitReplyWithDigest) (err error) { - return ssv1.sS.BiRPCv1InitiateSessionWithDigest(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1UpdateSession(clnt *rpc2.Client, args *sessions.V1UpdateSessionArgs, - rply *sessions.V1UpdateSessionReply) (err error) { - return ssv1.sS.BiRPCv1UpdateSession(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1SyncSessions(clnt *rpc2.Client, args *utils.TenantWithAPIOpts, - rply *string) (err error) { - return ssv1.sS.BiRPCv1SyncSessions(clnt, &utils.TenantWithAPIOpts{}, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1TerminateSession(clnt *rpc2.Client, args *sessions.V1TerminateSessionArgs, - rply *string) (err error) { - return ssv1.sS.BiRPCv1TerminateSession(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1ProcessCDR(clnt *rpc2.Client, cgrEv *utils.CGREvent, - rply *string) (err error) { - return ssv1.sS.BiRPCv1ProcessCDR(clnt, cgrEv, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1ProcessMessage(clnt *rpc2.Client, args *sessions.V1ProcessMessageArgs, - rply *sessions.V1ProcessMessageReply) (err error) { - return ssv1.sS.BiRPCv1ProcessMessage(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1ProcessEvent(clnt *rpc2.Client, args *sessions.V1ProcessEventArgs, - rply *sessions.V1ProcessEventReply) (err error) { - return ssv1.sS.BiRPCv1ProcessEvent(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1GetCost(clnt *rpc2.Client, args *sessions.V1ProcessEventArgs, - rply *sessions.V1GetCostReply) (err error) { - return ssv1.sS.BiRPCv1GetCost(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1GetActiveSessions(clnt *rpc2.Client, args *utils.SessionFilter, - rply *[]*sessions.ExternalSession) (err error) { - return ssv1.sS.BiRPCv1GetActiveSessions(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1GetActiveSessionsCount(clnt *rpc2.Client, args *utils.SessionFilter, - rply *int) (err error) { - return ssv1.sS.BiRPCv1GetActiveSessionsCount(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1GetPassiveSessions(clnt *rpc2.Client, args *utils.SessionFilter, - rply *[]*sessions.ExternalSession) (err error) { - return ssv1.sS.BiRPCv1GetPassiveSessions(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1GetPassiveSessionsCount(clnt *rpc2.Client, args *utils.SessionFilter, - rply *int) (err error) { - return ssv1.sS.BiRPCv1GetPassiveSessionsCount(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1ForceDisconnect(clnt *rpc2.Client, args *utils.SessionFilter, - rply *string) (err error) { - return ssv1.sS.BiRPCv1ForceDisconnect(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCv1RegisterInternalBiJSONConn(clnt *rpc2.Client, args string, - rply *string) (err error) { - return ssv1.sS.BiRPCv1RegisterInternalBiJSONConn(clnt, args, rply) -} - -func (ssv1 *SessionSv1) BiRPCPing(clnt *rpc2.Client, ign *utils.CGREvent, - reply *string) (err error) { - return ssv1.Ping(ign, reply) -} - -func (ssv1 *SessionSv1) BiRPCv1ReplicateSessions(clnt *rpc2.Client, - args sessions.ArgsReplicateSessions, reply *string) (err error) { - return ssv1.BiRPCv1ReplicateSessions(clnt, args, reply) -} - -func (ssv1 *SessionSv1) BiRPCv1SetPassiveSession(clnt *rpc2.Client, - args *sessions.Session, reply *string) (err error) { - return ssv1.sS.BiRPCv1SetPassiveSession(clnt, args, reply) -} - -func (ssv1 *SessionSv1) BiRPCv1ActivateSessions(clnt *rpc2.Client, - args *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) { - return ssv1.sS.BiRPCv1ActivateSessions(clnt, args, reply) -} - -func (ssv1 *SessionSv1) BiRPCv1DeactivateSessions(clnt *rpc2.Client, - args *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) { - return ssv1.sS.BiRPCv1DeactivateSessions(clnt, args, reply) -} - -// BiRPCV1ReAuthorize sends the RAR for filterd sessions -func (ssv1 *SessionSv1) BiRPCV1ReAuthorize(clnt *rpc2.Client, - args *utils.SessionFilter, reply *string) (err error) { - return ssv1.sS.BiRPCv1ReAuthorize(clnt, args, reply) -} - -// BiRPCV1DisconnectPeer sends the DPR for the OriginHost and OriginRealm -func (ssv1 *SessionSv1) BiRPCV1DisconnectPeer(clnt *rpc2.Client, - args *utils.DPRArgs, reply *string) (err error) { - return ssv1.sS.BiRPCv1DisconnectPeer(clnt, args, reply) -} - -// BiRPCV1STIRAuthenticate checks the identity using STIR/SHAKEN -func (ssv1 *SessionSv1) BiRPCV1STIRAuthenticate(clnt *rpc2.Client, - args *sessions.V1STIRAuthenticateArgs, reply *string) (err error) { - return ssv1.sS.BiRPCv1STIRAuthenticate(clnt, args, reply) -} - -// BiRPCV1STIRIdentity creates the identity for STIR/SHAKEN -func (ssv1 *SessionSv1) BiRPCV1STIRIdentity(clnt *rpc2.Client, - args *sessions.V1STIRIdentityArgs, reply *string) (err error) { - return ssv1.sS.BiRPCv1STIRIdentity(nil, args, reply) -} - -func (ssv1 *SessionSv1) BiRPCV1Sleep(clnt *rpc2.Client, args *utils.DurationArgs, - reply *string) (err error) { - time.Sleep(args.Duration) - *reply = utils.OK - return nil -} - -func (ssv1 *SessionSv1) BiRPCV1CapsError(clnt *rpc2.Client, args any, - reply *string) (err error) { - return ssv1.sS.BiRPCv1CapsError(clnt, args, reply) -} diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go index a15faa395..e959702c3 100644 --- a/apier/v1/sessionsv1_it_test.go +++ b/apier/v1/sessionsv1_it_test.go @@ -22,13 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "testing" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -38,8 +38,8 @@ import ( var ( sSv1CfgPath string sSv1Cfg *config.CGRConfig - sSv1BiRpc *rpc2.Client - sSApierRpc *rpc.Client + sSv1BiRpc *birpc.BirpcClient + sSApierRpc *birpc.Client discEvChan = make(chan *utils.AttrDisconnectSession, 1) sSV1RequestType string @@ -87,7 +87,9 @@ func testSSv1ItInitCfgDir(t *testing.T) { } } -func handleDisconnectSession(clnt *rpc2.Client, +type smock struct{} + +func (*smock) DisconnectSession(ctx *context.Context, args *utils.AttrDisconnectSession, reply *string) error { discEvChan <- args // free the channel @@ -96,7 +98,7 @@ func handleDisconnectSession(clnt *rpc2.Client, return nil } -func handleGetSessionIDs(clnt *rpc2.Client, +func (*smock) GetActiveSessionIDs(ctx *context.Context, ignParam string, sessionIDs *[]*sessions.SessionID) error { return nil } @@ -165,12 +167,12 @@ func testSSv1ItRpcConn(t *testing.T) { if err != nil { t.Fatal(err) } - clntHandlers := map[string]any{ - utils.SessionSv1DisconnectSession: handleDisconnectSession, - utils.SessionSv1GetActiveSessionIDs: handleGetSessionIDs, + srv, err := birpc.NewService(new(smock), utils.SessionSv1, true) + if err != nil { + t.Fatal(err) } if sSv1BiRpc, err = utils.NewBiJSONrpcClient(sSv1Cfg.SessionSCfg().ListenBijson, - clntHandlers); err != nil { + srv); err != nil { t.Fatal(err) } if sSApierRpc, err = newRPCClient(sSv1Cfg.ListenCfg()); err != nil { @@ -181,7 +183,7 @@ func testSSv1ItRpcConn(t *testing.T) { func testSSv1ItPing(t *testing.T) { var resp string - if err := sSv1BiRpc.Call(utils.SessionSv1Ping, new(utils.CGREvent), &resp); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1Ping, new(utils.CGREvent), &resp); err != nil { t.Error(err) } else if resp != utils.Pong { t.Error("Unexpected reply returned", resp) @@ -193,7 +195,7 @@ func testSSv1ItTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{ FolderPath: path.Join(*dataDir, "tariffplans", "testit")} var loadInst utils.LoadInstance - if err := sSApierRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := sSApierRpc.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } @@ -224,7 +226,7 @@ func testSSv1ItAuth(t *testing.T) { }, } var rply sessions.V1AuthorizeReply - if err := sSv1BiRpc.Call(utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Fatal(err) } if rply.MaxUsage == nil || *rply.MaxUsage != authUsage { @@ -321,7 +323,7 @@ func testSSv1ItAuthWithDigest(t *testing.T) { }, } var rply sessions.V1AuthorizeReplyWithDigest - if err := sSv1BiRpc.Call(utils.SessionSv1AuthorizeEventWithDigest, args, &rply); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1AuthorizeEventWithDigest, args, &rply); err != nil { t.Fatal(err) } // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min @@ -366,7 +368,7 @@ func testSSv1ItInitiateSession(t *testing.T) { }, } var rply sessions.V1InitSessionReply - if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSession, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err != nil { t.Fatal(err) } @@ -412,7 +414,7 @@ func testSSv1ItInitiateSession(t *testing.T) { utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes)) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) @@ -443,7 +445,7 @@ func testSSv1ItInitiateSessionWithDigest(t *testing.T) { }, } var rply sessions.V1InitReplyWithDigest - if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSessionWithDigest, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1InitiateSessionWithDigest, args, &rply); err != nil { t.Fatal(err) } @@ -462,7 +464,7 @@ func testSSv1ItInitiateSessionWithDigest(t *testing.T) { utils.ToJSON(eAttrs), utils.ToJSON(rply.AttributesDigest)) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) @@ -492,7 +494,7 @@ func testSSv1ItUpdateSession(t *testing.T) { }, } var rply sessions.V1UpdateSessionReply - if err := sSv1BiRpc.Call(utils.SessionSv1UpdateSession, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1UpdateSession, args, &rply); err != nil { t.Error(err) } @@ -533,7 +535,7 @@ func testSSv1ItUpdateSession(t *testing.T) { t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) @@ -562,7 +564,7 @@ func testSSv1ItTerminateSession(t *testing.T) { }, } var rply string - if err := sSv1BiRpc.Call(utils.SessionSv1TerminateSession, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } @@ -570,7 +572,7 @@ func testSSv1ItTerminateSession(t *testing.T) { t.Errorf("Unexpected reply: %s", rply) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error %s received error %v and reply %s", utils.ErrNotFound, err, utils.ToJSON(aSessions)) } @@ -594,7 +596,7 @@ func testSSv1ItProcessCDR(t *testing.T) { }, } var rply string - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessCDR, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessCDR, args, &rply); err != nil { t.Error(err) } @@ -629,7 +631,7 @@ func testSSv1ItProcessEvent(t *testing.T) { }, } var rply sessions.V1ProcessMessageReply - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessMessage, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -676,12 +678,12 @@ func testSSv1ItProcessEvent(t *testing.T) { utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes)) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } var rplyCDR string - if err := sSv1BiRpc.Call(utils.SessionSv1ProcessCDR, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ProcessCDR, args.CGREvent, &rplyCDR); err != nil { t.Error(err) } @@ -693,7 +695,7 @@ func testSSv1ItProcessEvent(t *testing.T) { func testSSv1ItCDRsGetCdrs(t *testing.T) { var cdrCnt int64 req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 6 { // 3 for each CDR t.Error("Unexpected number of CDRs returned: ", cdrCnt) @@ -701,7 +703,7 @@ func testSSv1ItCDRsGetCdrs(t *testing.T) { var cdrs []*engine.CDR args := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"raw"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 2 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -712,7 +714,7 @@ func testSSv1ItCDRsGetCdrs(t *testing.T) { } args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"TestSSv1It1"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -729,7 +731,7 @@ func testSSv1ItCDRsGetCdrs(t *testing.T) { } args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}, OriginIDs: []string{"TestSSv1It1"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -747,7 +749,7 @@ func testSSv1ItCDRsGetCdrs(t *testing.T) { args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"TestSSv1It2"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -764,7 +766,7 @@ func testSSv1ItCDRsGetCdrs(t *testing.T) { } args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}, OriginIDs: []string{"TestSSv1It2"}}} - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -787,13 +789,13 @@ func testSSv1ItForceUpdateSession(t *testing.T) { return } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error: %v with len(asessions)=%v", err, len(aSessions)) } var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 9.55 - if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -822,7 +824,7 @@ func testSSv1ItForceUpdateSession(t *testing.T) { }, } var rply sessions.V1UpdateSessionReply - if err := sSv1BiRpc.Call(utils.SessionSv1UpdateSession, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1UpdateSession, args, &rply); err != nil { t.Fatal(err) } @@ -861,31 +863,31 @@ func testSSv1ItForceUpdateSession(t *testing.T) { t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) } aSessions = make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active ssesions: %s", utils.ToJSON(aSessions)) } eAcntVal = 9.4 - if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) } rplyt := "" - if err := sSv1BiRpc.Call(utils.SessionSv1ForceDisconnect, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ForceDisconnect, map[string]string{utils.OriginID: "TestSSv1It"}, &rplyt); err != nil { t.Error(err) } else if rplyt != utils.OK { t.Errorf("Unexpected reply: %s", rplyt) } aSessions = make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { // no monetary change bacause the sessin was terminated t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -897,7 +899,7 @@ func testSSv1ItForceUpdateSession(t *testing.T) { OriginIDs: []string{"TestSSv1It"}, }, } - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs), "\n", utils.ToJSON(cdrs)) @@ -912,7 +914,7 @@ func testSSv1ItForceUpdateSession(t *testing.T) { OriginIDs: []string{"TestSSv1It"}, }, } - if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -939,7 +941,7 @@ func testSSv1ItDynamicDebit(t *testing.T) { }, } var reply string - if err := sSApierRpc.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -950,7 +952,7 @@ func testSSv1ItDynamicDebit(t *testing.T) { Account: attrSetBalance.Account, } eAcntVal := 2 * float64(time.Second) - if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %v, received: %v", @@ -982,7 +984,7 @@ func testSSv1ItDynamicDebit(t *testing.T) { }, } var rply1 sessions.V1InitSessionReply - if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSession, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1InitiateSession, args1, &rply1); err != nil { t.Error(err) return @@ -991,14 +993,14 @@ func testSSv1ItDynamicDebit(t *testing.T) { } aSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %+v , %s ", len(aSessions), utils.ToJSON(aSessions)) } time.Sleep(time.Millisecond) eAcntVal -= float64(time.Millisecond) * 30 * 2 // 2 session - if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %v, received: %v", @@ -1006,7 +1008,7 @@ func testSSv1ItDynamicDebit(t *testing.T) { } time.Sleep(10 * time.Millisecond) - if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %v, received: %v", @@ -1014,21 +1016,21 @@ func testSSv1ItDynamicDebit(t *testing.T) { } time.Sleep(20 * time.Millisecond) eAcntVal -= float64(time.Millisecond) * 30 * 2 // 2 session - if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sSApierRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %v, received: %v", time.Duration(eAcntVal), time.Duration(acnt.BalanceMap[utils.MetaVoice].GetTotalValue())) } - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %+v , %s ", len(aSessions), utils.ToJSON(aSessions)) } var rplyt string - if err := sSv1BiRpc.Call(utils.SessionSv1ForceDisconnect, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1ForceDisconnect, nil, &rplyt); err != nil { t.Error(err) } else if rplyt != utils.OK { @@ -1038,7 +1040,7 @@ func testSSv1ItDynamicDebit(t *testing.T) { time.Sleep(50 * time.Millisecond) aSessions = make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -1047,10 +1049,10 @@ func testSSv1ItDynamicDebit(t *testing.T) { func testSSv1ItDeactivateSessions(t *testing.T) { aSessions := make([]*sessions.ExternalSession, 0) pSessions := make([]*sessions.ExternalSession, 0) - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil && err.Error() != utils.NotFoundCaps { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil && err.Error() != utils.NotFoundCaps { t.Error(err) } - if err := sSv1BiRpc.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil && err.Error() != utils.NotFoundCaps { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil && err.Error() != utils.NotFoundCaps { t.Error(err) } initUsage := 5 * time.Minute @@ -1075,28 +1077,28 @@ func testSSv1ItDeactivateSessions(t *testing.T) { }, } var rply sessions.V1InitSessionReply - if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSession, args, &rply); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err != nil { t.Fatal(err) } - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) } - if err := sSv1BiRpc.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil && err.Error() != utils.NotFoundCaps { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil && err.Error() != utils.NotFoundCaps { t.Error(err) } var reply string - err := sSv1BiRpc.Call(utils.SessionSv1DeactivateSessions, &utils.SessionIDsWithArgsDispatcher{}, &reply) + err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1DeactivateSessions, &utils.SessionIDsWithArgsDispatcher{}, &reply) if err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting: OK, received : %+v", reply) } - if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil && err.Error() != utils.NotFoundCaps { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil && err.Error() != utils.NotFoundCaps { t.Error(err) } - if err := sSv1BiRpc.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil { + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil { t.Error(err) } else if len(pSessions) != 3 { t.Errorf("Expecting: 2, received: %+v", len(pSessions)) @@ -1124,7 +1126,7 @@ func testSSv1ItAuthNotFoundCharger(t *testing.T) { }, } var rply sessions.V1AuthorizeReply - if err := sSv1BiRpc.Call(utils.SessionSv1AuthorizeEvent, args, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err == nil || err.Error() != utils.NewErrChargerS(utils.ErrNotFound).Error() { t.Errorf("Expecting: %+v, received: %+v", utils.NewErrChargerS(utils.ErrNotFound), err) } @@ -1152,7 +1154,7 @@ func testSSv1ItInitiateSessionNotFoundCharger(t *testing.T) { }, } var rply sessions.V1InitSessionReply - if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSession, + if err := sSv1BiRpc.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err == nil || err.Error() != utils.NewErrChargerS(utils.ErrNotFound).Error() { t.Errorf("Expecting: %+v, received: %+v", utils.NewErrChargerS(utils.ErrNotFound), err) } diff --git a/apier/v1/smg.go b/apier/v1/smg.go index 5c8e277af..9e4a74851 100644 --- a/apier/v1/smg.go +++ b/apier/v1/smg.go @@ -19,6 +19,7 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/sessions" ) @@ -35,31 +36,31 @@ type SMGenericV1 struct { } // Returns MaxUsage (for calls in seconds), -1 for no limit -func (smgv1 *SMGenericV1) GetMaxUsage(ev map[string]any, +func (smgv1 *SMGenericV1) GetMaxUsage(ctx *context.Context, ev map[string]any, maxUsage *float64) error { - return smgv1.Ss.BiRPCV1GetMaxUsage(nil, ev, maxUsage) + return smgv1.Ss.BiRPCV1GetMaxUsage(ctx, ev, maxUsage) } // Called on session start, returns the maximum number of seconds the session can last -func (smgv1 *SMGenericV1) InitiateSession(ev map[string]any, +func (smgv1 *SMGenericV1) InitiateSession(ctx *context.Context, ev map[string]any, maxUsage *float64) error { - return smgv1.Ss.BiRPCV1InitiateSession(nil, ev, maxUsage) + return smgv1.Ss.BiRPCV1InitiateSession(ctx, ev, maxUsage) } // Interim updates, returns remaining duration from the rater -func (smgv1 *SMGenericV1) UpdateSession(ev map[string]any, +func (smgv1 *SMGenericV1) UpdateSession(ctx *context.Context, ev map[string]any, maxUsage *float64) error { - return smgv1.Ss.BiRPCV1UpdateSession(nil, ev, maxUsage) + return smgv1.Ss.BiRPCV1UpdateSession(ctx, ev, maxUsage) } // Called on session end, should stop debit loop -func (smgv1 *SMGenericV1) TerminateSession(ev map[string]any, +func (smgv1 *SMGenericV1) TerminateSession(ctx *context.Context, ev map[string]any, reply *string) error { - return smgv1.Ss.BiRPCV1TerminateSession(nil, ev, reply) + return smgv1.Ss.BiRPCV1TerminateSession(ctx, ev, reply) } // Called on session end, should send the CDR to CDRS -func (smgv1 *SMGenericV1) ProcessCDR(ev map[string]any, +func (smgv1 *SMGenericV1) ProcessCDR(ctx *context.Context, ev map[string]any, reply *string) error { - return smgv1.Ss.BiRPCV1ProcessCDR(nil, ev, reply) + return smgv1.Ss.BiRPCV1ProcessCDR(ctx, ev, reply) } diff --git a/apier/v1/smgbirpc.go b/apier/v1/smgbirpc.go deleted file mode 100644 index 282b5c9e9..000000000 --- a/apier/v1/smgbirpc.go +++ /dev/null @@ -1,72 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package v1 - -import ( - "github.com/cenkalti/rpc2" - "github.com/cgrates/cgrates/utils" -) - -// Publishes methods exported by SMGenericV1 as SMGenericV1 (so we can handle standard RPC methods via birpc socket) -func (smgv1 *SMGenericV1) Handlers() map[string]any { - return map[string]any{ - "SMGenericV1.GetMaxUsage": smgv1.BiRPCV1GetMaxUsage, - "SMGenericV1.InitiateSession": smgv1.BiRPCV1InitiateSession, - "SMGenericV1.UpdateSession": smgv1.BiRPCV1UpdateSession, - "SMGenericV1.TerminateSession": smgv1.BiRPCV1TerminateSession, - "SMGenericV1.ProcessCDR": smgv1.BiRPCV1ProcessCDR, - "SMGenericV1.Sleep": smgv1.BiRPCV1CapsError, - } -} - -// / Returns MaxUsage (for calls in seconds), -1 for no limit -func (smgv1 *SMGenericV1) BiRPCV1GetMaxUsage(clnt *rpc2.Client, - ev map[string]any, maxUsage *float64) (err error) { - return smgv1.Ss.BiRPCV1GetMaxUsage(clnt, ev, maxUsage) -} - -// Called on session start, returns the maximum number of seconds the session can last -func (smgv1 *SMGenericV1) BiRPCV1InitiateSession(clnt *rpc2.Client, - ev map[string]any, maxUsage *float64) (err error) { - return smgv1.Ss.BiRPCV1InitiateSession(clnt, ev, maxUsage) -} - -// Interim updates, returns remaining duration from the rater -func (smgv1 *SMGenericV1) BiRPCV1UpdateSession(clnt *rpc2.Client, - ev map[string]any, maxUsage *float64) (err error) { - return smgv1.Ss.BiRPCV1UpdateSession(clnt, ev, maxUsage) -} - -// Called on session end, should stop debit loop -func (smgv1 *SMGenericV1) BiRPCV1TerminateSession(clnt *rpc2.Client, - ev map[string]any, reply *string) (err error) { - return smgv1.Ss.BiRPCV1TerminateSession(clnt, ev, reply) -} - -// Called on session end, should send the CDR to CDRS -func (smgv1 *SMGenericV1) BiRPCV1ProcessCDR(clnt *rpc2.Client, - ev map[string]any, reply *string) (err error) { - return smgv1.Ss.BiRPCV1ProcessCDR(clnt, ev, reply) -} - -// BiRPCv1CapsError is used to return error when the caps limit is hit -func (smgv1 *SMGenericV1) BiRPCV1CapsError(clnt *rpc2.Client, - args any, reply *string) (err error) { - return utils.ErrMaxConcurrentRPCExceeded -} diff --git a/apier/v1/stats.go b/apier/v1/stats.go index a6957ed2c..33c5be393 100644 --- a/apier/v1/stats.go +++ b/apier/v1/stats.go @@ -21,12 +21,13 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // GetStatQueueProfile returns a StatQueue profile -func (apierSv1 *APIerSv1) GetStatQueueProfile(arg *utils.TenantID, reply *engine.StatQueueProfile) (err error) { +func (apierSv1 *APIerSv1) GetStatQueueProfile(ctx *context.Context, arg *utils.TenantID, reply *engine.StatQueueProfile) (err error) { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -44,7 +45,7 @@ func (apierSv1 *APIerSv1) GetStatQueueProfile(arg *utils.TenantID, reply *engine } // GetStatQueueProfileIDs returns list of statQueueProfile IDs registered for a tenant -func (apierSv1 *APIerSv1) GetStatQueueProfileIDs(args *utils.PaginatorWithTenant, stsPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetStatQueueProfileIDs(ctx *context.Context, args *utils.PaginatorWithTenant, stsPrfIDs *[]string) error { tnt := args.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -66,7 +67,7 @@ func (apierSv1 *APIerSv1) GetStatQueueProfileIDs(args *utils.PaginatorWithTenant } // SetStatQueueProfile alters/creates a StatQueueProfile -func (apierSv1 *APIerSv1) SetStatQueueProfile(arg *engine.StatQueueProfileWithAPIOpts, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetStatQueueProfile(ctx *context.Context, arg *engine.StatQueueProfileWithAPIOpts, reply *string) (err error) { if missing := utils.MissingStructFields(arg.StatQueueProfile, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -92,7 +93,7 @@ func (apierSv1 *APIerSv1) SetStatQueueProfile(arg *engine.StatQueueProfileWithAP } // RemoveStatQueueProfile remove a specific stat configuration -func (apierSv1 *APIerSv1) RemoveStatQueueProfile(args *utils.TenantIDWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) RemoveStatQueueProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -128,48 +129,48 @@ type StatSv1 struct { sS *engine.StatService } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (stsv1 *StatSv1) Call(serviceMethod string, args any, reply any) error { +// Call implements birpc.ClientConnector interface for internal RPC +func (stsv1 *StatSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(stsv1, serviceMethod, args, reply) } // GetQueueIDs returns list of queueIDs registered for a tenant -func (stsv1 *StatSv1) GetQueueIDs(tenant *utils.TenantWithAPIOpts, qIDs *[]string) error { - return stsv1.sS.V1GetQueueIDs(tenant.Tenant, qIDs) +func (stsv1 *StatSv1) GetQueueIDs(ctx *context.Context, tenant *utils.TenantWithAPIOpts, qIDs *[]string) error { + return stsv1.sS.V1GetQueueIDs(ctx, tenant.Tenant, qIDs) } // ProcessEvent returns processes a new Event -func (stsv1 *StatSv1) ProcessEvent(args *utils.CGREvent, reply *[]string) error { - return stsv1.sS.V1ProcessEvent(args, reply) +func (stsv1 *StatSv1) ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) error { + return stsv1.sS.V1ProcessEvent(ctx, args, reply) } // GetStatQueuesForEvent returns the list of queues IDs in the system -func (stsv1 *StatSv1) GetStatQueuesForEvent(args *utils.CGREvent, reply *[]string) (err error) { - return stsv1.sS.V1GetStatQueuesForEvent(args, reply) +func (stsv1 *StatSv1) GetStatQueuesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) { + return stsv1.sS.V1GetStatQueuesForEvent(ctx, args, reply) } // GetStatQueue returns a StatQueue object -func (stsv1 *StatSv1) GetStatQueue(args *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) (err error) { - return stsv1.sS.V1GetStatQueue(args, reply) +func (stsv1 *StatSv1) GetStatQueue(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) (err error) { + return stsv1.sS.V1GetStatQueue(ctx, args, reply) } // GetQueueStringMetrics returns the string metrics for a Queue -func (stsv1 *StatSv1) GetQueueStringMetrics(args *utils.TenantIDWithAPIOpts, reply *map[string]string) (err error) { - return stsv1.sS.V1GetQueueStringMetrics(args.TenantID, reply) +func (stsv1 *StatSv1) GetQueueStringMetrics(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *map[string]string) (err error) { + return stsv1.sS.V1GetQueueStringMetrics(ctx, args.TenantID, reply) } // GetQueueFloatMetrics returns the float metrics for a Queue -func (stsv1 *StatSv1) GetQueueFloatMetrics(args *utils.TenantIDWithAPIOpts, reply *map[string]float64) (err error) { - return stsv1.sS.V1GetQueueFloatMetrics(args.TenantID, reply) +func (stsv1 *StatSv1) GetQueueFloatMetrics(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *map[string]float64) (err error) { + return stsv1.sS.V1GetQueueFloatMetrics(ctx, args.TenantID, reply) } // ResetStatQueue resets the stat queue -func (stsv1 *StatSv1) ResetStatQueue(tntID *utils.TenantIDWithAPIOpts, reply *string) error { - return stsv1.sS.V1ResetStatQueue(tntID.TenantID, reply) +func (stsv1 *StatSv1) ResetStatQueue(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { + return stsv1.sS.V1ResetStatQueue(ctx, args.TenantID, reply) } // Ping . -func (stsv1 *StatSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (stsv1 *StatSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } diff --git a/apier/v1/stats_it_test.go b/apier/v1/stats_it_test.go index 95d7f2f5c..852a7760b 100644 --- a/apier/v1/stats_it_test.go +++ b/apier/v1/stats_it_test.go @@ -22,13 +22,14 @@ package v1 import ( "math/rand" - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( stsV1CfgPath string stsV1Cfg *config.CGRConfig - stsV1Rpc *rpc.Client + stsV1Rpc *birpc.Client statConfig *engine.StatQueueProfileWithAPIOpts stsV1ConfDIR string //run tests for specific configuration @@ -171,7 +172,7 @@ func testV1STSRpcConn(t *testing.T) { func testV1STSCacheQueueBeforeLoad(t *testing.T) { // cache it with not found var replySq engine.StatQueue - if err := stsV1Rpc.Call(utils.StatSv1GetStatQueue, &utils.TenantIDWithAPIOpts{ + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetStatQueue, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: "cgrates.org", ID: "Stats1", @@ -182,7 +183,7 @@ func testV1STSCacheQueueBeforeLoad(t *testing.T) { // cache it with not found } func testV1STSCacheQueueAfterLoad(t *testing.T) { // the APIerSv1LoadTariffPlanFromFolder should also reload the cache for resources - if err := stsV1Rpc.Call(utils.StatSv1GetStatQueue, &utils.TenantIDWithAPIOpts{ + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetStatQueue, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: "cgrates.org", ID: "Stats1", @@ -195,7 +196,7 @@ func testV1STSCacheQueueAfterLoad(t *testing.T) { // the APIerSv1LoadTariffPlanF func testV1STSFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} - if err := stsV1Rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -204,7 +205,7 @@ func testV1STSFromFolder(t *testing.T) { func testV1STSGetStats(t *testing.T) { var reply []string expectedIDs := []string{"Stats1"} - if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueIDs, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedIDs, reply) { @@ -221,7 +222,7 @@ func testV1STSGetStats(t *testing.T) { utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: utils.NotAvailable, utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: utils.NotAvailable, } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil { t.Error(err) @@ -233,7 +234,7 @@ func testV1STSGetStats(t *testing.T) { func testV1STSV1StatSv1GetQueueStringMetricsWithoutTenant(t *testing.T) { var reply []string expectedIDs := []string{"CustomStatProfile", "Stats1", "StaticStatQueue", "StatWithThreshold"} - if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueIDs, &utils.TenantWithAPIOpts{}, &reply); err != nil { t.Error(err) } else { @@ -249,7 +250,7 @@ func testV1STSV1StatSv1GetQueueStringMetricsWithoutTenant(t *testing.T) { utils.MetaTCD: "18s", utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.CustomValue: "10", } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: expectedIDs[0]}}, &metrics); err != nil { t.Error(err) @@ -259,7 +260,7 @@ func testV1STSV1StatSv1GetQueueStringMetricsWithoutTenant(t *testing.T) { } func testV1STSV1StatSv1ResetAction(t *testing.T) { var reply string - if err := stsV1Rpc.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{ + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv2SetActions, &utils.AttrSetActions{ ActionsId: "ACT_RESET_STS", Actions: []*utils.TPAction{{Identifier: utils.MetaResetStatQueue, ExtraParameters: "cgrates.org:CustomStatProfile"}}, }, &reply); err != nil { @@ -268,7 +269,7 @@ func testV1STSV1StatSv1ResetAction(t *testing.T) { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrs := utils.AttrExecuteAction{Tenant: "cgrates.org", ActionsId: "ACT_RESET_STS"} - if err := stsV1Rpc.Call(utils.APIerSv1ExecuteAction, attrs, &reply); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrs, &reply); err != nil { t.Error(err) } var metrics map[string]string @@ -277,7 +278,7 @@ func testV1STSV1StatSv1ResetAction(t *testing.T) { utils.MetaTCD: utils.NotAvailable, utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.CustomValue: utils.NotAvailable, } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomStatProfile"}}, &metrics); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics, metrics) { @@ -299,7 +300,7 @@ func testV1STSProcessEvent(t *testing.T) { utils.PDD: 12 * time.Second, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -316,7 +317,7 @@ func testV1STSProcessEvent(t *testing.T) { utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: utils.NotAvailable, } var metrics map[string]string - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}}, &metrics); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics, metrics) { @@ -335,7 +336,7 @@ func testV1STSProcessEvent(t *testing.T) { utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: -1.0, } var floatMetrics map[string]float64 - if err := stsV1Rpc.Call(utils.StatSv1GetQueueFloatMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueFloatMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}}, &floatMetrics); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedFloatMetrics, floatMetrics) { @@ -352,7 +353,7 @@ func testV1STSProcessEvent(t *testing.T) { utils.Cost: 12.1, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args2, &reply); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args2, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -367,7 +368,7 @@ func testV1STSProcessEvent(t *testing.T) { utils.Cost: 0, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args3, &reply); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args3, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -383,7 +384,7 @@ func testV1STSProcessEvent(t *testing.T) { utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: "60000000000", } var metrics2 map[string]string - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}}, &metrics2); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics2, metrics2) { @@ -401,14 +402,14 @@ func testV1STSProcessEvent(t *testing.T) { utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: 60000000000, } var floatMetrics2 map[string]float64 - if err := stsV1Rpc.Call(utils.StatSv1GetQueueFloatMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueFloatMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}}, &floatMetrics2); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedFloatMetrics2, floatMetrics2) { t.Errorf("expecting: %+v, received reply: %+v", expectedFloatMetrics2, floatMetrics2) } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueFloatMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueFloatMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "Stats1"}}, &floatMetrics2); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedFloatMetrics2, floatMetrics2) { @@ -444,7 +445,7 @@ func testV1STSGetStatsAfterRestart(t *testing.T) { utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: "60000000000", } var metrics2 map[string]string - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}}, &metrics2); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics2, metrics2) { @@ -483,10 +484,10 @@ func testV1STSSetStatQueueProfile(t *testing.T) { } expErr := "SERVER_ERROR: broken reference to filter: <*wrong:inline> for item with ID: cgrates.org:TEST_PROFILE1" - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err == nil || err.Error() != expErr { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err == nil || err.Error() != expErr { t.Fatalf("Expected error: %q, received: %v", expErr, err) } - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -509,23 +510,23 @@ func testV1STSSetStatQueueProfile(t *testing.T) { }, }, } - if err := stsV1Rpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -536,12 +537,12 @@ func testV1STSSetStatQueueProfile(t *testing.T) { func testV1STSGetStatQueueProfileIDs(t *testing.T) { expected := []string{"Stats1", "TEST_PROFILE1"} var result []string - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) @@ -567,19 +568,19 @@ func testV1STSUpdateStatQueueProfile(t *testing.T) { }, }, } - if err := stsV1Rpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } statConfig.FilterIDs = []string{"FLTR_1", "FLTR_2"} - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.StatQueueProfile - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -589,18 +590,18 @@ func testV1STSUpdateStatQueueProfile(t *testing.T) { func testV1STSRemoveStatQueueProfile(t *testing.T) { var resp string - if err := stsV1Rpc.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } var sqp *engine.StatQueueProfile - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := stsV1Rpc.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &resp); err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err) } @@ -640,14 +641,14 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) { } //set the custom statProfile var result string - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //verify it var reply *engine.StatQueueProfile - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "CustomStatProfile"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -661,7 +662,7 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) { utils.MetaTCD: utils.NotAvailable, utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + "CustomValue": utils.NotAvailable, } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics, metrics) { @@ -679,7 +680,7 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) { "CustomValue": 7.0, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -690,7 +691,7 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) { utils.MetaTCD: "6s", utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + "CustomValue": utils.NotAvailable, } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil { t.Error(err) @@ -707,7 +708,7 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) { "CustomValue": 10.0, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -718,7 +719,7 @@ func testV1STSProcessMetricsWithFilter(t *testing.T) { utils.MetaTCD: "18s", utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + "CustomValue": "10", } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil { t.Error(err) @@ -754,14 +755,14 @@ func testV1STSProcessStaticMetrics(t *testing.T) { } //set the custom statProfile var result string - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //verify it var reply *engine.StatQueueProfile - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "StaticStatQueue"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -784,7 +785,7 @@ func testV1STSProcessStaticMetrics(t *testing.T) { "StaticMetrics": "StaticMetrics", }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -794,7 +795,7 @@ func testV1STSProcessStaticMetrics(t *testing.T) { utils.MetaSum + utils.HashtagSep + "1": "1", utils.MetaAverage + utils.HashtagSep + "2": "2", } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil { t.Error(err) @@ -802,7 +803,7 @@ func testV1STSProcessStaticMetrics(t *testing.T) { t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics) } //second process - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -811,7 +812,7 @@ func testV1STSProcessStaticMetrics(t *testing.T) { utils.MetaSum + utils.HashtagSep + "1": "2", utils.MetaAverage + utils.HashtagSep + "2": "2", } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil { t.Error(err) @@ -819,7 +820,7 @@ func testV1STSProcessStaticMetrics(t *testing.T) { t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics) } - if err := stsV1Rpc.Call(utils.StatSv1ResetStatQueue, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ResetStatQueue, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &result); err != nil { t.Error(err) @@ -830,7 +831,7 @@ func testV1STSProcessStaticMetrics(t *testing.T) { utils.MetaSum + utils.HashtagSep + "1": utils.NotAvailable, utils.MetaAverage + utils.HashtagSep + "2": utils.NotAvailable, } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil { t.Error(err) @@ -841,7 +842,7 @@ func testV1STSProcessStaticMetrics(t *testing.T) { func testV1STSStatsPing(t *testing.T) { var resp string - if err := stsV1Rpc.Call(utils.StatSv1Ping, new(utils.CGREvent), &resp); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1Ping, new(utils.CGREvent), &resp); err != nil { t.Error(err) } else if resp != utils.Pong { t.Error("Unexpected reply returned", resp) @@ -873,7 +874,7 @@ func testV1STSProcessStatWithThreshold(t *testing.T) { }, } var result string - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, stTh, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, stTh, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -894,7 +895,7 @@ func testV1STSProcessStatWithThreshold(t *testing.T) { Async: true, }, } - if err := stsV1Rpc.Call(utils.APIerSv1SetThresholdProfile, thSts, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, thSts, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -910,7 +911,7 @@ func testV1STSProcessStatWithThreshold(t *testing.T) { utils.Usage: 45 * time.Second, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -918,7 +919,7 @@ func testV1STSProcessStatWithThreshold(t *testing.T) { var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_Stat", Hits: 1} - if err := stsV1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := stsV1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Stat"}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd.Hits, td.Hits) { @@ -951,14 +952,14 @@ func testV1STSProcessCDRStat(t *testing.T) { } //set the custom statProfile var result string - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //verify it var reply *engine.StatQueueProfile - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "StatForCDR"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -1025,7 +1026,7 @@ func testV1STSProcessCDRStat(t *testing.T) { var reply2 []string expected := []string{"StatForCDR"} args := cdr.AsCGREvent() - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -1034,7 +1035,7 @@ func testV1STSProcessCDRStat(t *testing.T) { expectedMetrics = map[string]string{ utils.MetaSum + utils.HashtagSep + "~*req.CostDetails.Usage": "10000000000", } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatForCDR"}}, &metrics); err != nil { t.Error(err) @@ -1042,7 +1043,7 @@ func testV1STSProcessCDRStat(t *testing.T) { t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics) } //second process - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -1050,7 +1051,7 @@ func testV1STSProcessCDRStat(t *testing.T) { expectedMetrics = map[string]string{ utils.MetaSum + utils.HashtagSep + "~*req.CostDetails.Usage": "20000000000", } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatForCDR"}}, &metrics); err != nil { t.Error(err) @@ -1084,14 +1085,14 @@ func testV1STSOverWriteStats(t *testing.T) { } //set the custom statProfile var result string - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, initStat, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, initStat, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //verify it var reply *engine.StatQueueProfile - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "InitStat"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(initStat.StatQueueProfile, reply) { @@ -1102,7 +1103,7 @@ func testV1STSOverWriteStats(t *testing.T) { expectedMetrics := map[string]string{ utils.MetaSum + utils.HashtagSep + "1": utils.NotAvailable, } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "InitStat"}}, &metrics); err != nil { t.Error(err) @@ -1132,7 +1133,7 @@ func testV1STSOverWriteStats(t *testing.T) { MinItems: 1, }, } - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, initStat2, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, initStat2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1142,7 +1143,7 @@ func testV1STSOverWriteStats(t *testing.T) { expectedMetrics2 := map[string]string{ utils.MetaSum + utils.HashtagSep + "~*req.Test": utils.NotAvailable, } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "InitStat"}}, &metrics2); err != nil { t.Error(err) @@ -1176,7 +1177,7 @@ func testV1STSProcessStatWithThreshold2(t *testing.T) { }, } var result string - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, stTh, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, stTh, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1197,7 +1198,7 @@ func testV1STSProcessStatWithThreshold2(t *testing.T) { Async: true, }, } - if err := stsV1Rpc.Call(utils.APIerSv1SetThresholdProfile, thSts, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, thSts, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1213,7 +1214,7 @@ func testV1STSProcessStatWithThreshold2(t *testing.T) { utils.Usage: 45 * time.Second, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -1221,7 +1222,7 @@ func testV1STSProcessStatWithThreshold2(t *testing.T) { var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_Stat2", Hits: 1} - if err := stsV1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := stsV1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Stat"}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd.Hits, td.Hits) { @@ -1250,7 +1251,7 @@ func BenchmarkSTSV1SetEvent(b *testing.B) { var reply string b.StartTimer() for i := 0; i < b.N; i++ { - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &evs[rand.Intn(len(evs))], + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &evs[rand.Intn(len(evs))], &reply); err != nil { b.Error(err) } else if reply != utils.OK { @@ -1263,7 +1264,7 @@ func BenchmarkSTSV1SetEvent(b *testing.B) { func BenchmarkSTSV1GetQueueStringMetrics(b *testing.B) { for i := 0; i < b.N; i++ { var metrics map[string]string - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "STATS_1"}}, &metrics); err != nil { b.Error(err) @@ -1298,14 +1299,14 @@ func testV1STSGetStatQueueProfileWithoutTenant(t *testing.T) { }, } var result string - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } statConfig.Tenant = "cgrates.org" var reply *engine.StatQueueProfile - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{ID: "TEST_PROFILE10"}, &reply); err != nil { t.Error(err) @@ -1316,7 +1317,7 @@ func testV1STSGetStatQueueProfileWithoutTenant(t *testing.T) { func testV1STSRemStatQueueProfileWithoutTenant(t *testing.T) { var reply string - if err := stsV1Rpc.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "TEST_PROFILE10"}}, &reply); err != nil { t.Error(err) @@ -1324,7 +1325,7 @@ func testV1STSRemStatQueueProfileWithoutTenant(t *testing.T) { t.Error("Unexpected reply returned", reply) } var result *engine.StatQueueProfile - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{ID: "TEST_PROFILE10"}, &result); err == nil || utils.ErrNotFound.Error() != err.Error() { t.Error(err) @@ -1335,7 +1336,7 @@ func testV1STSV1GetQueueIDs(t *testing.T) { expected := []string{"StatWithThreshold", "Stats1", "StaticStatQueue", "CustomStatProfile"} sort.Strings(expected) var qIDs []string - if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueIDs, &utils.TenantWithAPIOpts{}, &qIDs); err != nil { t.Error(err) @@ -1344,7 +1345,7 @@ func testV1STSV1GetQueueIDs(t *testing.T) { if !reflect.DeepEqual(qIDs, expected) { t.Errorf("Expected %+v \n ,received %+v", expected, qIDs) } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueIDs, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &qIDs); err != nil { t.Error(err) @@ -1360,7 +1361,7 @@ func testV1STSV1GetQueueIDs(t *testing.T) { func testV1STSV1GetStatQueuesForEventWithoutTenant(t *testing.T) { var reply []string estats := []string{"Stats1"} - if err := stsV1Rpc.Call(utils.StatSv1GetStatQueuesForEvent, &utils.CGREvent{ + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetStatQueuesForEvent, &utils.CGREvent{ ID: "GetStats", Event: map[string]any{ utils.AccountField: "1002", @@ -1408,14 +1409,14 @@ func testV1STSSimulateAccountUpdate(t *testing.T) { } //set the custom statProfile var result string - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //verify it var reply *engine.StatQueueProfile - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "StatForAccountUpdate"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -1439,7 +1440,7 @@ func testV1STSSimulateAccountUpdate(t *testing.T) { utils.ID: "HolidayBalance", }, } - if err := stsV1Rpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetBalance, attrSetBalance, &result); err != nil { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) } else if result != utils.OK { t.Errorf("Calling APIerSv1.SetBalance received: %s", result) @@ -1450,7 +1451,7 @@ func testV1STSSimulateAccountUpdate(t *testing.T) { Tenant: "cgrates.org", Account: "testV1STSSimulateAccountUpdate", } - if err := stsV1Rpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } @@ -1463,7 +1464,7 @@ func testV1STSSimulateAccountUpdate(t *testing.T) { }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &acntUpdateEv, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &acntUpdateEv, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -1472,7 +1473,7 @@ func testV1STSSimulateAccountUpdate(t *testing.T) { expectedMetrics = map[string]string{ utils.MetaSum + utils.HashtagSep + "~*asm.BalanceSummaries.HolidayBalance.Value": "1.5", } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatForAccountUpdate"}}, &metrics); err != nil { t.Error(err) @@ -1480,7 +1481,7 @@ func testV1STSSimulateAccountUpdate(t *testing.T) { t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics) } //second process - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &acntUpdateEv, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &acntUpdateEv, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -1488,7 +1489,7 @@ func testV1STSSimulateAccountUpdate(t *testing.T) { expectedMetrics = map[string]string{ utils.MetaSum + utils.HashtagSep + "~*asm.BalanceSummaries.HolidayBalance.Value": "3", } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatForAccountUpdate"}}, &metrics); err != nil { t.Error(err) @@ -1516,12 +1517,12 @@ func testV1STSGetStatQueueWithoutExpired(t *testing.T) { MinItems: 1, }, } - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1Nanao"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -1543,13 +1544,13 @@ func testV1STSGetStatQueueWithoutExpired(t *testing.T) { utils.Usage: 10, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) } //verify metrics after first process - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1Nanao"}}, &metrics); err != nil { t.Error(err) @@ -1579,12 +1580,12 @@ func testV1STSGetStatQueueWithoutStored(t *testing.T) { MinItems: 1, }, } - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1NotStored"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -1606,31 +1607,31 @@ func testV1STSGetStatQueueWithoutStored(t *testing.T) { utils.Usage: 10 * time.Second, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) } //verify metrics after first process - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1NotStored"}}, &metrics); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics, metrics) { t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics) } - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) } //verify metrics after first process - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1NotStored"}}, &metrics); err != nil { t.Error(err) @@ -1645,7 +1646,7 @@ func testV1STSCheckMetricsAfterRestart(t *testing.T) { expectedMetrics := map[string]string{ utils.MetaSum + utils.HashtagSep + "~*asm.BalanceSummaries.HolidayBalance.Value": "3", } - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatForAccountUpdate"}}, &metrics); err != nil { t.Error(err) @@ -1656,7 +1657,7 @@ func testV1STSCheckMetricsAfterRestart(t *testing.T) { utils.MetaTCD: utils.NotAvailable, } metrics = map[string]string{} - if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1NotStored"}}, &metrics); err != nil { t.Error(err) @@ -1681,7 +1682,7 @@ func testStatSCacheProcessEventNotFound(t *testing.T) { utils.OptsStatsProfileIDs: []string{"STAT_CACHE"}, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } @@ -1701,7 +1702,7 @@ func testStatSCacheProcessEventFound(t *testing.T) { utils.OptsStatsProfileIDs: []string{"STAT_CACHE"}, }, } - if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply); err != nil { t.Error(err) } } @@ -1717,7 +1718,7 @@ func testStatSCacheSet(t *testing.T) { utils.CacheOpt: utils.MetaNone, }, } - if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Fatalf("Expected error: %+v, received: %+v", nil, err) } } @@ -1727,7 +1728,7 @@ func testStatSCacheReload(t *testing.T) { StatsQueueProfileIDs: []string{"cgrates.org:STAT_CACHE"}, } var reply string - if err := stsV1Rpc.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil { + if err := stsV1Rpc.Call(context.Background(), utils.CacheSv1ReloadCache, cache, &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Error("Calling CacheSv1.ReloadCache got reply: ", reply) diff --git a/apier/v1/thresholds.go b/apier/v1/thresholds.go index d27736105..e9b63e180 100644 --- a/apier/v1/thresholds.go +++ b/apier/v1/thresholds.go @@ -21,6 +21,7 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -35,38 +36,38 @@ type ThresholdSv1 struct { tS *engine.ThresholdService } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (tSv1 *ThresholdSv1) Call(serviceMethod string, args any, reply any) error { +// Call implements birpc.ClientConnector interface for internal RPC +func (tSv1 *ThresholdSv1) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(tSv1, serviceMethod, args, reply) } // GetThresholdIDs returns list of threshold IDs registered for a tenant -func (tSv1 *ThresholdSv1) GetThresholdIDs(tenant *utils.TenantWithAPIOpts, tIDs *[]string) error { - return tSv1.tS.V1GetThresholdIDs(tenant.Tenant, tIDs) +func (tSv1 *ThresholdSv1) GetThresholdIDs(ctx *context.Context, tenant *utils.TenantWithAPIOpts, tIDs *[]string) error { + return tSv1.tS.V1GetThresholdIDs(ctx, tenant.Tenant, tIDs) } // GetThresholdsForEvent returns a list of thresholds matching an event -func (tSv1 *ThresholdSv1) GetThresholdsForEvent(args *utils.CGREvent, reply *engine.Thresholds) error { - return tSv1.tS.V1GetThresholdsForEvent(args, reply) +func (tSv1 *ThresholdSv1) GetThresholdsForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.Thresholds) error { + return tSv1.tS.V1GetThresholdsForEvent(ctx, args, reply) } // GetThreshold queries a Threshold -func (tSv1 *ThresholdSv1) GetThreshold(tntID *utils.TenantIDWithAPIOpts, t *engine.Threshold) error { - return tSv1.tS.V1GetThreshold(tntID.TenantID, t) +func (tSv1 *ThresholdSv1) GetThreshold(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, t *engine.Threshold) error { + return tSv1.tS.V1GetThreshold(ctx, tntID.TenantID, t) } // ProcessEvent will process an Event -func (tSv1 *ThresholdSv1) ProcessEvent(args *utils.CGREvent, tIDs *[]string) error { - return tSv1.tS.V1ProcessEvent(args, tIDs) +func (tSv1 *ThresholdSv1) ProcessEvent(ctx *context.Context, args *utils.CGREvent, tIDs *[]string) error { + return tSv1.tS.V1ProcessEvent(ctx, args, tIDs) } // ResetThreshold resets the threshold hits -func (tSv1 *ThresholdSv1) ResetThreshold(tntID *utils.TenantIDWithAPIOpts, reply *string) error { - return tSv1.tS.V1ResetThreshold(tntID.TenantID, reply) +func (tSv1 *ThresholdSv1) ResetThreshold(ctx *context.Context, tntID *utils.TenantIDWithAPIOpts, reply *string) error { + return tSv1.tS.V1ResetThreshold(ctx, tntID.TenantID, reply) } // GetThresholdProfile returns a Threshold Profile -func (apierSv1 *APIerSv1) GetThresholdProfile(arg *utils.TenantID, reply *engine.ThresholdProfile) (err error) { +func (apierSv1 *APIerSv1) GetThresholdProfile(ctx *context.Context, arg *utils.TenantID, reply *engine.ThresholdProfile) (err error) { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -83,7 +84,7 @@ func (apierSv1 *APIerSv1) GetThresholdProfile(arg *utils.TenantID, reply *engine } // GetThresholdProfileIDs returns list of thresholdProfile IDs registered for a tenant -func (apierSv1 *APIerSv1) GetThresholdProfileIDs(args *utils.PaginatorWithTenant, thPrfIDs *[]string) error { +func (apierSv1 *APIerSv1) GetThresholdProfileIDs(ctx *context.Context, args *utils.PaginatorWithTenant, thPrfIDs *[]string) error { tnt := args.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -106,7 +107,7 @@ func (apierSv1 *APIerSv1) GetThresholdProfileIDs(args *utils.PaginatorWithTenant // GetThresholdProfileCount sets in reply var the total number of ThresholdProfileIDs registered for the received tenant // returns ErrNotFound in case of 0 ThresholdProfileIDs -func (apierSv1 *APIerSv1) GetThresholdProfileCount(args *utils.TenantWithAPIOpts, reply *int) (err error) { +func (apierSv1 *APIerSv1) GetThresholdProfileCount(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *int) (err error) { tnt := args.Tenant if tnt == utils.EmptyString { tnt = apierSv1.Config.GeneralCfg().DefaultTenant @@ -124,7 +125,7 @@ func (apierSv1 *APIerSv1) GetThresholdProfileCount(args *utils.TenantWithAPIOpts } // SetThresholdProfile alters/creates a ThresholdProfile -func (apierSv1 *APIerSv1) SetThresholdProfile(args *engine.ThresholdProfileWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) SetThresholdProfile(ctx *context.Context, args *engine.ThresholdProfileWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(args.ThresholdProfile, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -150,7 +151,7 @@ func (apierSv1 *APIerSv1) SetThresholdProfile(args *engine.ThresholdProfileWithA } // RemoveThresholdProfile removes a specific Threshold Profile -func (apierSv1 *APIerSv1) RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) RemoveThresholdProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -177,7 +178,7 @@ func (apierSv1 *APIerSv1) RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts } // Ping . -func (tSv1 *ThresholdSv1) Ping(ign *utils.CGREvent, reply *string) error { +func (tSv1 *ThresholdSv1) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } diff --git a/apier/v1/thresholds_it_test.go b/apier/v1/thresholds_it_test.go index acf4b28cf..b0a99bad2 100644 --- a/apier/v1/thresholds_it_test.go +++ b/apier/v1/thresholds_it_test.go @@ -21,7 +21,6 @@ along with this program. If not, see package v1 import ( - "net/rpc" "os" "path" "reflect" @@ -29,6 +28,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( tSv1CfgPath string tSv1Cfg *config.CGRConfig - tSv1Rpc *rpc.Client + tSv1Rpc *birpc.Client tPrfl *engine.ThresholdProfileWithAPIOpts tSv1ConfDIR string //run tests for specific configuration @@ -294,7 +295,7 @@ func testV1ThresholdStartCPUProfiling(t *testing.T) { DirPath: "/tmp", } var reply string - if err := tSv1Rpc.Call(utils.CoreSv1StartCPUProfiling, + if err := tSv1Rpc.Call(context.Background(), utils.CoreSv1StartCPUProfiling, argPath, &reply); err != nil { t.Error(err) } @@ -302,7 +303,7 @@ func testV1ThresholdStartCPUProfiling(t *testing.T) { func testV1TSCacheThresholdBeforeLoad(t *testing.T) { // cache it with not found var td engine.Threshold - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}}, &td); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -312,7 +313,7 @@ func testV1TSCacheThresholdBeforeLoad(t *testing.T) { // cache it with not found func testV1TSCacheThresholdAfterLoad(t *testing.T) { // the APIerSv1LoadTariffPlanFromFolder should also reload the cache for resources var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"} - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd, td) { @@ -322,7 +323,7 @@ func testV1TSCacheThresholdAfterLoad(t *testing.T) { // the APIerSv1LoadTariffPl func testV1TSFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} - if err := tSv1Rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -331,13 +332,13 @@ func testV1TSFromFolder(t *testing.T) { func testV1TSGetThresholds(t *testing.T) { var tIDs []string expectedIDs := []string{"THD_RES_1", "THD_STATS_2", "THD_STATS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED", "THD_STATS_3", "THD_CDRS_1"} - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThresholdIDs, &utils.TenantWithAPIOpts{}, &tIDs); err != nil { t.Error(err) } else if len(expectedIDs) != len(tIDs) { t.Errorf("expecting: %+v, received reply: %s", expectedIDs, tIDs) } - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThresholdIDs, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &tIDs); err != nil { t.Error(err) } else if len(expectedIDs) != len(tIDs) { @@ -345,7 +346,7 @@ func testV1TSGetThresholds(t *testing.T) { } var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: expectedIDs[0]} - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd, td) { @@ -356,53 +357,53 @@ func testV1TSGetThresholds(t *testing.T) { func testV1TSProcessEvent(t *testing.T) { var ids []string eIDs := []string{} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[0], &ids); err == nil || + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, &tEvs[0], &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } eIDs = []string{"THD_ACNT_BALANCE_1"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[1], &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, &tEvs[1], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_STATS_1"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[2], &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, &tEvs[2], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_STATS_2", "THD_STATS_1"} eIDs2 := []string{"THD_STATS_1", "THD_STATS_2"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[3], &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, &tEvs[3], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) && !reflect.DeepEqual(ids, eIDs2) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_STATS_3"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[4], &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, &tEvs[4], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_RES_1"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[5], &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, &tEvs[5], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[6], &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, &tEvs[6], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[7], &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, &tEvs[7], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_CDRS_1"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[8], &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, &tEvs[8], &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -412,14 +413,14 @@ func testV1TSProcessEvent(t *testing.T) { func testV1TSGetThresholdsAfterProcess(t *testing.T) { var tIDs []string expectedIDs := []string{"THD_RES_1", "THD_STATS_2", "THD_STATS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED"} - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThresholdIDs, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &tIDs); err != nil { t.Error(err) } else if len(expectedIDs) != len(tIDs) { // THD_STATS_3 is not reccurent, so it was removed t.Errorf("expecting: %+v, received reply: %s", expectedIDs, tIDs) } var td engine.Threshold - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}}, &td); err != nil { t.Error(err) } else if td.Snooze.IsZero() { // make sure Snooze time was reset during execution @@ -442,7 +443,7 @@ func testV1TSGetThresholdsAfterRestart(t *testing.T) { t.Fatal("Could not connect to rater: ", err.Error()) } var td engine.Threshold - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}}, &td); err != nil { t.Error(err) } else if td.Snooze.IsZero() { // make sure Snooze time was reset during execution @@ -471,10 +472,10 @@ func testV1TSSetThresholdProfileBrokenReference(t *testing.T) { }, } expErr := "SERVER_ERROR: broken reference to filter: for item with ID: cgrates.org:THD_Test" - if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err == nil || err.Error() != expErr { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err == nil || err.Error() != expErr { t.Fatalf("Expected error: %q, received: %v", expErr, err) } - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -484,12 +485,12 @@ func testV1TSSetThresholdProfileBrokenReference(t *testing.T) { func testv1TSGetThresholdProfileIDs(t *testing.T) { expected := []string{"THD_STATS_1", "THD_STATS_2", "THD_STATS_3", "THD_RES_1", "THD_CDRS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED"} var result []string - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) @@ -499,7 +500,7 @@ func testv1TSGetThresholdProfileIDs(t *testing.T) { func testV1TSSetThresholdProfile(t *testing.T) { var reply *engine.ThresholdProfile var result string - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -521,12 +522,12 @@ func testV1TSSetThresholdProfile(t *testing.T) { Async: true, }, } - if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { @@ -537,13 +538,13 @@ func testV1TSSetThresholdProfile(t *testing.T) { func testV1TSUpdateThresholdProfile(t *testing.T) { var result string tPrfl.FilterIDs = []string{"*string:~*req.Account:1001", "*prefix:~*opts.DST:10"} - if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.ThresholdProfile - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err != nil { t.Error(err) } else { @@ -557,19 +558,19 @@ func testV1TSUpdateThresholdProfile(t *testing.T) { func testV1TSRemoveThresholdProfile(t *testing.T) { var resp string - if err := tSv1Rpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } var sqp *engine.ThresholdProfile - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Received %s and the error:%+v", utils.ToJSON(sqp), err) } - if err := tSv1Rpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &resp); err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err) } @@ -578,7 +579,7 @@ func testV1TSRemoveThresholdProfile(t *testing.T) { func testV1TSMaxHits(t *testing.T) { var reply string // check if exist - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TH3"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -591,7 +592,7 @@ func testV1TSMaxHits(t *testing.T) { }, } //set - if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -607,7 +608,7 @@ func testV1TSMaxHits(t *testing.T) { }, } //process event - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -615,14 +616,14 @@ func testV1TSMaxHits(t *testing.T) { //check threshold after first process ( hits : 1) var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "TH3", Hits: 1} - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH3"}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd.Hits, td.Hits) { t.Errorf("expecting: %+v, received: %+v", eTd, td) } //process event - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -631,7 +632,7 @@ func testV1TSMaxHits(t *testing.T) { //check threshold for event var ths engine.Thresholds eTd.Hits = 2 - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdsForEvent, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThresholdsForEvent, thEvent, &ths); err != nil { t.Error(err) } else if len(ths) != 1 { @@ -644,7 +645,7 @@ func testV1TSMaxHits(t *testing.T) { //check threshold for event without tenant thEvent.Tenant = utils.EmptyString - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdsForEvent, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThresholdsForEvent, thEvent, &ths); err != nil { t.Error(err) } else if len(ths) != 1 { @@ -657,7 +658,7 @@ func testV1TSMaxHits(t *testing.T) { //check threshold after second process ( hits : 2) eTd.Hits = 2 - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH3"}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd.Hits, td.Hits) { @@ -665,13 +666,13 @@ func testV1TSMaxHits(t *testing.T) { } //process event - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } //check threshold after third process (reached the maximum hits and should be removed) - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH3"}}, &td); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Err : %+v \n, td : %+v", err, utils.ToJSON(td)) @@ -681,7 +682,7 @@ func testV1TSMaxHits(t *testing.T) { func testV1TSUpdateSnooze(t *testing.T) { var reply string // check if exist - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TH4"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -696,7 +697,7 @@ func testV1TSUpdateSnooze(t *testing.T) { }, } //set - if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, customTh, &reply); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, customTh, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -716,7 +717,7 @@ func testV1TSUpdateSnooze(t *testing.T) { } tNow := time.Now() //process event - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -724,7 +725,7 @@ func testV1TSUpdateSnooze(t *testing.T) { //check threshold after first process ( hits : 1) var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "TH4", Hits: 1} - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH4"}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd.Hits, td.Hits) { @@ -743,14 +744,14 @@ func testV1TSUpdateSnooze(t *testing.T) { }, } //set - if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, customTh2, &reply); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, customTh2, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } eTd = engine.Threshold{Tenant: "cgrates.org", ID: "TH4"} - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH4"}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd, td) { // the threshold was reseted because the configuration chaged @@ -783,14 +784,14 @@ func testV1TSGetThresholdProfileWithoutTenant(t *testing.T) { }, } var reply string - if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } tPrfl.ThresholdProfile.Tenant = "cgrates.org" var result *engine.ThresholdProfile - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{ID: "randomID"}, &result); err != nil { t.Error(err) @@ -801,7 +802,7 @@ func testV1TSGetThresholdProfileWithoutTenant(t *testing.T) { func testV1TSRemThresholdProfileWithoutTenant(t *testing.T) { var reply string - if err := tSv1Rpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "randomID"}}, &reply); err != nil { t.Error(err) @@ -809,7 +810,7 @@ func testV1TSRemThresholdProfileWithoutTenant(t *testing.T) { t.Error("Unexpected reply returned", reply) } var result *engine.ThresholdProfile - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{ID: "randomID"}, &result); err == nil || utils.ErrNotFound.Error() != err.Error() { t.Error(err) @@ -818,14 +819,14 @@ func testV1TSRemThresholdProfileWithoutTenant(t *testing.T) { func testv1TSGetThresholdProfileIDsCount(t *testing.T) { var reply int - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileCount, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfileCount, &utils.TenantWithAPIOpts{}, &reply); err != nil { t.Error(err) } else if reply != 7 { t.Errorf("Expected 7, received %+v", reply) } - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileCount, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfileCount, &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) @@ -846,7 +847,7 @@ func testV1TSProcessEventWithoutTenant(t *testing.T) { utils.OptsThresholdsProfileIDs: []string{"TH4"}, }, } - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -860,7 +861,7 @@ func testV1TSGetThresholdsWithoutTenant(t *testing.T) { Hits: 1, } var reply *engine.Threshold - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "THD_ACNT_BALANCE_1"}}, &reply); err != nil { t.Error(err) @@ -891,13 +892,13 @@ func testV1TSProcessAccountUpdateEvent(t *testing.T) { Async: true, }, } - if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, thAcntUpdate, &result); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, thAcntUpdate, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.ThresholdProfile - if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile, + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TH_ACNT_UPDATE_EV"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(thAcntUpdate.ThresholdProfile, reply) { @@ -913,7 +914,7 @@ func testV1TSProcessAccountUpdateEvent(t *testing.T) { utils.ID: "HolidayBalance", }, } - if err := tSv1Rpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &result); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1SetBalance, attrSetBalance, &result); err != nil { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) } else if result != utils.OK { t.Errorf("Calling APIerSv1.SetBalance received: %s", result) @@ -924,7 +925,7 @@ func testV1TSProcessAccountUpdateEvent(t *testing.T) { Tenant: "cgrates.org", Account: "testV1TSProcessAccountUpdateEvent", } - if err := tSv1Rpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } @@ -939,7 +940,7 @@ func testV1TSProcessAccountUpdateEvent(t *testing.T) { var ids []string eIDs := []string{"TH_ACNT_UPDATE_EV"} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, acntUpdateEv, &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, acntUpdateEv, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -954,7 +955,7 @@ func testV1TSResetThresholdsWithoutTenant(t *testing.T) { Hits: 1, } var reply *engine.Threshold - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "THD_ACNT_BALANCE_1"}}, &reply); err != nil { t.Fatal(err) @@ -964,7 +965,7 @@ func testV1TSResetThresholdsWithoutTenant(t *testing.T) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedThreshold), utils.ToJSON(reply)) } var result string - if err := tSv1Rpc.Call(utils.ThresholdSv1ResetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ResetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "THD_ACNT_BALANCE_1"}}, &result); err != nil { t.Fatal(err) @@ -973,7 +974,7 @@ func testV1TSResetThresholdsWithoutTenant(t *testing.T) { } expectedThreshold.Hits = 0 reply = nil - if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold, + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "THD_ACNT_BALANCE_1"}}, &reply); err != nil { t.Fatal(err) @@ -987,7 +988,7 @@ func testV1TSResetThresholdsWithoutTenant(t *testing.T) { func testV1ThresholdStopCPUProfiling(t *testing.T) { argPath := "/tmp/cpu.prof" var reply string - if err := tSv1Rpc.Call(utils.CoreSv1StopCPUProfiling, + if err := tSv1Rpc.Call(context.Background(), utils.CoreSv1StopCPUProfiling, new(utils.DirectoryArgs), &reply); err != nil { t.Error(err) } @@ -1022,7 +1023,7 @@ func testThresholdSCacheProcessEventNotFound(t *testing.T) { utils.OptsThresholdsProfileIDs: []string{"THRESHOLD_CACHE"}, }, } - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } @@ -1039,7 +1040,7 @@ func testThresholdSCacheProcessEventFound(t *testing.T) { utils.OptsThresholdsProfileIDs: []string{"THRESHOLD_CACHE"}, }, } - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } } @@ -1055,7 +1056,7 @@ func testThresholdSCacheSet(t *testing.T) { utils.CacheOpt: utils.MetaNone, }, } - if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1067,7 +1068,7 @@ func testThresholdSCacheReload(t *testing.T) { ThresholdProfileIDs: []string{"cgrates.org:THRESHOLD_CACHE"}, } var reply string - if err := tSv1Rpc.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil { + if err := tSv1Rpc.Call(context.Background(), utils.CacheSv1ReloadCache, cache, &reply); err != nil { t.Error("Got error on CacheSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Error("Calling CacheSv1.ReloadCache got reply: ", reply) diff --git a/apier/v1/timing.go b/apier/v1/timing.go index 961eeb6dc..aa94f7bc4 100644 --- a/apier/v1/timing.go +++ b/apier/v1/timing.go @@ -21,11 +21,12 @@ package v1 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // GetTiming returns a TPTiming object -func (apierSv1 *APIerSv1) GetTiming(arg *utils.ArgsGetTimingID, reply *utils.TPTiming) (err error) { +func (apierSv1 *APIerSv1) GetTiming(ctx *context.Context, arg *utils.ArgsGetTimingID, reply *utils.TPTiming) (err error) { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -39,7 +40,7 @@ func (apierSv1 *APIerSv1) GetTiming(arg *utils.ArgsGetTimingID, reply *utils.TPT } // SetTiming alters/creates a TPTimingWithAPIOpts -func (apierSv1 *APIerSv1) SetTiming(args *utils.TPTimingWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) SetTiming(ctx *context.Context, args *utils.TPTimingWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(args.TPTiming, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -63,7 +64,7 @@ func (apierSv1 *APIerSv1) SetTiming(args *utils.TPTimingWithAPIOpts, reply *stri } // RemoveTiming removes a specific TPTimingWithAPIOpts instance -func (apierSv1 *APIerSv1) RemoveTiming(args *utils.TPTimingWithAPIOpts, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTiming(ctx *context.Context, args *utils.TPTimingWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(args.TPTiming, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/timing_it_test.go b/apier/v1/timing_it_test.go index df6faaf49..a9153422d 100644 --- a/apier/v1/timing_it_test.go +++ b/apier/v1/timing_it_test.go @@ -22,11 +22,12 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -35,7 +36,7 @@ import ( var ( timCfgPath string timCfg *config.CGRConfig - timSRPC *rpc.Client + timSRPC *birpc.Client timConfigDIR string //run tests for specific configuration sTestsTiming = []func(t *testing.T){ @@ -119,7 +120,7 @@ func testTimingKillEngine(t *testing.T) { func testTimingGetTimingNotFound(t *testing.T) { var reply *utils.TPTiming - if err := timSRPC.Call(utils.APIerSv1GetTiming, &utils.ArgsGetTimingID{ID: "MIDNIGHT"}, + if err := timSRPC.Call(context.Background(), utils.APIerSv1GetTiming, &utils.ArgsGetTimingID{ID: "MIDNIGHT"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -141,7 +142,7 @@ func testTimingSetTiming(t *testing.T) { var reply string - if err := timSRPC.Call(utils.APIerSv1SetTiming, timing, &reply); err != nil { + if err := timSRPC.Call(context.Background(), utils.APIerSv1SetTiming, timing, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -150,7 +151,7 @@ func testTimingSetTiming(t *testing.T) { func testTimingGetTimingAfterSet(t *testing.T) { var reply *utils.TPTiming - if err := timSRPC.Call(utils.APIerSv1GetTiming, &utils.ArgsGetTimingID{ID: "MIDNIGHT"}, + if err := timSRPC.Call(context.Background(), utils.APIerSv1GetTiming, &utils.ArgsGetTimingID{ID: "MIDNIGHT"}, &reply); err != nil { t.Fatal(err) } @@ -170,7 +171,7 @@ func testTimingGetTimingAfterSet(t *testing.T) { func testTimingRemoveTiming(t *testing.T) { var reply string - if err := timSRPC.Call(utils.APIerSv1RemoveTiming, + if err := timSRPC.Call(context.Background(), utils.APIerSv1RemoveTiming, &utils.ArgsGetTimingID{ID: "MIDNIGHT"}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { diff --git a/apier/v1/tp.go b/apier/v1/tp.go index 160ce9a49..6e018cb58 100644 --- a/apier/v1/tp.go +++ b/apier/v1/tp.go @@ -25,6 +25,7 @@ import ( "os" "path/filepath" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -33,7 +34,7 @@ type AttrGetTPIds struct { } // Queries tarrif plan identities gathered from all tables. -func (apierSv1 *APIerSv1) GetTPIds(attrs *AttrGetTPIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPIds(ctx *context.Context, attrs *AttrGetTPIds, reply *[]string) error { if ids, err := apierSv1.StorDb.GetTpIds(utils.EmptyString); err != nil { return utils.NewErrServerError(err) } else if ids == nil { @@ -49,7 +50,7 @@ type AttrImportTPZipFile struct { File []byte } -func (apierSv1 *APIerSv1) ImportTPZipFile(attrs *AttrImportTPZipFile, reply *string) error { +func (apierSv1 *APIerSv1) ImportTPZipFile(ctx *context.Context, attrs *AttrImportTPZipFile, reply *string) error { tmpDir, err := os.MkdirTemp("/tmp", "cgr_") if err != nil { *reply = "ERROR: creating temp directory!" @@ -102,7 +103,7 @@ type AttrRemTp struct { TPid string } -func (apierSv1 *APIerSv1) RemTP(attrs *AttrRemTp, reply *string) error { +func (apierSv1 *APIerSv1) RemTP(ctx *context.Context, attrs *AttrRemTp, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing(utils.TPid) } @@ -114,7 +115,7 @@ func (apierSv1 *APIerSv1) RemTP(attrs *AttrRemTp, reply *string) error { return nil } -func (apierSv1 *APIerSv1) ExportTPToFolder(attrs *utils.AttrDirExportTP, exported *utils.ExportedTPStats) error { +func (apierSv1 *APIerSv1) ExportTPToFolder(ctx *context.Context, attrs *utils.AttrDirExportTP, exported *utils.ExportedTPStats) error { if attrs.TPid == nil || *attrs.TPid == "" { return utils.NewErrMandatoryIeMissing(utils.TPid) } @@ -147,7 +148,7 @@ func (apierSv1 *APIerSv1) ExportTPToFolder(attrs *utils.AttrDirExportTP, exporte return nil } -func (apierSv1 *APIerSv1) ExportTPToZipString(attrs *utils.AttrDirExportTP, reply *string) error { +func (apierSv1 *APIerSv1) ExportTPToZipString(ctx *context.Context, attrs *utils.AttrDirExportTP, reply *string) error { if attrs.TPid == nil || *attrs.TPid == utils.EmptyString { return utils.NewErrMandatoryIeMissing(utils.TPid) } diff --git a/apier/v1/tp_it_test.go b/apier/v1/tp_it_test.go index b954a8c13..e9d55b874 100644 --- a/apier/v1/tp_it_test.go +++ b/apier/v1/tp_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( tpCfgPath string tpCfg *config.CGRConfig - tpRPC *rpc.Client + tpRPC *birpc.Client tpConfigDIR string //run tests for specific configuration sTestsTP = []func(t *testing.T){ @@ -106,7 +107,7 @@ func testTPRpcConn(t *testing.T) { func testTPImportTPFromFolderPath(t *testing.T) { var reply string - if err := tpRPC.Call(utils.APIerSv1ImportTariffPlanFromFolder, + if err := tpRPC.Call(context.Background(), utils.APIerSv1ImportTariffPlanFromFolder, utils.AttrImportTPFromFolder{TPid: "TEST_TPID2", FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}, &reply); err != nil { t.Error("Got error on APIerSv1.ImportTarrifPlanFromFolder: ", err.Error()) @@ -129,7 +130,7 @@ func testTPExportTPToFolder(t *testing.T) { tpid := "TEST_TPID2" compress := true exportPath := "/tmp/" - if err := tpRPC.Call(utils.APIerSv1ExportTPToFolder, &utils.AttrDirExportTP{TPid: &tpid, ExportPath: &exportPath, Compress: &compress}, &reply); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv1ExportTPToFolder, &utils.AttrDirExportTP{TPid: &tpid, ExportPath: &exportPath, Compress: &compress}, &reply); err != nil { t.Error("Got error on APIerSv1.ExportTPToFolder: ", err.Error()) } else if !reflect.DeepEqual(reply.ExportPath, expectedTPStas.ExportPath) { t.Errorf("Expecting : %+v, received: %+v", expectedTPStas.ExportPath, reply.ExportPath) @@ -145,7 +146,7 @@ func testTPExportTPToFolderWithError(t *testing.T) { tpid := "UnexistedTP" compress := true exportPath := "/tmp/" - if err := tpRPC.Call(utils.APIerSv1ExportTPToFolder, + if err := tpRPC.Call(context.Background(), utils.APIerSv1ExportTPToFolder, &utils.AttrDirExportTP{TPid: &tpid, ExportPath: &exportPath, Compress: &compress}, &reply); err == nil || err.Error() != utils.NewErrServerError(utils.ErrNotFound).Error() { t.Error("Expecting error, received: ", err) } diff --git a/apier/v1/tpaccountactions.go b/apier/v1/tpaccountactions.go index e359e65c2..944275243 100644 --- a/apier/v1/tpaccountactions.go +++ b/apier/v1/tpaccountactions.go @@ -19,12 +19,13 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // SetTPAccountActions creates a new AccountActions profile within a tariff plan -func (apierSv1 *APIerSv1) SetTPAccountActions(attrs *utils.TPAccountActions, reply *string) error { +func (apierSv1 *APIerSv1) SetTPAccountActions(ctx *context.Context, attrs *utils.TPAccountActions, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.LoadId, utils.AccountField, utils.ActionPlanId}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) @@ -45,7 +46,7 @@ type AttrGetTPAccountActionsByLoadId struct { } // GetTPAccountActionsByLoadId queries specific AccountActions profile on tariff plan -func (apierSv1 *APIerSv1) GetTPAccountActionsByLoadId(attrs *utils.TPAccountActions, reply *[]*utils.TPAccountActions) error { +func (apierSv1 *APIerSv1) GetTPAccountActionsByLoadId(ctx *context.Context, attrs *utils.TPAccountActions, reply *[]*utils.TPAccountActions) error { mndtryFlds := []string{utils.TPid, utils.LoadId} if len(attrs.Account) != 0 { // If account provided as filter, make all related fields mandatory mndtryFlds = append(mndtryFlds, utils.AccountField) @@ -73,7 +74,7 @@ type AttrGetTPAccountActions struct { } // GetTPAccountActions queries specific DerivedCharge on tariff plan -func (apierSv1 *APIerSv1) GetTPAccountActions(attrs *AttrGetTPAccountActions, reply *utils.TPAccountActions) error { +func (apierSv1 *APIerSv1) GetTPAccountActions(ctx *context.Context, attrs *AttrGetTPAccountActions, reply *utils.TPAccountActions) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.AccountActionsId}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -98,7 +99,7 @@ type AttrGetTPAccountActionIds struct { } // GetTPAccountActionLoadIds queries AccountActions identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPAccountActionLoadIds(attrs *AttrGetTPAccountActionIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPAccountActionLoadIds(ctx *context.Context, attrs *AttrGetTPAccountActionIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -115,7 +116,7 @@ func (apierSv1 *APIerSv1) GetTPAccountActionLoadIds(attrs *AttrGetTPAccountActio } // GetTPAccountActionIds queries DerivedCharges identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPAccountActionIds(attrs *AttrGetTPAccountActionIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPAccountActionIds(ctx *context.Context, attrs *AttrGetTPAccountActionIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -132,7 +133,7 @@ func (apierSv1 *APIerSv1) GetTPAccountActionIds(attrs *AttrGetTPAccountActionIds } // RemoveTPAccountActions removes specific AccountActions on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPAccountActions(attrs *AttrGetTPAccountActions, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPAccountActions(ctx *context.Context, attrs *AttrGetTPAccountActions, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.AccountActionsId}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpaccountactions_it_test.go b/apier/v1/tpaccountactions_it_test.go index 687eb0811..a4adba180 100644 --- a/apier/v1/tpaccountactions_it_test.go +++ b/apier/v1/tpaccountactions_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpAccActionsCfgPath string tpAccActionsCfg *config.CGRConfig - tpAccActionsRPC *rpc.Client + tpAccActionsRPC *birpc.Client tpAccActions *utils.TPAccountActions tpAccActionsDelay int tpAccActionsConfigDIR string //run tests for specific configuration @@ -115,7 +116,7 @@ func testTPAccActionsRpcConn(t *testing.T) { func testTPAccActionsGetTPAccActionBeforeSet(t *testing.T) { var reply *utils.TPAccountActions - if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActions, + if err := tpAccActionsRPC.Call(context.Background(), utils.APIerSv1GetTPAccountActions, &AttrGetTPAccountActions{TPid: "TPAcc", AccountActionsId: tpAccActionID}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -135,7 +136,7 @@ func testTPAccActionsSetTPAccAction(t *testing.T) { Disabled: false, } var result string - if err := tpAccActionsRPC.Call(utils.APIerSv1SetTPAccountActions, tpAccActions, &result); err != nil { + if err := tpAccActionsRPC.Call(context.Background(), utils.APIerSv1SetTPAccountActions, tpAccActions, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -144,7 +145,7 @@ func testTPAccActionsSetTPAccAction(t *testing.T) { func testTPAccActionsGetTPAccActionAfterSet(t *testing.T) { var reply *utils.TPAccountActions - if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActions, + if err := tpAccActionsRPC.Call(context.Background(), utils.APIerSv1GetTPAccountActions, &AttrGetTPAccountActions{TPid: "TPAcc", AccountActionsId: tpAccActionID}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpAccActions, reply) { @@ -154,7 +155,7 @@ func testTPAccActionsGetTPAccActionAfterSet(t *testing.T) { func testTPAccActionsGetTPAccountActionsByLoadId(t *testing.T) { var reply *[]*utils.TPAccountActions - if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActionsByLoadId, + if err := tpAccActionsRPC.Call(context.Background(), utils.APIerSv1GetTPAccountActionsByLoadId, &utils.TPAccountActions{TPid: "TPAcc", LoadId: "ID"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpAccActions, (*reply)[0]) { @@ -165,7 +166,7 @@ func testTPAccActionsGetTPAccountActionsByLoadId(t *testing.T) { func testTPAccActionsGetTPAccountActionLoadIds(t *testing.T) { var result []string expectedTPID := []string{"ID"} - if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActionLoadIds, + if err := tpAccActionsRPC.Call(context.Background(), utils.APIerSv1GetTPAccountActionLoadIds, &AttrGetTPAccountActionIds{TPid: "TPAcc"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -176,7 +177,7 @@ func testTPAccActionsGetTPAccountActionLoadIds(t *testing.T) { func testTPAccActionsGetTPAccountActionIds(t *testing.T) { var result []string expectedTPID := []string{"ID:cgrates.org:1001"} - if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActionIds, + if err := tpAccActionsRPC.Call(context.Background(), utils.APIerSv1GetTPAccountActionIds, &AttrGetTPAccountActionIds{TPid: "TPAcc"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -187,7 +188,7 @@ func testTPAccActionsGetTPAccountActionIds(t *testing.T) { func testTPAccActionsUpdateTPAccAction(t *testing.T) { tpAccActions.ActionPlanId = "PlanOne" var result string - if err := tpAccActionsRPC.Call(utils.APIerSv1SetTPAccountActions, tpAccActions, &result); err != nil { + if err := tpAccActionsRPC.Call(context.Background(), utils.APIerSv1SetTPAccountActions, tpAccActions, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -197,7 +198,7 @@ func testTPAccActionsUpdateTPAccAction(t *testing.T) { func testTPAccActionsGetTPAccActionAfterUpdate(t *testing.T) { var reply *utils.TPAccountActions - if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActions, + if err := tpAccActionsRPC.Call(context.Background(), utils.APIerSv1GetTPAccountActions, &AttrGetTPAccountActions{TPid: "TPAcc", AccountActionsId: tpAccActionID}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpAccActions, reply) { @@ -208,7 +209,7 @@ func testTPAccActionsGetTPAccActionAfterUpdate(t *testing.T) { func testTPAccActionsRemTPAccAction(t *testing.T) { var resp string - if err := tpAccActionsRPC.Call(utils.APIerSv1RemoveTPAccountActions, + if err := tpAccActionsRPC.Call(context.Background(), utils.APIerSv1RemoveTPAccountActions, &AttrGetTPAccountActions{TPid: "TPAcc", AccountActionsId: tpAccActionID}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -218,7 +219,7 @@ func testTPAccActionsRemTPAccAction(t *testing.T) { func testTPAccActionsGetTPAccActionAfterRemove(t *testing.T) { var reply *utils.TPAccountActions - if err := tpAccActionsRPC.Call(utils.APIerSv1GetTPAccountActions, + if err := tpAccActionsRPC.Call(context.Background(), utils.APIerSv1GetTPAccountActions, &AttrGetTPAccountActions{TPid: "TPAcc", AccountActionsId: tpAccActionID}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) diff --git a/apier/v1/tpactionplans.go b/apier/v1/tpactionplans.go index dcc34c728..52fe74631 100644 --- a/apier/v1/tpactionplans.go +++ b/apier/v1/tpactionplans.go @@ -21,11 +21,12 @@ package v1 import ( "fmt" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPActionPlan creates a new ActionTimings profile within a tariff plan -func (apierSv1 *APIerSv1) SetTPActionPlan(attrs *utils.TPActionPlan, reply *string) error { +func (apierSv1 *APIerSv1) SetTPActionPlan(ctx *context.Context, attrs *utils.TPActionPlan, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.ActionPlan}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -48,7 +49,7 @@ type AttrGetTPActionPlan struct { } // GetTPActionPlan queries specific ActionPlan profile on tariff plan -func (apierSv1 *APIerSv1) GetTPActionPlan(attrs *AttrGetTPActionPlan, reply *utils.TPActionPlan) error { +func (apierSv1 *APIerSv1) GetTPActionPlan(ctx *context.Context, attrs *AttrGetTPActionPlan, reply *utils.TPActionPlan) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -69,7 +70,7 @@ type AttrGetTPActionPlanIds struct { } // GetTPActionPlanIds queries ActionPlan identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPActionPlanIds(attrs *AttrGetTPActionPlanIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPActionPlanIds(ctx *context.Context, attrs *AttrGetTPActionPlanIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -86,7 +87,7 @@ func (apierSv1 *APIerSv1) GetTPActionPlanIds(attrs *AttrGetTPActionPlanIds, repl } // RemoveTPActionPlan removes specific ActionPlan on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPActionPlan(attrs *AttrGetTPActionPlan, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPActionPlan(ctx *context.Context, attrs *AttrGetTPActionPlan, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpactionplans_it_test.go b/apier/v1/tpactionplans_it_test.go index 6e64870f2..afe0c6d29 100644 --- a/apier/v1/tpactionplans_it_test.go +++ b/apier/v1/tpactionplans_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpAccPlansCfgPath string tpAccPlansCfg *config.CGRConfig - tpAccPlansRPC *rpc.Client + tpAccPlansRPC *birpc.Client tpAccPlan *utils.TPActionPlan tpAccPlansDelay int tpAccPlansConfigDIR string //run tests for specific configuration @@ -118,7 +119,7 @@ func testTPAccPlansRpcConn(t *testing.T) { func testTPAccPlansGetTPAccPlanBeforeSet(t *testing.T) { var reply *utils.TPActionPlan - if err := tpAccPlansRPC.Call(utils.APIerSv1GetTPActionPlan, + if err := tpAccPlansRPC.Call(context.Background(), utils.APIerSv1GetTPActionPlan, &AttrGetTPActionPlan{TPid: "TPAcc", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -142,7 +143,7 @@ func testTPAccPlansSetTPAccPlan(t *testing.T) { }, } var result string - if err := tpAccPlansRPC.Call(utils.APIerSv1SetTPActionPlan, tpAccPlan, &result); err != nil { + if err := tpAccPlansRPC.Call(context.Background(), utils.APIerSv1SetTPActionPlan, tpAccPlan, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -151,7 +152,7 @@ func testTPAccPlansSetTPAccPlan(t *testing.T) { func testTPAccPlansGetTPAccPlanAfterSet(t *testing.T) { var reply *utils.TPActionPlan - if err := tpAccPlansRPC.Call(utils.APIerSv1GetTPActionPlan, + if err := tpAccPlansRPC.Call(context.Background(), utils.APIerSv1GetTPActionPlan, &AttrGetTPActionPlan{TPid: "TPAcc", ID: "ID"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpAccPlan.TPid, reply.TPid) { @@ -166,7 +167,7 @@ func testTPAccPlansGetTPAccPlanAfterSet(t *testing.T) { func testTPAccPlansGetTPAccPlanIds(t *testing.T) { var result []string expectedTPID := []string{"ID"} - if err := tpAccPlansRPC.Call(utils.APIerSv1GetTPActionPlanIds, + if err := tpAccPlansRPC.Call(context.Background(), utils.APIerSv1GetTPActionPlanIds, &AttrGetTPActionPlanIds{TPid: "TPAcc"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -194,7 +195,7 @@ func testTPAccPlansUpdateTPAccPlan(t *testing.T) { }, } var result string - if err := tpAccPlansRPC.Call(utils.APIerSv1SetTPActionPlan, tpAccPlan, &result); err != nil { + if err := tpAccPlansRPC.Call(context.Background(), utils.APIerSv1SetTPActionPlan, tpAccPlan, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -204,7 +205,7 @@ func testTPAccPlansUpdateTPAccPlan(t *testing.T) { func testTPAccPlansGetTPAccPlanAfterUpdate(t *testing.T) { var reply *utils.TPActionPlan - if err := tpAccPlansRPC.Call(utils.APIerSv1GetTPActionPlan, + if err := tpAccPlansRPC.Call(context.Background(), utils.APIerSv1GetTPActionPlan, &AttrGetTPActionPlan{TPid: "TPAcc", ID: "ID"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpAccPlan.TPid, reply.TPid) { @@ -219,7 +220,7 @@ func testTPAccPlansGetTPAccPlanAfterUpdate(t *testing.T) { func testTPAccPlansRemTPAccPlan(t *testing.T) { var resp string - if err := tpAccPlansRPC.Call(utils.APIerSv1RemoveTPActionPlan, + if err := tpAccPlansRPC.Call(context.Background(), utils.APIerSv1RemoveTPActionPlan, &AttrGetTPActionPlan{TPid: "TPAcc", ID: "ID"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -230,7 +231,7 @@ func testTPAccPlansRemTPAccPlan(t *testing.T) { func testTPAccPlansGetTPAccPlanAfterRemove(t *testing.T) { var reply *utils.TPActionPlan - if err := tpAccPlansRPC.Call(utils.APIerSv1GetTPActionPlan, + if err := tpAccPlansRPC.Call(context.Background(), utils.APIerSv1GetTPActionPlan, &AttrGetTPActionPlan{TPid: "TPAcc", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/apier/v1/tpactions.go b/apier/v1/tpactions.go index fcdacc1c9..58e397187 100644 --- a/apier/v1/tpactions.go +++ b/apier/v1/tpactions.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPActions creates a new Actions profile within a tariff plan -func (apierSv1 *APIerSv1) SetTPActions(attrs *utils.TPActions, reply *string) error { +func (apierSv1 *APIerSv1) SetTPActions(ctx *context.Context, attrs *utils.TPActions, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.Actions}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -40,7 +41,7 @@ type AttrGetTPActions struct { } // GetTPActions queries specific Actions profile on tariff plan -func (apierSv1 *APIerSv1) GetTPActions(attrs *AttrGetTPActions, reply *utils.TPActions) error { +func (apierSv1 *APIerSv1) GetTPActions(ctx *context.Context, attrs *AttrGetTPActions, reply *utils.TPActions) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -61,7 +62,7 @@ type AttrGetTPActionIds struct { } // GetTPActionIds queries Actions identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPActionIds(attrs *AttrGetTPActionIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPActionIds(ctx *context.Context, attrs *AttrGetTPActionIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -78,7 +79,7 @@ func (apierSv1 *APIerSv1) GetTPActionIds(attrs *AttrGetTPActionIds, reply *[]str } // RemoveTPActions removes specific Actions on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPActions(attrs *AttrGetTPActions, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPActions(ctx *context.Context, attrs *AttrGetTPActions, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpactions_it_test.go b/apier/v1/tpactions_it_test.go index b7a9b931e..47516dfc7 100644 --- a/apier/v1/tpactions_it_test.go +++ b/apier/v1/tpactions_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpActionCfgPath string tpActionCfg *config.CGRConfig - tpActionRPC *rpc.Client + tpActionRPC *birpc.Client tpActions *utils.TPActions tpActionDelay int tpActionConfigDIR string //run tests for specific configuration @@ -118,7 +119,7 @@ func testTPActionsRpcConn(t *testing.T) { func testTPActionsGetTPActionBeforeSet(t *testing.T) { var reply *utils.TPActionPlan - if err := tpActionRPC.Call(utils.APIerSv1GetTPActions, + if err := tpActionRPC.Call(context.Background(), utils.APIerSv1GetTPActions, &AttrGetTPActions{TPid: "TPAcc", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -170,7 +171,7 @@ func testTPActionsSetTPAction(t *testing.T) { }, } var result string - if err := tpActionRPC.Call(utils.APIerSv1SetTPActions, tpActions, &result); err != nil { + if err := tpActionRPC.Call(context.Background(), utils.APIerSv1SetTPActions, tpActions, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -179,7 +180,7 @@ func testTPActionsSetTPAction(t *testing.T) { func testTPActionsGetTPActionAfterSet(t *testing.T) { var reply *utils.TPActions - if err := tpActionRPC.Call(utils.APIerSv1GetTPActions, + if err := tpActionRPC.Call(context.Background(), utils.APIerSv1GetTPActions, &AttrGetTPActions{TPid: "TPAcc", ID: "ID"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpActions.TPid, reply.TPid) { @@ -194,7 +195,7 @@ func testTPActionsGetTPActionAfterSet(t *testing.T) { func testTPActionsGetTPActionIds(t *testing.T) { var result []string expectedTPID := []string{"ID"} - if err := tpActionRPC.Call(utils.APIerSv1GetTPActionIds, + if err := tpActionRPC.Call(context.Background(), utils.APIerSv1GetTPActionIds, &AttrGetTPActionIds{TPid: "TPAcc"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -263,7 +264,7 @@ func testTPActionsUpdateTPAction(t *testing.T) { }, } var result string - if err := tpActionRPC.Call(utils.APIerSv1SetTPActions, tpActions, &result); err != nil { + if err := tpActionRPC.Call(context.Background(), utils.APIerSv1SetTPActions, tpActions, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -273,7 +274,7 @@ func testTPActionsUpdateTPAction(t *testing.T) { func testTPActionsGetTPActionAfterUpdate(t *testing.T) { var reply *utils.TPActions - if err := tpActionRPC.Call(utils.APIerSv1GetTPActions, + if err := tpActionRPC.Call(context.Background(), utils.APIerSv1GetTPActions, &AttrGetTPActions{TPid: "TPAcc", ID: "ID"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpActions.TPid, reply.TPid) { @@ -288,7 +289,7 @@ func testTPActionsGetTPActionAfterUpdate(t *testing.T) { func testTPActionsRemTPAction(t *testing.T) { var resp string - if err := tpActionRPC.Call(utils.APIerSv1RemoveTPActions, + if err := tpActionRPC.Call(context.Background(), utils.APIerSv1RemoveTPActions, &AttrGetTPActions{TPid: "TPAcc", ID: "ID"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -299,7 +300,7 @@ func testTPActionsRemTPAction(t *testing.T) { func testTPActionsGetTPActionAfterRemove(t *testing.T) { var reply *utils.TPActionPlan - if err := tpActionRPC.Call(utils.APIerSv1GetTPActions, + if err := tpActionRPC.Call(context.Background(), utils.APIerSv1GetTPActions, &AttrGetTPActions{TPid: "TPAcc", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/apier/v1/tpactiontriggers.go b/apier/v1/tpactiontriggers.go index 6102e4dd1..e8b4f1e84 100644 --- a/apier/v1/tpactiontriggers.go +++ b/apier/v1/tpactiontriggers.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPActionTriggers creates a new ActionTriggers profile within a tariff plan -func (apierSv1 *APIerSv1) SetTPActionTriggers(attrs *utils.TPActionTriggers, reply *string) error { +func (apierSv1 *APIerSv1) SetTPActionTriggers(ctx *context.Context, attrs *utils.TPActionTriggers, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -41,7 +42,7 @@ type AttrGetTPActionTriggers struct { } // GetTPActionTriggers queries specific ActionTriggers profile on tariff plan -func (apierSv1 *APIerSv1) GetTPActionTriggers(attrs *AttrGetTPActionTriggers, reply *utils.TPActionTriggers) error { +func (apierSv1 *APIerSv1) GetTPActionTriggers(ctx *context.Context, attrs *AttrGetTPActionTriggers, reply *utils.TPActionTriggers) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -63,7 +64,7 @@ type AttrGetTPActionTriggerIds struct { } // GetTPActionTriggerIds queries ActionTriggers identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPActionTriggerIds(attrs *AttrGetTPActionTriggerIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPActionTriggerIds(ctx *context.Context, attrs *AttrGetTPActionTriggerIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -80,7 +81,7 @@ func (apierSv1 *APIerSv1) GetTPActionTriggerIds(attrs *AttrGetTPActionTriggerIds } // RemoveTPActionTriggers removes specific ActionTriggers on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPActionTriggers(attrs *AttrGetTPActionTriggers, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPActionTriggers(ctx *context.Context, attrs *AttrGetTPActionTriggers, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpactiontriggers_it_test.go b/apier/v1/tpactiontriggers_it_test.go index 1222ea162..7cd1fef27 100644 --- a/apier/v1/tpactiontriggers_it_test.go +++ b/apier/v1/tpactiontriggers_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpActionTriggerCfgPath string tpActionTriggerCfg *config.CGRConfig - tpActionTriggerRPC *rpc.Client + tpActionTriggerRPC *birpc.Client tpActionTriggers *utils.TPActionTriggers tpActionTriggerDelay int tpActionTriggerConfigDIR string //run tests for specific configuration @@ -118,7 +119,7 @@ func testTPActionTriggersRpcConn(t *testing.T) { func testTPActionTriggersGetTPActionTriggersBeforeSet(t *testing.T) { var reply *utils.TPActionTriggers - if err := tpActionTriggerRPC.Call(utils.APIerSv1GetTPActionTriggers, + if err := tpActionTriggerRPC.Call(context.Background(), utils.APIerSv1GetTPActionTriggers, &AttrGetTPActionTriggers{TPid: "TPAct", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -178,7 +179,7 @@ func testTPActionTriggersSetTPActionTriggers(t *testing.T) { }, } var result string - if err := tpActionTriggerRPC.Call(utils.APIerSv1SetTPActionTriggers, tpActionTriggers, &result); err != nil { + if err := tpActionTriggerRPC.Call(context.Background(), utils.APIerSv1SetTPActionTriggers, tpActionTriggers, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -187,7 +188,7 @@ func testTPActionTriggersSetTPActionTriggers(t *testing.T) { func testTPActionTriggersGetTPActionTriggersAfterSet(t *testing.T) { var reply *utils.TPActionTriggers - if err := tpActionTriggerRPC.Call(utils.APIerSv1GetTPActionTriggers, + if err := tpActionTriggerRPC.Call(context.Background(), utils.APIerSv1GetTPActionTriggers, &AttrGetTPActionTriggers{TPid: "TPAct", ID: "ID"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpActionTriggers.TPid, reply.TPid) { @@ -202,7 +203,7 @@ func testTPActionTriggersGetTPActionTriggersAfterSet(t *testing.T) { func testTPActionTriggersGetTPActionTriggersIds(t *testing.T) { var result []string expectedTPID := []string{"ID"} - if err := tpActionTriggerRPC.Call(utils.APIerSv1GetTPActionTriggerIds, + if err := tpActionTriggerRPC.Call(context.Background(), utils.APIerSv1GetTPActionTriggerIds, &AttrGetTPActionTriggerIds{TPid: "TPAct"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -284,7 +285,7 @@ func testTPActionTriggersUpdateTPActionTriggers(t *testing.T) { } var result string - if err := tpActionTriggerRPC.Call(utils.APIerSv1SetTPActionTriggers, tpActionTriggers, &result); err != nil { + if err := tpActionTriggerRPC.Call(context.Background(), utils.APIerSv1SetTPActionTriggers, tpActionTriggers, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -294,7 +295,7 @@ func testTPActionTriggersUpdateTPActionTriggers(t *testing.T) { func testTPActionTriggersGetTPActionTriggersAfterUpdate(t *testing.T) { var reply *utils.TPActionTriggers - if err := tpActionTriggerRPC.Call(utils.APIerSv1GetTPActionTriggers, + if err := tpActionTriggerRPC.Call(context.Background(), utils.APIerSv1GetTPActionTriggers, &AttrGetTPActionTriggers{TPid: "TPAct", ID: "ID"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpActionTriggers.TPid, reply.TPid) { @@ -309,7 +310,7 @@ func testTPActionTriggersGetTPActionTriggersAfterUpdate(t *testing.T) { func testTPActionTriggersRemoveTPActionTriggers(t *testing.T) { var resp string - if err := tpActionTriggerRPC.Call(utils.APIerSv1RemoveTPActionTriggers, + if err := tpActionTriggerRPC.Call(context.Background(), utils.APIerSv1RemoveTPActionTriggers, &AttrGetTPActionTriggers{TPid: "TPAct", ID: "ID"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -320,7 +321,7 @@ func testTPActionTriggersRemoveTPActionTriggers(t *testing.T) { func testTPActionTriggersGetTPActionTriggersAfterRemove(t *testing.T) { var reply *utils.TPActionTriggers - if err := tpActionTriggerRPC.Call(utils.APIerSv1GetTPActionTriggers, + if err := tpActionTriggerRPC.Call(context.Background(), utils.APIerSv1GetTPActionTriggers, &AttrGetTPActionTriggers{TPid: "TPAct", ID: "ID"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/apier/v1/tpattributes.go b/apier/v1/tpattributes.go index 25e3026ca..0947a94da 100644 --- a/apier/v1/tpattributes.go +++ b/apier/v1/tpattributes.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPAttributeProfile creates a new AttributeProfile within a tariff plan -func (apierSv1 *APIerSv1) SetTPAttributeProfile(attrs *utils.TPAttributeProfile, reply *string) error { +func (apierSv1 *APIerSv1) SetTPAttributeProfile(ctx *context.Context, attrs *utils.TPAttributeProfile, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -39,7 +40,7 @@ func (apierSv1 *APIerSv1) SetTPAttributeProfile(attrs *utils.TPAttributeProfile, } // GetTPAttributeProfile queries specific AttributeProfile on Tariff plan -func (apierSv1 *APIerSv1) GetTPAttributeProfile(attr *utils.TPTntID, reply *utils.TPAttributeProfile) error { +func (apierSv1 *APIerSv1) GetTPAttributeProfile(ctx *context.Context, attr *utils.TPTntID, reply *utils.TPAttributeProfile) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -63,7 +64,7 @@ type AttrGetTPAttributeProfileIds struct { } // GetTPAttributeProfileIds queries attribute identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPAttributeProfileIds(attrs *AttrGetTPAttributeProfileIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPAttributeProfileIds(ctx *context.Context, attrs *AttrGetTPAttributeProfileIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -80,7 +81,7 @@ func (apierSv1 *APIerSv1) GetTPAttributeProfileIds(attrs *AttrGetTPAttributeProf } // RemoveTPAttributeProfile removes specific AttributeProfile on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPAttributeProfile(attrs *utils.TPTntID, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPAttributeProfile(ctx *context.Context, attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpattributes_it_test.go b/apier/v1/tpattributes_it_test.go index 9ae7caf38..1ecb4f67f 100644 --- a/apier/v1/tpattributes_it_test.go +++ b/apier/v1/tpattributes_it_test.go @@ -22,14 +22,15 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "sort" "strings" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ import ( var ( tpAlsPrfCfgPath string tpAlsPrfCfg *config.CGRConfig - tpAlsPrfRPC *rpc.Client + tpAlsPrfRPC *birpc.Client tpAlsPrf *utils.TPAttributeProfile tpAlsPrfDelay int tpAlsPrfConfigDIR string //run tests for specific configuration @@ -114,7 +115,7 @@ func testTPAlsPrfRPCConn(t *testing.T) { func testTPAlsPrfGetTPAlsPrfBeforeSet(t *testing.T) { var reply *utils.TPAttributeProfile - if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfile, + if err := tpAlsPrfRPC.Call(context.Background(), utils.APIerSv1GetTPAttributeProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -142,7 +143,7 @@ func testTPAlsPrfSetTPAlsPrf(t *testing.T) { } sort.Strings(tpAlsPrf.FilterIDs) var result string - if err := tpAlsPrfRPC.Call(utils.APIerSv1SetTPAttributeProfile, tpAlsPrf, &result); err != nil { + if err := tpAlsPrfRPC.Call(context.Background(), utils.APIerSv1SetTPAttributeProfile, tpAlsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -151,7 +152,7 @@ func testTPAlsPrfSetTPAlsPrf(t *testing.T) { func testTPAlsPrfGetTPAlsPrfAfterSet(t *testing.T) { var reply *utils.TPAttributeProfile - if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfile, + if err := tpAlsPrfRPC.Call(context.Background(), utils.APIerSv1GetTPAttributeProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err != nil { t.Fatal(err) } @@ -164,7 +165,7 @@ func testTPAlsPrfGetTPAlsPrfAfterSet(t *testing.T) { func testTPAlsPrfGetTPAlsPrfIDs(t *testing.T) { var result []string expectedTPID := []string{"cgrates.org:Attr1"} - if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfileIds, + if err := tpAlsPrfRPC.Call(context.Background(), utils.APIerSv1GetTPAttributeProfileIds, &AttrGetTPAttributeProfileIds{TPid: "TP1"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -186,7 +187,7 @@ func testTPAlsPrfUpdateTPAlsPrf(t *testing.T) { }, } var result string - if err := tpAlsPrfRPC.Call(utils.APIerSv1SetTPAttributeProfile, tpAlsPrf, &result); err != nil { + if err := tpAlsPrfRPC.Call(context.Background(), utils.APIerSv1SetTPAttributeProfile, tpAlsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -223,7 +224,7 @@ func testTPAlsPrfGetTPAlsPrfAfterUpdate(t *testing.T) { sort.Slice(revTPAlsPrf.Attributes, func(i, j int) bool { return strings.Compare(revTPAlsPrf.Attributes[i].Path, revTPAlsPrf.Attributes[j].Path) == -1 }) - if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfile, + if err := tpAlsPrfRPC.Call(context.Background(), utils.APIerSv1GetTPAttributeProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err != nil { t.Fatal(err) } @@ -238,7 +239,7 @@ func testTPAlsPrfGetTPAlsPrfAfterUpdate(t *testing.T) { func testTPAlsPrfRemTPAlsPrf(t *testing.T) { var resp string - if err := tpAlsPrfRPC.Call(utils.APIerSv1RemoveTPAttributeProfile, + if err := tpAlsPrfRPC.Call(context.Background(), utils.APIerSv1RemoveTPAttributeProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &resp); err != nil { t.Error(err) @@ -249,7 +250,7 @@ func testTPAlsPrfRemTPAlsPrf(t *testing.T) { func testTPAlsPrfGetTPAlsPrfAfterRemove(t *testing.T) { var reply *utils.TPAttributeProfile - if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfile, + if err := tpAlsPrfRPC.Call(context.Background(), utils.APIerSv1GetTPAttributeProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) diff --git a/apier/v1/tpchargers.go b/apier/v1/tpchargers.go index 073b4e8e1..eaab4485b 100644 --- a/apier/v1/tpchargers.go +++ b/apier/v1/tpchargers.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPCharger creates a new ChargerProfile within a tariff plan -func (apierSv1 *APIerSv1) SetTPCharger(attr *utils.TPChargerProfile, reply *string) error { +func (apierSv1 *APIerSv1) SetTPCharger(ctx *context.Context, attr *utils.TPChargerProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -38,7 +39,7 @@ func (apierSv1 *APIerSv1) SetTPCharger(attr *utils.TPChargerProfile, reply *stri } // GetTPCharger queries specific ChargerProfile on Tariff plan -func (apierSv1 *APIerSv1) GetTPCharger(attr *utils.TPTntID, reply *utils.TPChargerProfile) error { +func (apierSv1 *APIerSv1) GetTPCharger(ctx *context.Context, attr *utils.TPTntID, reply *utils.TPChargerProfile) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -62,7 +63,7 @@ type AttrGetTPChargerIds struct { } // GetTPChargerIDs queries Charger identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPChargerIDs(attrs *AttrGetTPChargerIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPChargerIDs(ctx *context.Context, attrs *AttrGetTPChargerIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -79,7 +80,7 @@ func (apierSv1 *APIerSv1) GetTPChargerIDs(attrs *AttrGetTPChargerIds, reply *[]s } // RemoveTPCharger removes specific ChargerProfile on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPCharger(attrs *utils.TPTntID, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPCharger(ctx *context.Context, attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpchargers_it_test.go b/apier/v1/tpchargers_it_test.go index d43c2dd93..8e6ff29fe 100644 --- a/apier/v1/tpchargers_it_test.go +++ b/apier/v1/tpchargers_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "sort" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( tpChrgsCfgPath string tpChrgsCfg *config.CGRConfig - tpChrgsRPC *rpc.Client + tpChrgsRPC *birpc.Client tpChrgs *utils.TPChargerProfile tpChrgsDelay int tpChrgsConfigDIR string //run tests for specific configuration @@ -114,7 +115,7 @@ func testTPChrgsRPCConn(t *testing.T) { func testTPChrgsGetTPChrgsBeforeSet(t *testing.T) { var reply *utils.TPChargerProfile - if err := tpChrgsRPC.Call(utils.APIerSv1GetTPCharger, + if err := tpChrgsRPC.Call(context.Background(), utils.APIerSv1GetTPCharger, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -138,7 +139,7 @@ func testTPChrgsSetTPChrgs(t *testing.T) { sort.Strings(tpChrgs.FilterIDs) sort.Strings(tpChrgs.AttributeIDs) var result string - if err := tpChrgsRPC.Call(utils.APIerSv1SetTPCharger, tpChrgs, &result); err != nil { + if err := tpChrgsRPC.Call(context.Background(), utils.APIerSv1SetTPCharger, tpChrgs, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -147,7 +148,7 @@ func testTPChrgsSetTPChrgs(t *testing.T) { func testTPChrgsGetTPChrgsAfterSet(t *testing.T) { var reply *utils.TPChargerProfile - if err := tpChrgsRPC.Call(utils.APIerSv1GetTPCharger, + if err := tpChrgsRPC.Call(context.Background(), utils.APIerSv1GetTPCharger, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err != nil { t.Fatal(err) } @@ -161,7 +162,7 @@ func testTPChrgsGetTPChrgsAfterSet(t *testing.T) { func testTPChrgsGetTPChrgsIDs(t *testing.T) { var result []string expectedTPID := []string{"cgrates.org:Chrgs"} - if err := tpChrgsRPC.Call(utils.APIerSv1GetTPChargerIDs, + if err := tpChrgsRPC.Call(context.Background(), utils.APIerSv1GetTPChargerIDs, &AttrGetTPAttributeProfileIds{TPid: "TP1"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -172,7 +173,7 @@ func testTPChrgsGetTPChrgsIDs(t *testing.T) { func testTPChrgsUpdateTPChrgs(t *testing.T) { tpChrgs.AttributeIDs = []string{"Attr1", "Attr2", "Attr3"} var result string - if err := tpChrgsRPC.Call(utils.APIerSv1SetTPCharger, tpChrgs, &result); err != nil { + if err := tpChrgsRPC.Call(context.Background(), utils.APIerSv1SetTPCharger, tpChrgs, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -181,7 +182,7 @@ func testTPChrgsUpdateTPChrgs(t *testing.T) { func testTPChrgsGetTPChrgsAfterUpdate(t *testing.T) { var reply *utils.TPChargerProfile - if err := tpChrgsRPC.Call(utils.APIerSv1GetTPCharger, + if err := tpChrgsRPC.Call(context.Background(), utils.APIerSv1GetTPCharger, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err != nil { t.Fatal(err) } @@ -194,7 +195,7 @@ func testTPChrgsGetTPChrgsAfterUpdate(t *testing.T) { func testTPChrgsRemTPChrgs(t *testing.T) { var resp string - if err := tpChrgsRPC.Call(utils.APIerSv1RemoveTPCharger, + if err := tpChrgsRPC.Call(context.Background(), utils.APIerSv1RemoveTPCharger, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &resp); err != nil { t.Error(err) @@ -205,7 +206,7 @@ func testTPChrgsRemTPChrgs(t *testing.T) { func testTPChrgsGetTPChrgsAfterRemove(t *testing.T) { var reply *utils.TPChargerProfile - if err := tpChrgsRPC.Call(utils.APIerSv1GetTPCharger, + if err := tpChrgsRPC.Call(context.Background(), utils.APIerSv1GetTPCharger, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) diff --git a/apier/v1/tpdestinationrates.go b/apier/v1/tpdestinationrates.go index c76ba21a3..eca76013e 100644 --- a/apier/v1/tpdestinationrates.go +++ b/apier/v1/tpdestinationrates.go @@ -21,11 +21,12 @@ package v1 // This file deals with tp_destination_rates management over APIs import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPDestinationRate creates a new DestinationRate profile within a tariff plan -func (apierSv1 *APIerSv1) SetTPDestinationRate(attrs *utils.TPDestinationRate, reply *string) error { +func (apierSv1 *APIerSv1) SetTPDestinationRate(ctx *context.Context, attrs *utils.TPDestinationRate, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.DestinationRates}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -43,7 +44,7 @@ type AttrGetTPDestinationRate struct { } // GetTPDestinationRate queries specific DestinationRate profile on tariff plan -func (apierSv1 *APIerSv1) GetTPDestinationRate(attrs *AttrGetTPDestinationRate, reply *utils.TPDestinationRate) error { +func (apierSv1 *APIerSv1) GetTPDestinationRate(ctx *context.Context, attrs *AttrGetTPDestinationRate, reply *utils.TPDestinationRate) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -64,7 +65,7 @@ type AttrTPDestinationRateIds struct { } // GetTPDestinationRateIds queries DestinationRate identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPDestinationRateIds(attrs *AttrGetTPRateIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPDestinationRateIds(ctx *context.Context, attrs *AttrGetTPRateIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -81,7 +82,7 @@ func (apierSv1 *APIerSv1) GetTPDestinationRateIds(attrs *AttrGetTPRateIds, reply } // RemoveTPDestinationRate removes specific DestinationRate on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPDestinationRate(attrs *AttrGetTPDestinationRate, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPDestinationRate(ctx *context.Context, attrs *AttrGetTPDestinationRate, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpdestinationrates_it_test.go b/apier/v1/tpdestinationrates_it_test.go index 3ac692e67..6e4200f9a 100644 --- a/apier/v1/tpdestinationrates_it_test.go +++ b/apier/v1/tpdestinationrates_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpDstRateCfgPath string tpDstRateCfg *config.CGRConfig - tpDstRateRPC *rpc.Client + tpDstRateRPC *birpc.Client tpDstRate *utils.TPDestinationRate tpDstRateDelay int tpDstRateConfigDIR string //run tests for specific configuration @@ -112,7 +113,7 @@ func testTPDstRateRpcConn(t *testing.T) { func testTPDstRateGetTPDstRateBeforeSet(t *testing.T) { var reply *utils.TPDestinationRate - if err := tpDstRateRPC.Call(utils.APIerSv1GetTPDestinationRate, + if err := tpDstRateRPC.Call(context.Background(), utils.APIerSv1GetTPDestinationRate, &AttrGetTPDestinationRate{TPid: "TP1", ID: "DR_FREESWITCH_USERS"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -133,7 +134,7 @@ func testTPDstRateSetTPDstRate(t *testing.T) { }, } var result string - if err := tpDstRateRPC.Call(utils.APIerSv1SetTPDestinationRate, tpDstRate, &result); err != nil { + if err := tpDstRateRPC.Call(context.Background(), utils.APIerSv1SetTPDestinationRate, tpDstRate, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -142,7 +143,7 @@ func testTPDstRateSetTPDstRate(t *testing.T) { func testTPDstRateGetTPDstRateAfterSet(t *testing.T) { var reply *utils.TPDestinationRate - if err := tpDstRateRPC.Call(utils.APIerSv1GetTPDestinationRate, + if err := tpDstRateRPC.Call(context.Background(), utils.APIerSv1GetTPDestinationRate, &AttrGetTPDestinationRate{TPid: "TP1", ID: "DR_FREESWITCH_USERS"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpDstRate, reply) { @@ -153,7 +154,7 @@ func testTPDstRateGetTPDstRateAfterSet(t *testing.T) { func testTPDstRateGetTPDstRateIds(t *testing.T) { var result []string expectedTPID := []string{"DR_FREESWITCH_USERS"} - if err := tpDstRateRPC.Call(utils.APIerSv1GetTPDestinationRateIds, + if err := tpDstRateRPC.Call(context.Background(), utils.APIerSv1GetTPDestinationRateIds, &AttrTPDestinationRateIds{TPid: "TP1"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -168,7 +169,7 @@ func testTPDstRateUpdateTPDstRate(t *testing.T) { func testTPDstRateGetTPDstRateAfterUpdate(t *testing.T) { var reply *utils.TPDestinationRate - if err := tpDstRateRPC.Call(utils.APIerSv1GetTPDestinationRate, + if err := tpDstRateRPC.Call(context.Background(), utils.APIerSv1GetTPDestinationRate, &AttrGetTPDestinationRate{TPid: "TP1", ID: "DR_FREESWITCH_USERS"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpDstRate, reply) { @@ -178,7 +179,7 @@ func testTPDstRateGetTPDstRateAfterUpdate(t *testing.T) { func testTPDstRateRemTPDstRate(t *testing.T) { var resp string - if err := tpDstRateRPC.Call(utils.APIerSv1RemoveTPDestinationRate, + if err := tpDstRateRPC.Call(context.Background(), utils.APIerSv1RemoveTPDestinationRate, &AttrGetTPDestinationRate{TPid: "TP1", ID: "DR_FREESWITCH_USERS"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -189,7 +190,7 @@ func testTPDstRateRemTPDstRate(t *testing.T) { func testTPDstRateGetTPDstRateAfterRemove(t *testing.T) { var reply *utils.TPDestinationRate - if err := tpDstRateRPC.Call(utils.APIerSv1GetTPDestinationRate, + if err := tpDstRateRPC.Call(context.Background(), utils.APIerSv1GetTPDestinationRate, &AttrGetTPDestinationRate{TPid: "TP1", ID: "DR_FREESWITCH_USERS"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) diff --git a/apier/v1/tpdestinations.go b/apier/v1/tpdestinations.go index 5cbaee605..e83233b5b 100644 --- a/apier/v1/tpdestinations.go +++ b/apier/v1/tpdestinations.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPDestination creates a new destination within a tariff plan -func (apierSv1 *APIerSv1) SetTPDestination(attrs *utils.TPDestination, reply *string) error { +func (apierSv1 *APIerSv1) SetTPDestination(ctx *context.Context, attrs *utils.TPDestination, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.Prefixes}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -40,7 +41,7 @@ type AttrGetTPDestination struct { } // GetTPDestination queries a specific destination -func (apierSv1 *APIerSv1) GetTPDestination(attrs *AttrGetTPDestination, reply *utils.TPDestination) error { +func (apierSv1 *APIerSv1) GetTPDestination(ctx *context.Context, attrs *AttrGetTPDestination, reply *utils.TPDestination) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -63,7 +64,7 @@ type AttrGetTPDestinationIds struct { } // GetTPDestinationIDs queries destination identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPDestinationIDs(attrs *AttrGetTPDestinationIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPDestinationIDs(ctx *context.Context, attrs *AttrGetTPDestinationIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -80,7 +81,7 @@ func (apierSv1 *APIerSv1) GetTPDestinationIDs(attrs *AttrGetTPDestinationIds, re } // RemoveTPDestination removes specific Destination on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPDestination(attrs *AttrGetTPDestination, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPDestination(ctx *context.Context, attrs *AttrGetTPDestination, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpdestinations_it_test.go b/apier/v1/tpdestinations_it_test.go index 4744a46d6..2d1e8c192 100644 --- a/apier/v1/tpdestinations_it_test.go +++ b/apier/v1/tpdestinations_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpDestinationCfgPath string tpDestinationCfg *config.CGRConfig - tpDestinationRPC *rpc.Client + tpDestinationRPC *birpc.Client tpDestination *utils.TPDestination tpDestinationDelay int tpDestinationConfigDIR string //run tests for specific configuration @@ -117,7 +118,7 @@ func testTPDestinationsRpcConn(t *testing.T) { func testTPDestinationsGetTPDestinationBeforeSet(t *testing.T) { var reply *utils.TPDestination - if err := tpDestinationRPC.Call(utils.APIerSv1GetTPDestination, + if err := tpDestinationRPC.Call(context.Background(), utils.APIerSv1GetTPDestination, &AttrGetTPDestination{TPid: "TPD", ID: "GERMANY"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -131,7 +132,7 @@ func testTPDestinationsSetTPDestination(t *testing.T) { Prefixes: []string{"+49", "+4915"}, } var result string - if err := tpDestinationRPC.Call(utils.APIerSv1SetTPDestination, tpDestination, &result); err != nil { + if err := tpDestinationRPC.Call(context.Background(), utils.APIerSv1SetTPDestination, tpDestination, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -140,7 +141,7 @@ func testTPDestinationsSetTPDestination(t *testing.T) { func testTPDestinationsGetTPDestinationAfterSet(t *testing.T) { var reply *utils.TPDestination - if err := tpDestinationRPC.Call(utils.APIerSv1GetTPDestination, + if err := tpDestinationRPC.Call(context.Background(), utils.APIerSv1GetTPDestination, &AttrGetTPDestination{TPid: "TPD", ID: "GERMANY"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpDestination.TPid, reply.TPid) { @@ -156,7 +157,7 @@ func testTPDestinationsGetTPDestinationAfterSet(t *testing.T) { func testTPDestinationsGetTPDestinationIds(t *testing.T) { var result []string expectedTPID := []string{"GERMANY"} - if err := tpDestinationRPC.Call(utils.APIerSv1GetTPDestinationIDs, + if err := tpDestinationRPC.Call(context.Background(), utils.APIerSv1GetTPDestinationIDs, &AttrGetTPDestinationIds{TPid: "TPD"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -168,7 +169,7 @@ func testTPDestinationsGetTPDestinationIds(t *testing.T) { func testTPDestinationsUpdateTPDestination(t *testing.T) { tpDestination.Prefixes = []string{"+49", "+4915", "+4916"} var result string - if err := tpDestinationRPC.Call(utils.APIerSv1SetTPDestination, tpDestination, &result); err != nil { + if err := tpDestinationRPC.Call(context.Background(), utils.APIerSv1SetTPDestination, tpDestination, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -178,7 +179,7 @@ func testTPDestinationsUpdateTPDestination(t *testing.T) { func testTPDestinationsGetTPDestinationAfterUpdate(t *testing.T) { var reply *utils.TPDestination - if err := tpDestinationRPC.Call(utils.APIerSv1GetTPDestination, + if err := tpDestinationRPC.Call(context.Background(), utils.APIerSv1GetTPDestination, &AttrGetTPDestination{TPid: "TPD", ID: "GERMANY"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpDestination.TPid, reply.TPid) { @@ -193,7 +194,7 @@ func testTPDestinationsGetTPDestinationAfterUpdate(t *testing.T) { func testTPDestinationsRemoveTPDestination(t *testing.T) { var resp string - if err := tpDestinationRPC.Call(utils.APIerSv1RemoveTPDestination, + if err := tpDestinationRPC.Call(context.Background(), utils.APIerSv1RemoveTPDestination, &AttrGetTPDestination{TPid: "TPD", ID: "GERMANY"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -204,7 +205,7 @@ func testTPDestinationsRemoveTPDestination(t *testing.T) { func testTPDestinationsGetTPDestinationAfterRemove(t *testing.T) { var reply *utils.TPDestination - if err := tpDestinationRPC.Call(utils.APIerSv1GetTPDestination, + if err := tpDestinationRPC.Call(context.Background(), utils.APIerSv1GetTPDestination, &AttrGetTPDestination{TPid: "TPD", ID: "GERMANY"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/apier/v1/tpdispatchers.go b/apier/v1/tpdispatchers.go index 9ece9c173..8764a07ab 100644 --- a/apier/v1/tpdispatchers.go +++ b/apier/v1/tpdispatchers.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPDispatcherProfile creates a new DispatcherProfile within a tariff plan -func (apierSv1 *APIerSv1) SetTPDispatcherProfile(attr *utils.TPDispatcherProfile, reply *string) error { +func (apierSv1 *APIerSv1) SetTPDispatcherProfile(ctx *context.Context, attr *utils.TPDispatcherProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -38,7 +39,7 @@ func (apierSv1 *APIerSv1) SetTPDispatcherProfile(attr *utils.TPDispatcherProfile } // GetTPDispatcherProfile queries specific DispatcherProfile on Tariff plan -func (apierSv1 *APIerSv1) GetTPDispatcherProfile(attr *utils.TPTntID, reply *utils.TPDispatcherProfile) error { +func (apierSv1 *APIerSv1) GetTPDispatcherProfile(ctx *context.Context, attr *utils.TPTntID, reply *utils.TPDispatcherProfile) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -63,7 +64,7 @@ type AttrGetTPDispatcherIds struct { } // GetTPDispatcherProfileIDs queries dispatcher identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPDispatcherProfileIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPDispatcherProfileIDs(ctx *context.Context, attrs *AttrGetTPDispatcherIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -80,7 +81,7 @@ func (apierSv1 *APIerSv1) GetTPDispatcherProfileIDs(attrs *AttrGetTPDispatcherId } // RemoveTPDispatcherProfile removes specific DispatcherProfile on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPDispatcherProfile(attrs *utils.TPTntID, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPDispatcherProfile(ctx *context.Context, attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -96,7 +97,7 @@ func (apierSv1 *APIerSv1) RemoveTPDispatcherProfile(attrs *utils.TPTntID, reply } // SetTPDispatcherHost creates a new DispatcherHost within a tariff plan -func (apierSv1 *APIerSv1) SetTPDispatcherHost(attr *utils.TPDispatcherHost, reply *string) error { +func (apierSv1 *APIerSv1) SetTPDispatcherHost(ctx *context.Context, attr *utils.TPDispatcherHost, reply *string) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -111,7 +112,7 @@ func (apierSv1 *APIerSv1) SetTPDispatcherHost(attr *utils.TPDispatcherHost, repl } // GetTPDispatcherHost queries specific DispatcherHosts on Tariff plan -func (apierSv1 *APIerSv1) GetTPDispatcherHost(attr *utils.TPTntID, reply *utils.TPDispatcherHost) error { +func (apierSv1 *APIerSv1) GetTPDispatcherHost(ctx *context.Context, attr *utils.TPTntID, reply *utils.TPDispatcherHost) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -131,7 +132,7 @@ func (apierSv1 *APIerSv1) GetTPDispatcherHost(attr *utils.TPTntID, reply *utils. } // GetTPDispatcherHostIDs queries dispatcher host identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPDispatcherHostIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPDispatcherHostIDs(ctx *context.Context, attrs *AttrGetTPDispatcherIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -148,7 +149,7 @@ func (apierSv1 *APIerSv1) GetTPDispatcherHostIDs(attrs *AttrGetTPDispatcherIds, } // RemoveTPDispatcherHost removes specific DispatcherHost on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPDispatcherHost(attrs *utils.TPTntID, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPDispatcherHost(ctx *context.Context, attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpdispatchers_it_test.go b/apier/v1/tpdispatchers_it_test.go index b3ea5ff82..2e1c54d21 100644 --- a/apier/v1/tpdispatchers_it_test.go +++ b/apier/v1/tpdispatchers_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpDispatcherCfgPath string tpDispatcherCfg *config.CGRConfig - tpDispatcherRPC *rpc.Client + tpDispatcherRPC *birpc.Client tpDispatcher *utils.TPDispatcherProfile tpDispatcherDelay int tpDispatcherConfigDIR string //run tests for specific configuration @@ -113,7 +114,7 @@ func testTPDispatcherRpcConn(t *testing.T) { func testTPDispatcherGetTPDispatcherBeforeSet(t *testing.T) { var reply *utils.TPDispatcherProfile - if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfile, + if err := tpDispatcherRPC.Call(context.Background(), utils.APIerSv1GetTPDispatcherProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -136,7 +137,7 @@ func testTPDispatcherSetTPDispatcher(t *testing.T) { } var result string - if err := tpDispatcherRPC.Call(utils.APIerSv1SetTPDispatcherProfile, tpDispatcher, &result); err != nil { + if err := tpDispatcherRPC.Call(context.Background(), utils.APIerSv1SetTPDispatcherProfile, tpDispatcher, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -145,7 +146,7 @@ func testTPDispatcherSetTPDispatcher(t *testing.T) { func testTPDispatcherGetTPDispatcherAfterSet(t *testing.T) { var reply *utils.TPDispatcherProfile - if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfile, + if err := tpDispatcherRPC.Call(context.Background(), utils.APIerSv1GetTPDispatcherProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpDispatcher, reply) { @@ -156,7 +157,7 @@ func testTPDispatcherGetTPDispatcherAfterSet(t *testing.T) { func testTPDispatcherGetTPDispatcherIds(t *testing.T) { var result []string expectedTPID := []string{"cgrates.org:Dsp1"} - if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfileIDs, + if err := tpDispatcherRPC.Call(context.Background(), utils.APIerSv1GetTPDispatcherProfileIDs, &AttrGetTPDispatcherIds{TPid: "TP1"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -166,7 +167,7 @@ func testTPDispatcherGetTPDispatcherIds(t *testing.T) { func testTPDispatcherUpdateTPDispatcher(t *testing.T) { var result string - if err := tpDispatcherRPC.Call(utils.APIerSv1SetTPDispatcherProfile, tpDispatcher, &result); err != nil { + if err := tpDispatcherRPC.Call(context.Background(), utils.APIerSv1SetTPDispatcherProfile, tpDispatcher, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -187,7 +188,7 @@ func testTPDispatcherGetTPDispatcherAfterUpdate(t *testing.T) { Strategy: utils.MetaFirst, Weight: 10, } - if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfile, + if err := tpDispatcherRPC.Call(context.Background(), utils.APIerSv1GetTPDispatcherProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpDispatcher, reply) && !reflect.DeepEqual(revHosts, reply) { @@ -197,7 +198,7 @@ func testTPDispatcherGetTPDispatcherAfterUpdate(t *testing.T) { func testTPDispatcherRemTPDispatcher(t *testing.T) { var resp string - if err := tpDispatcherRPC.Call(utils.APIerSv1RemoveTPDispatcherProfile, + if err := tpDispatcherRPC.Call(context.Background(), utils.APIerSv1RemoveTPDispatcherProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -207,7 +208,7 @@ func testTPDispatcherRemTPDispatcher(t *testing.T) { func testTPDispatcherGetTPDispatcherAfterRemove(t *testing.T) { var reply *utils.TPDispatcherProfile - if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfile, + if err := tpDispatcherRPC.Call(context.Background(), utils.APIerSv1GetTPDispatcherProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) diff --git a/apier/v1/tpfilters.go b/apier/v1/tpfilters.go index e589f4a78..4256e00fc 100644 --- a/apier/v1/tpfilters.go +++ b/apier/v1/tpfilters.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPFilterProfile creates a new FilterProfile within a tariff plan -func (apierSv1 *APIerSv1) SetTPFilterProfile(attrs *utils.TPFilterProfile, reply *string) error { +func (apierSv1 *APIerSv1) SetTPFilterProfile(ctx *context.Context, attrs *utils.TPFilterProfile, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -38,7 +39,7 @@ func (apierSv1 *APIerSv1) SetTPFilterProfile(attrs *utils.TPFilterProfile, reply } // GetTPFilterProfile queries specific FilterProfile on tariff plan -func (apierSv1 *APIerSv1) GetTPFilterProfile(attr *utils.TPTntID, reply *utils.TPFilterProfile) error { +func (apierSv1 *APIerSv1) GetTPFilterProfile(ctx *context.Context, attr *utils.TPTntID, reply *utils.TPFilterProfile) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -62,7 +63,7 @@ type AttrGetTPFilterProfileIds struct { } // GetTPFilterProfileIds queries FilterProfile identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPFilterProfileIds(attrs *AttrGetTPFilterProfileIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPFilterProfileIds(ctx *context.Context, attrs *AttrGetTPFilterProfileIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -79,7 +80,7 @@ func (apierSv1 *APIerSv1) GetTPFilterProfileIds(attrs *AttrGetTPFilterProfileIds } // RemoveTPFilterProfile removes specific FilterProfile on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPFilterProfile(attrs *utils.TPTntID, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPFilterProfile(ctx *context.Context, attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpfilters_it_test.go b/apier/v1/tpfilters_it_test.go index d7e619e87..212c2133d 100644 --- a/apier/v1/tpfilters_it_test.go +++ b/apier/v1/tpfilters_it_test.go @@ -22,14 +22,15 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "sort" "strings" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ import ( var ( tpFilterCfgPath string tpFilterCfg *config.CGRConfig - tpFilterRPC *rpc.Client + tpFilterRPC *birpc.Client tpFilter *utils.TPFilterProfile tpFilterDelay int tpFilterConfigDIR string //run tests for specific configuration @@ -115,7 +116,7 @@ func testTPFilterRpcConn(t *testing.T) { func ttestTPFilterGetTPFilterBeforeSet(t *testing.T) { var reply *utils.TPFilterProfile - if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfile, + if err := tpFilterRPC.Call(context.Background(), utils.APIerSv1GetTPFilterProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -142,7 +143,7 @@ func testTPFilterSetTPFilter(t *testing.T) { sort.Strings(tpFilter.Filters[0].Values) var result string - if err := tpFilterRPC.Call(utils.APIerSv1SetTPFilterProfile, tpFilter, &result); err != nil { + if err := tpFilterRPC.Call(context.Background(), utils.APIerSv1SetTPFilterProfile, tpFilter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -151,7 +152,7 @@ func testTPFilterSetTPFilter(t *testing.T) { func testTPFilterGetTPFilterAfterSet(t *testing.T) { var reply *utils.TPFilterProfile - if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfile, + if err := tpFilterRPC.Call(context.Background(), utils.APIerSv1GetTPFilterProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"}, &reply); err != nil { t.Fatal(err) } @@ -164,7 +165,7 @@ func testTPFilterGetTPFilterAfterSet(t *testing.T) { func testTPFilterGetFilterIds(t *testing.T) { var result []string expectedTPID := []string{"cgrates.org:Filter"} - if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfileIds, + if err := tpFilterRPC.Call(context.Background(), utils.APIerSv1GetTPFilterProfileIds, &AttrGetTPFilterProfileIds{TPid: "TP1"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -191,7 +192,7 @@ func testTPFilterUpdateTPFilter(t *testing.T) { return strings.Compare(tpFilter.Filters[i].Element, tpFilter.Filters[j].Element) == -1 }) var result string - if err := tpFilterRPC.Call(utils.APIerSv1SetTPFilterProfile, tpFilter, &result); err != nil { + if err := tpFilterRPC.Call(context.Background(), utils.APIerSv1SetTPFilterProfile, tpFilter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -200,7 +201,7 @@ func testTPFilterUpdateTPFilter(t *testing.T) { func testTPFilterGetTPFilterAfterUpdate(t *testing.T) { var reply *utils.TPFilterProfile - if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfile, + if err := tpFilterRPC.Call(context.Background(), utils.APIerSv1GetTPFilterProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"}, &reply); err != nil { t.Fatal(err) } @@ -216,7 +217,7 @@ func testTPFilterGetTPFilterAfterUpdate(t *testing.T) { func testTPFilterRemTPFilter(t *testing.T) { var resp string - if err := tpFilterRPC.Call(utils.APIerSv1RemoveTPFilterProfile, + if err := tpFilterRPC.Call(context.Background(), utils.APIerSv1RemoveTPFilterProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -226,7 +227,7 @@ func testTPFilterRemTPFilter(t *testing.T) { func testTPFilterGetTPFilterAfterRemove(t *testing.T) { var reply *utils.TPFilterProfile - if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfile, + if err := tpFilterRPC.Call(context.Background(), utils.APIerSv1GetTPFilterProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) diff --git a/apier/v1/tprates.go b/apier/v1/tprates.go index 7c8ea93d0..5d02951b1 100644 --- a/apier/v1/tprates.go +++ b/apier/v1/tprates.go @@ -21,11 +21,12 @@ package v1 // This file deals with tp_rates management over APIs import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPRate creates a new rate within a tariff plan -func (apierSv1 *APIerSv1) SetTPRate(attrs *utils.TPRateRALs, reply *string) error { +func (apierSv1 *APIerSv1) SetTPRate(ctx *context.Context, attrs *utils.TPRateRALs, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.RateSlots}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -42,7 +43,7 @@ type AttrGetTPRate struct { } // GetTPRate queries specific Rate on tariff plan -func (apierSv1 *APIerSv1) GetTPRate(attrs *AttrGetTPRate, reply *utils.TPRateRALs) error { +func (apierSv1 *APIerSv1) GetTPRate(ctx *context.Context, attrs *AttrGetTPRate, reply *utils.TPRateRALs) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -63,7 +64,7 @@ type AttrGetTPRateIds struct { } // GetTPRateIds queries rate identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPRateIds(attrs *AttrGetTPRateIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPRateIds(ctx *context.Context, attrs *AttrGetTPRateIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -80,7 +81,7 @@ func (apierSv1 *APIerSv1) GetTPRateIds(attrs *AttrGetTPRateIds, reply *[]string) } // RemoveTPRate removes specific Rate on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPRate(attrs *AttrGetTPRate, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPRate(ctx *context.Context, attrs *AttrGetTPRate, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tprates_it_test.go b/apier/v1/tprates_it_test.go index 1ed88084c..3fc8380ed 100644 --- a/apier/v1/tprates_it_test.go +++ b/apier/v1/tprates_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpRateCfgPath string tpRateCfg *config.CGRConfig - tpRateRPC *rpc.Client + tpRateRPC *birpc.Client tpRate *utils.TPRateRALs tpRateDelay int tpRateConfigDIR string //run tests for specific configuration @@ -117,7 +118,7 @@ func testTPRatesRpcConn(t *testing.T) { func testTPRatesGetTPRateforeSet(t *testing.T) { var reply *utils.TPRateRALs - if err := tpRateRPC.Call(utils.APIerSv1GetTPRate, + if err := tpRateRPC.Call(context.Background(), utils.APIerSv1GetTPRate, &AttrGetTPRate{TPid: "TPidTpRate", ID: "RT_FS_USERS"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -145,7 +146,7 @@ func testTPRatesSetTPRate(t *testing.T) { }, } var result string - if err := tpRateRPC.Call(utils.APIerSv1SetTPRate, tpRate, &result); err != nil { + if err := tpRateRPC.Call(context.Background(), utils.APIerSv1SetTPRate, tpRate, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -154,7 +155,7 @@ func testTPRatesSetTPRate(t *testing.T) { func testTPRatesGetTPRateAfterSet(t *testing.T) { var reply *utils.TPRateRALs - if err := tpRateRPC.Call(utils.APIerSv1GetTPRate, &AttrGetTPRate{TPid: "TPidTpRate", ID: tpRate.ID}, &reply); err != nil { + if err := tpRateRPC.Call(context.Background(), utils.APIerSv1GetTPRate, &AttrGetTPRate{TPid: "TPidTpRate", ID: tpRate.ID}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpRate, reply) { t.Errorf("Expecting : %+v, received: %+v", tpRate, reply) @@ -164,7 +165,7 @@ func testTPRatesGetTPRateAfterSet(t *testing.T) { func testTPRatesGetTPRateIds(t *testing.T) { var result []string expectedTPID := []string{"RT_FS_USERS"} - if err := tpRateRPC.Call(utils.APIerSv1GetTPRateIds, &AttrGetTPRateIds{TPid: "TPidTpRate"}, &result); err != nil { + if err := tpRateRPC.Call(context.Background(), utils.APIerSv1GetTPRateIds, &AttrGetTPRateIds{TPid: "TPidTpRate"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result) @@ -196,7 +197,7 @@ func testTPRatesUpdateTPRate(t *testing.T) { GroupIntervalStart: "3s", }, } - if err := tpRateRPC.Call(utils.APIerSv1SetTPRate, tpRate, &result); err != nil { + if err := tpRateRPC.Call(context.Background(), utils.APIerSv1SetTPRate, tpRate, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -205,7 +206,7 @@ func testTPRatesUpdateTPRate(t *testing.T) { func testTPRatesGetTPRateAfterUpdate(t *testing.T) { var reply *utils.TPRateRALs - if err := tpRateRPC.Call(utils.APIerSv1GetTPRate, + if err := tpRateRPC.Call(context.Background(), utils.APIerSv1GetTPRate, &AttrGetTPRate{TPid: "TPidTpRate", ID: tpRate.ID}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpRate, reply) { @@ -216,7 +217,7 @@ func testTPRatesGetTPRateAfterUpdate(t *testing.T) { func testTPRatesRemoveTPRate(t *testing.T) { var resp string - if err := tpRateRPC.Call(utils.APIerSv1RemoveTPRate, + if err := tpRateRPC.Call(context.Background(), utils.APIerSv1RemoveTPRate, &AttrGetTPRate{TPid: "TPidTpRate", ID: "RT_FS_USERS"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -226,7 +227,7 @@ func testTPRatesRemoveTPRate(t *testing.T) { func testTPRatesGetTPRateAfterRemove(t *testing.T) { var reply *utils.TPRateRALs - if err := tpRateRPC.Call(utils.APIerSv1GetTPRate, + if err := tpRateRPC.Call(context.Background(), utils.APIerSv1GetTPRate, &AttrGetTPRate{TPid: "TPidTpRate", ID: "RT_FS_USERS"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/apier/v1/tpratingplans.go b/apier/v1/tpratingplans.go index d27c41075..550ac50fc 100644 --- a/apier/v1/tpratingplans.go +++ b/apier/v1/tpratingplans.go @@ -21,11 +21,12 @@ package v1 // This file deals with tp_destrates_timing management over APIs import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPRatingPlan creates a new DestinationRateTiming profile within a tariff plan -func (apierSv1 *APIerSv1) SetTPRatingPlan(attrs *utils.TPRatingPlan, reply *string) error { +func (apierSv1 *APIerSv1) SetTPRatingPlan(ctx *context.Context, attrs *utils.TPRatingPlan, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.RatingPlanBindings}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -43,7 +44,7 @@ type AttrGetTPRatingPlan struct { } // GetTPRatingPlan queries specific RatingPlan profile on tariff plan -func (apierSv1 *APIerSv1) GetTPRatingPlan(attrs *AttrGetTPRatingPlan, reply *utils.TPRatingPlan) error { +func (apierSv1 *APIerSv1) GetTPRatingPlan(ctx *context.Context, attrs *AttrGetTPRatingPlan, reply *utils.TPRatingPlan) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -64,7 +65,7 @@ type AttrGetTPRatingPlanIds struct { } // GetTPRatingPlanIds queries RatingPlan identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPRatingPlanIds(attrs *AttrGetTPRatingPlanIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPRatingPlanIds(ctx *context.Context, attrs *AttrGetTPRatingPlanIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -81,7 +82,7 @@ func (apierSv1 *APIerSv1) GetTPRatingPlanIds(attrs *AttrGetTPRatingPlanIds, repl } // RemoveTPRatingPlan removes specific RatingPlan on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPRatingPlan(attrs *AttrGetTPRatingPlan, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPRatingPlan(ctx *context.Context, attrs *AttrGetTPRatingPlan, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpratingplans_it_test.go b/apier/v1/tpratingplans_it_test.go index 73b0c7d89..35243b592 100644 --- a/apier/v1/tpratingplans_it_test.go +++ b/apier/v1/tpratingplans_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpRatingPlanCfgPath string tpRatingPlanCfg *config.CGRConfig - tpRatingPlanRPC *rpc.Client + tpRatingPlanRPC *birpc.Client tpRatingPlan *utils.TPRatingPlan tpRatingPlanDelay int tpRatingPlanConfigDIR string //run tests for specific configuration @@ -117,7 +118,7 @@ func testTPRatingPlansRpcConn(t *testing.T) { func testTPRatingPlansGetTPRatingPlanBeforeSet(t *testing.T) { var reply *utils.TPRatingPlan - if err := tpRatingPlanRPC.Call(utils.APIerSv1GetTPRatingPlan, + if err := tpRatingPlanRPC.Call(context.Background(), utils.APIerSv1GetTPRatingPlan, &AttrGetTPRatingPlan{TPid: "TPRP1", ID: "Plan1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -141,7 +142,7 @@ func testTPRatingPlansSetTPRatingPlan(t *testing.T) { }, } var result string - if err := tpRatingPlanRPC.Call(utils.APIerSv1SetTPRatingPlan, tpRatingPlan, &result); err != nil { + if err := tpRatingPlanRPC.Call(context.Background(), utils.APIerSv1SetTPRatingPlan, tpRatingPlan, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -150,7 +151,7 @@ func testTPRatingPlansSetTPRatingPlan(t *testing.T) { func testTPRatingPlansGetTPRatingPlanAfterSet(t *testing.T) { var respond *utils.TPRatingPlan - if err := tpRatingPlanRPC.Call(utils.APIerSv1GetTPRatingPlan, + if err := tpRatingPlanRPC.Call(context.Background(), utils.APIerSv1GetTPRatingPlan, &AttrGetTPRatingPlan{TPid: "TPRP1", ID: "Plan1"}, &respond); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpRatingPlan.TPid, respond.TPid) { @@ -165,7 +166,7 @@ func testTPRatingPlansGetTPRatingPlanAfterSet(t *testing.T) { func testTPRatingPlansGetTPRatingPlanIds(t *testing.T) { var result []string expected := []string{"Plan1"} - if err := tpRatingPlanRPC.Call(utils.APIerSv1GetTPRatingPlanIds, + if err := tpRatingPlanRPC.Call(context.Background(), utils.APIerSv1GetTPRatingPlanIds, &AttrGetTPRatingPlanIds{TPid: tpRatingPlan.TPid}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, result) { @@ -192,7 +193,7 @@ func testTPRatingPlansUpdateTPRatingPlan(t *testing.T) { }, } var result string - if err := tpRatingPlanRPC.Call(utils.APIerSv1SetTPRatingPlan, tpRatingPlan, &result); err != nil { + if err := tpRatingPlanRPC.Call(context.Background(), utils.APIerSv1SetTPRatingPlan, tpRatingPlan, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -201,7 +202,7 @@ func testTPRatingPlansUpdateTPRatingPlan(t *testing.T) { func testTPRatingPlansGetTPRatingPlanAfterUpdate(t *testing.T) { var respond *utils.TPRatingPlan - if err := tpRatingPlanRPC.Call(utils.APIerSv1GetTPRatingPlan, + if err := tpRatingPlanRPC.Call(context.Background(), utils.APIerSv1GetTPRatingPlan, &AttrGetTPRatingPlan{TPid: "TPRP1", ID: "Plan1"}, &respond); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpRatingPlan.TPid, respond.TPid) { @@ -215,7 +216,7 @@ func testTPRatingPlansGetTPRatingPlanAfterUpdate(t *testing.T) { func testTPRatingPlansRemoveTPRatingPlan(t *testing.T) { var resp string - if err := tpRatingPlanRPC.Call(utils.APIerSv1RemoveTPRatingPlan, + if err := tpRatingPlanRPC.Call(context.Background(), utils.APIerSv1RemoveTPRatingPlan, &AttrGetTPRatingPlan{TPid: "TPRP1", ID: "Plan1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -225,7 +226,7 @@ func testTPRatingPlansRemoveTPRatingPlan(t *testing.T) { func testTPRatingPlansGetTPRatingPlanAfterRemove(t *testing.T) { var respond *utils.TPRatingPlan - if err := tpRatingPlanRPC.Call(utils.APIerSv1GetTPRatingPlan, + if err := tpRatingPlanRPC.Call(context.Background(), utils.APIerSv1GetTPRatingPlan, &AttrGetTPRatingPlan{TPid: "TPRP1", ID: "Plan1"}, &respond); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/apier/v1/tpratingprofiles.go b/apier/v1/tpratingprofiles.go index d6baa1881..db91d17f3 100644 --- a/apier/v1/tpratingprofiles.go +++ b/apier/v1/tpratingprofiles.go @@ -21,11 +21,12 @@ package v1 // This file deals with tp_rate_profiles management over APIs import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPRatingProfile creates a new RatingProfile within a tariff plan -func (apierSv1 *APIerSv1) SetTPRatingProfile(attrs *utils.TPRatingProfile, reply *string) error { +func (apierSv1 *APIerSv1) SetTPRatingProfile(ctx *context.Context, attrs *utils.TPRatingProfile, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.LoadId, utils.Category, utils.Subject, utils.RatingPlanActivations}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) @@ -41,7 +42,7 @@ func (apierSv1 *APIerSv1) SetTPRatingProfile(attrs *utils.TPRatingProfile, reply } // GetTPRatingProfilesByLoadID queries specific RatingProfile on tariff plan -func (apierSv1 *APIerSv1) GetTPRatingProfilesByLoadID(attrs *utils.TPRatingProfile, reply *[]*utils.TPRatingProfile) error { +func (apierSv1 *APIerSv1) GetTPRatingProfilesByLoadID(ctx *context.Context, attrs *utils.TPRatingProfile, reply *[]*utils.TPRatingProfile) error { mndtryFlds := []string{utils.TPid, utils.LoadId} if len(attrs.Subject) != 0 { // If Subject provided as filter, make all related fields mandatory mndtryFlds = append(mndtryFlds, utils.Category, utils.Subject) @@ -64,7 +65,7 @@ func (apierSv1 *APIerSv1) GetTPRatingProfilesByLoadID(attrs *utils.TPRatingProfi } // GetTPRatingProfileLoadIds queries RatingProfile identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPRatingProfileLoadIds(attrs *utils.AttrTPRatingProfileIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPRatingProfileLoadIds(ctx *context.Context, attrs *utils.AttrTPRatingProfileIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -94,7 +95,7 @@ type AttrGetTPRatingProfile struct { } // GetTPRatingProfile queries specific RatingProfile on tariff plan -func (apierSv1 *APIerSv1) GetTPRatingProfile(attrs *AttrGetTPRatingProfile, reply *utils.TPRatingProfile) error { +func (apierSv1 *APIerSv1) GetTPRatingProfile(ctx *context.Context, attrs *AttrGetTPRatingProfile, reply *utils.TPRatingProfile) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.RatingProfileID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -120,7 +121,7 @@ type AttrGetTPRatingProfileIds struct { } // GetTPRatingProfileIds queries RatingProfiles identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPRatingProfileIds(attrs *AttrGetTPRatingProfileIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPRatingProfileIds(ctx *context.Context, attrs *AttrGetTPRatingProfileIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -138,7 +139,7 @@ func (apierSv1 *APIerSv1) GetTPRatingProfileIds(attrs *AttrGetTPRatingProfileIds } // RemoveTPRatingProfile removes specific RatingProfiles on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPRatingProfile(attrs *AttrGetTPRatingProfile, reply *string) (err error) { +func (apierSv1 *APIerSv1) RemoveTPRatingProfile(ctx *context.Context, attrs *AttrGetTPRatingProfile, reply *string) (err error) { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.RatingProfileID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpratingprofiles_it_test.go b/apier/v1/tpratingprofiles_it_test.go index 09ccad258..15be9234e 100644 --- a/apier/v1/tpratingprofiles_it_test.go +++ b/apier/v1/tpratingprofiles_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpRatingProfileCfgPath string tpRatingProfileCfg *config.CGRConfig - tpRatingProfileRPC *rpc.Client + tpRatingProfileRPC *birpc.Client tpRatingProfile *utils.TPRatingProfile tpRatingProfileDelay int tpRatingProfileConfigDIR string //run tests for specific configuration @@ -120,7 +121,7 @@ func testTPRatingProfilesRpcConn(t *testing.T) { func testTPRatingProfilesGetTPRatingProfileBeforeSet(t *testing.T) { var reply *utils.TPRatingProfile - if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfile, + if err := tpRatingProfileRPC.Call(context.Background(), utils.APIerSv1GetTPRatingProfile, &AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileID: tpRatingProfileID}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -147,7 +148,7 @@ func testTPRatingProfilesSetTPRatingProfile(t *testing.T) { }, } var result string - if err := tpRatingProfileRPC.Call(utils.APIerSv1SetTPRatingProfile, tpRatingProfile, &result); err != nil { + if err := tpRatingProfileRPC.Call(context.Background(), utils.APIerSv1SetTPRatingProfile, tpRatingProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -156,7 +157,7 @@ func testTPRatingProfilesSetTPRatingProfile(t *testing.T) { func testTPRatingProfilesGetTPRatingProfileAfterSet(t *testing.T) { var respond *utils.TPRatingProfile - if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfile, + if err := tpRatingProfileRPC.Call(context.Background(), utils.APIerSv1GetTPRatingProfile, &AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileID: tpRatingProfileID}, &respond); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpRatingProfile.TPid, respond.TPid) { @@ -177,7 +178,7 @@ func testTPRatingProfilesGetTPRatingProfileAfterSet(t *testing.T) { func testTPRatingProfilesGetTPRatingProfileLoadIds(t *testing.T) { var result []string expected := []string{"RPrf"} - if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfileLoadIds, + if err := tpRatingProfileRPC.Call(context.Background(), utils.APIerSv1GetTPRatingProfileLoadIds, &utils.AttrTPRatingProfileIds{TPid: tpRatingProfile.TPid, Tenant: tpRatingProfile.Tenant, Category: tpRatingProfile.Category, Subject: tpRatingProfile.Subject}, &result); err != nil { t.Error(err) @@ -188,7 +189,7 @@ func testTPRatingProfilesGetTPRatingProfileLoadIds(t *testing.T) { func testTPRatingProfilesGetTPRatingProfilesByLoadID(t *testing.T) { var respond *[]*utils.TPRatingProfile - if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfilesByLoadID, + if err := tpRatingProfileRPC.Call(context.Background(), utils.APIerSv1GetTPRatingProfilesByLoadID, &utils.TPRatingProfile{TPid: "TPRProf1", LoadId: "RPrf", Tenant: "Tenant1"}, &respond); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpRatingProfile.TPid, (*respond)[0].TPid) { @@ -225,7 +226,7 @@ func testTPRatingProfilesUpdateTPRatingProfile(t *testing.T) { FallbackSubjects: "Retreat", }, } - if err := tpRatingProfileRPC.Call(utils.APIerSv1SetTPRatingProfile, tpRatingProfile, &result); err != nil { + if err := tpRatingProfileRPC.Call(context.Background(), utils.APIerSv1SetTPRatingProfile, tpRatingProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -234,7 +235,7 @@ func testTPRatingProfilesUpdateTPRatingProfile(t *testing.T) { func testTPRatingProfilesGetTPRatingProfileAfterUpdate(t *testing.T) { var respond *utils.TPRatingProfile - if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfile, + if err := tpRatingProfileRPC.Call(context.Background(), utils.APIerSv1GetTPRatingProfile, &AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileID: tpRatingProfileID}, &respond); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpRatingProfile.TPid, respond.TPid) { @@ -255,7 +256,7 @@ func testTPRatingProfilesGetTPRatingProfileAfterUpdate(t *testing.T) { func testTPRatingProfilesGetTPRatingProfileIds(t *testing.T) { var respond []string expected := []string{"RPrf:Tenant1:Category:Subject"} - if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfileIds, + if err := tpRatingProfileRPC.Call(context.Background(), utils.APIerSv1GetTPRatingProfileIds, &AttrGetTPRatingProfileIds{TPid: "TPRProf1"}, &respond); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, respond) { @@ -265,7 +266,7 @@ func testTPRatingProfilesGetTPRatingProfileIds(t *testing.T) { func testTPRatingProfilesRemoveTPRatingProfile(t *testing.T) { var resp string - if err := tpRatingProfileRPC.Call(utils.APIerSv1RemoveTPRatingProfile, + if err := tpRatingProfileRPC.Call(context.Background(), utils.APIerSv1RemoveTPRatingProfile, &AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileID: utils.ConcatenatedKey(tpRatingProfile.LoadId, tpRatingProfile.Tenant, tpRatingProfile.Category, tpRatingProfile.Subject)}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -275,7 +276,7 @@ func testTPRatingProfilesRemoveTPRatingProfile(t *testing.T) { func testTPRatingProfilesGetTPRatingProfileAfterRemove(t *testing.T) { var respond *utils.TPRatingProfile - if err := tpRatingProfileRPC.Call(utils.APIerSv1GetTPRatingProfile, + if err := tpRatingProfileRPC.Call(context.Background(), utils.APIerSv1GetTPRatingProfile, &AttrGetTPRatingProfile{TPid: "TPRProf1", RatingProfileID: tpRatingProfileID}, &respond); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/apier/v1/tpresources.go b/apier/v1/tpresources.go index cb016ce45..0b7aeb307 100644 --- a/apier/v1/tpresources.go +++ b/apier/v1/tpresources.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPResource creates a new resource within a tariff plan -func (apierSv1 *APIerSv1) SetTPResource(attr *utils.TPResourceProfile, reply *string) error { +func (apierSv1 *APIerSv1) SetTPResource(ctx *context.Context, attr *utils.TPResourceProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID, utils.Limit}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -38,7 +39,7 @@ func (apierSv1 *APIerSv1) SetTPResource(attr *utils.TPResourceProfile, reply *st } // GetTPResource queries specific Resource on Tariff plan -func (apierSv1 *APIerSv1) GetTPResource(attr *utils.TPTntID, reply *utils.TPResourceProfile) error { +func (apierSv1 *APIerSv1) GetTPResource(ctx *context.Context, attr *utils.TPTntID, reply *utils.TPResourceProfile) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -62,7 +63,7 @@ type AttrGetTPResourceIds struct { } // GetTPResourceIDs queries Resource identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPResourceIDs(attrs *AttrGetTPResourceIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPResourceIDs(ctx *context.Context, attrs *AttrGetTPResourceIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -79,7 +80,7 @@ func (apierSv1 *APIerSv1) GetTPResourceIDs(attrs *AttrGetTPResourceIds, reply *[ } // RemoveTPResource removes specific Resource on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPResource(attrs *utils.TPTntID, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPResource(ctx *context.Context, attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpresources_it_test.go b/apier/v1/tpresources_it_test.go index df97db955..3e45b45ae 100644 --- a/apier/v1/tpresources_it_test.go +++ b/apier/v1/tpresources_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "sort" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( tpResCfgPath string tpResCfg *config.CGRConfig - tpResRPC *rpc.Client + tpResRPC *birpc.Client tpRes *utils.TPResourceProfile tpResDelay int tpResConfigDIR string //run tests for specific configuration @@ -112,7 +113,7 @@ func testTPResRpcConn(t *testing.T) { func testTPResGetTPResourceBeforeSet(t *testing.T) { var reply *utils.TPResourceProfile - if err := tpResRPC.Call(utils.APIerSv1GetTPResource, + if err := tpResRPC.Call(context.Background(), utils.APIerSv1GetTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -139,7 +140,7 @@ func testTPResSetTPResource(t *testing.T) { } sort.Strings(tpRes.ThresholdIDs) var result string - if err := tpResRPC.Call(utils.APIerSv1SetTPResource, tpRes, &result); err != nil { + if err := tpResRPC.Call(context.Background(), utils.APIerSv1SetTPResource, tpRes, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -148,7 +149,7 @@ func testTPResSetTPResource(t *testing.T) { func testTPResGetTPResourceAfterSet(t *testing.T) { var respond *utils.TPResourceProfile - if err := tpResRPC.Call(utils.APIerSv1GetTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"}, + if err := tpResRPC.Call(context.Background(), utils.APIerSv1GetTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"}, &respond); err != nil { t.Fatal(err) } @@ -162,7 +163,7 @@ func testTPResUpdateTPResource(t *testing.T) { var result string tpRes.FilterIDs = []string{"FLTR_1", "FLTR_STS1"} sort.Strings(tpRes.FilterIDs) - if err := tpResRPC.Call(utils.APIerSv1SetTPResource, tpRes, &result); err != nil { + if err := tpResRPC.Call(context.Background(), utils.APIerSv1SetTPResource, tpRes, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -171,7 +172,7 @@ func testTPResUpdateTPResource(t *testing.T) { func testTPResGetTPResourceAfterUpdate(t *testing.T) { var expectedTPR *utils.TPResourceProfile - if err := tpResRPC.Call(utils.APIerSv1GetTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"}, + if err := tpResRPC.Call(context.Background(), utils.APIerSv1GetTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"}, &expectedTPR); err != nil { t.Fatal(err) } @@ -184,7 +185,7 @@ func testTPResGetTPResourceAfterUpdate(t *testing.T) { func testTPResRemoveTPResource(t *testing.T) { var resp string - if err := tpResRPC.Call(utils.APIerSv1RemoveTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"}, + if err := tpResRPC.Call(context.Background(), utils.APIerSv1RemoveTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -194,7 +195,7 @@ func testTPResRemoveTPResource(t *testing.T) { func testTPResGetTPResourceAfterRemove(t *testing.T) { var respond *utils.TPResourceProfile - if err := tpResRPC.Call(utils.APIerSv1GetTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"}, + if err := tpResRPC.Call(context.Background(), utils.APIerSv1GetTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"}, &respond); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/apier/v1/tproutes.go b/apier/v1/tproutes.go index 3aae994b0..1aa3865e2 100644 --- a/apier/v1/tproutes.go +++ b/apier/v1/tproutes.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPRouteProfile creates a new RouteProfile within a tariff plan -func (apierSv1 *APIerSv1) SetTPRouteProfile(attrs *utils.TPRouteProfile, reply *string) error { +func (apierSv1 *APIerSv1) SetTPRouteProfile(ctx *context.Context, attrs *utils.TPRouteProfile, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -38,7 +39,7 @@ func (apierSv1 *APIerSv1) SetTPRouteProfile(attrs *utils.TPRouteProfile, reply * } // GetTPRouteProfile queries specific RouteProfile on tariff plan -func (apierSv1 *APIerSv1) GetTPRouteProfile(attr *utils.TPTntID, reply *utils.TPRouteProfile) error { +func (apierSv1 *APIerSv1) GetTPRouteProfile(ctx *context.Context, attr *utils.TPTntID, reply *utils.TPRouteProfile) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -62,7 +63,7 @@ type AttrGetTPRouteProfileIDs struct { } // GetTPRouteProfileIDs queries RouteProfile identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPRouteProfileIDs(attrs *AttrGetTPRouteProfileIDs, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPRouteProfileIDs(ctx *context.Context, attrs *AttrGetTPRouteProfileIDs, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -79,7 +80,7 @@ func (apierSv1 *APIerSv1) GetTPRouteProfileIDs(attrs *AttrGetTPRouteProfileIDs, } // RemoveTPRouteProfile removes specific RouteProfile on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPRouteProfile(attrs *utils.TPTntID, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPRouteProfile(ctx *context.Context, attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tproutes_it_test.go b/apier/v1/tproutes_it_test.go index 6edf46c5c..ca3fea00c 100644 --- a/apier/v1/tproutes_it_test.go +++ b/apier/v1/tproutes_it_test.go @@ -22,14 +22,15 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "sort" "strings" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ import ( var ( tpRouteCfgPath string tpRouteCfg *config.CGRConfig - tpRouteRPC *rpc.Client + tpRouteRPC *birpc.Client tpRoutePrf *utils.TPRouteProfile tpRouteDelay int tpRouteConfigDIR string //run tests for specific configuration @@ -115,7 +116,7 @@ func testTPRouteRPCConn(t *testing.T) { func testTPRouteGetTPRouteBeforeSet(t *testing.T) { var reply *utils.TPRoute - if err := tpRouteRPC.Call(utils.APIerSv1GetTPRouteProfile, + if err := tpRouteRPC.Call(context.Background(), utils.APIerSv1GetTPRouteProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -150,7 +151,7 @@ func testTPRouteSetTPRoute(t *testing.T) { } sort.Strings(tpRoutePrf.FilterIDs) var result string - if err := tpRouteRPC.Call(utils.APIerSv1SetTPRouteProfile, + if err := tpRouteRPC.Call(context.Background(), utils.APIerSv1SetTPRouteProfile, tpRoutePrf, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -160,7 +161,7 @@ func testTPRouteSetTPRoute(t *testing.T) { func testTPRouteGetTPRouteAfterSet(t *testing.T) { var reply *utils.TPRouteProfile - if err := tpRouteRPC.Call(utils.APIerSv1GetTPRouteProfile, + if err := tpRouteRPC.Call(context.Background(), utils.APIerSv1GetTPRouteProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf"}, &reply); err != nil { t.Fatal(err) } @@ -173,7 +174,7 @@ func testTPRouteGetTPRouteAfterSet(t *testing.T) { func testTPRouteGetTPRouteIDs(t *testing.T) { var result []string expectedTPID := []string{"cgrates.org:RoutePrf"} - if err := tpRouteRPC.Call(utils.APIerSv1GetTPRouteProfileIDs, + if err := tpRouteRPC.Call(context.Background(), utils.APIerSv1GetTPRouteProfileIDs, &AttrGetTPRouteProfileIDs{TPid: "TP1"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedTPID, result) { @@ -208,7 +209,7 @@ func testTPRouteUpdateTPRoute(t *testing.T) { }, } var result string - if err := tpRouteRPC.Call(utils.APIerSv1SetTPRouteProfile, + if err := tpRouteRPC.Call(context.Background(), utils.APIerSv1SetTPRouteProfile, tpRoutePrf, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -221,7 +222,7 @@ func testTPRouteUpdateTPRoute(t *testing.T) { func testTPRouteGetTPRouteAfterUpdate(t *testing.T) { var reply *utils.TPRouteProfile - if err := tpRouteRPC.Call(utils.APIerSv1GetTPRouteProfile, + if err := tpRouteRPC.Call(context.Background(), utils.APIerSv1GetTPRouteProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf"}, &reply); err != nil { t.Fatal(err) } @@ -236,7 +237,7 @@ func testTPRouteGetTPRouteAfterUpdate(t *testing.T) { func testTPRouteRemTPRoute(t *testing.T) { var resp string - if err := tpRouteRPC.Call(utils.APIerSv1RemoveTPRouteProfile, + if err := tpRouteRPC.Call(context.Background(), utils.APIerSv1RemoveTPRouteProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf"}, &resp); err != nil { t.Error(err) @@ -247,7 +248,7 @@ func testTPRouteRemTPRoute(t *testing.T) { func testTPRouteGetTPRouteAfterRemove(t *testing.T) { var reply *utils.TPRouteProfile - if err := tpRouteRPC.Call(utils.APIerSv1GetTPRouteProfile, + if err := tpRouteRPC.Call(context.Background(), utils.APIerSv1GetTPRouteProfile, &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) diff --git a/apier/v1/tpsharedgroups.go b/apier/v1/tpsharedgroups.go index 1b1b5ad9b..f4c17d60c 100644 --- a/apier/v1/tpsharedgroups.go +++ b/apier/v1/tpsharedgroups.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPSharedGroups creates a new SharedGroups profile within a tariff plan -func (apierSv1 *APIerSv1) SetTPSharedGroups(attrs *utils.TPSharedGroups, reply *string) error { +func (apierSv1 *APIerSv1) SetTPSharedGroups(ctx *context.Context, attrs *utils.TPSharedGroups, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.SharedGroups}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -40,7 +41,7 @@ type AttrGetTPSharedGroups struct { } // GetTPSharedGroups queries specific SharedGroup on tariff plan -func (apierSv1 *APIerSv1) GetTPSharedGroups(attrs *AttrGetTPSharedGroups, reply *utils.TPSharedGroups) error { +func (apierSv1 *APIerSv1) GetTPSharedGroups(ctx *context.Context, attrs *AttrGetTPSharedGroups, reply *utils.TPSharedGroups) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -61,7 +62,7 @@ type AttrGetTPSharedGroupIds struct { } // GetTPSharedGroupIds queries SharedGroups identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPSharedGroupIds(attrs *AttrGetTPSharedGroupIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPSharedGroupIds(ctx *context.Context, attrs *AttrGetTPSharedGroupIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -78,7 +79,7 @@ func (apierSv1 *APIerSv1) GetTPSharedGroupIds(attrs *AttrGetTPSharedGroupIds, re } // RemoveTPSharedGroups removes specific SharedGroups on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPSharedGroups(attrs *AttrGetTPSharedGroups, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPSharedGroups(ctx *context.Context, attrs *AttrGetTPSharedGroups, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpsharedgroups_it_test.go b/apier/v1/tpsharedgroups_it_test.go index 5f80beed4..8c3f493cb 100644 --- a/apier/v1/tpsharedgroups_it_test.go +++ b/apier/v1/tpsharedgroups_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpSharedGroupCfgPath string tpSharedGroupCfg *config.CGRConfig - tpSharedGroupRPC *rpc.Client + tpSharedGroupRPC *birpc.Client tpSharedGroups *utils.TPSharedGroups tpSharedGroupDelay int tpSharedGroupConfigDIR string //run tests for specific configuration @@ -117,7 +118,7 @@ func testTPSharedGroupsRpcConn(t *testing.T) { func testTPSharedGroupsBeforeSet(t *testing.T) { var reply *utils.TPSharedGroups - if err := tpSharedGroupRPC.Call(utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: "TPS1", ID: "Group1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := tpSharedGroupRPC.Call(context.Background(), utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: "TPS1", ID: "Group1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } @@ -140,7 +141,7 @@ func testTPSharedGroupsSetSharedGroups(t *testing.T) { }, } var result string - if err := tpSharedGroupRPC.Call(utils.APIerSv1SetTPSharedGroups, &tpSharedGroups, &result); err != nil { + if err := tpSharedGroupRPC.Call(context.Background(), utils.APIerSv1SetTPSharedGroups, &tpSharedGroups, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -149,7 +150,7 @@ func testTPSharedGroupsSetSharedGroups(t *testing.T) { func testTPSharedGroupsAfterSet(t *testing.T) { var respond *utils.TPSharedGroups - if err := tpSharedGroupRPC.Call(utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &respond); err != nil { + if err := tpSharedGroupRPC.Call(context.Background(), utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &respond); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpSharedGroups.TPid, respond.TPid) { t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups.TPid, respond.TPid) @@ -163,7 +164,7 @@ func testTPSharedGroupsAfterSet(t *testing.T) { func testTPSharedGroupsGetTPSharedGroupIds(t *testing.T) { var result []string expectedTPID := []string{"Group1"} - if err := tpSharedGroupRPC.Call(utils.APIerSv1GetTPSharedGroupIds, + if err := tpSharedGroupRPC.Call(context.Background(), utils.APIerSv1GetTPSharedGroupIds, &AttrGetTPSharedGroupIds{tpSharedGroups.TPid, utils.PaginatorWithSearch{}}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(result, expectedTPID) { @@ -190,7 +191,7 @@ func testTPSharedGroupsUpdateTPShareGroups(t *testing.T) { RatingSubject: "SubPlus", }, } - if err := tpSharedGroupRPC.Call(utils.APIerSv1SetTPSharedGroups, tpSharedGroups, &result); err != nil { + if err := tpSharedGroupRPC.Call(context.Background(), utils.APIerSv1SetTPSharedGroups, tpSharedGroups, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -199,7 +200,7 @@ func testTPSharedGroupsUpdateTPShareGroups(t *testing.T) { func testTpSharedGroupsGetTPSharedGroupsAfterUpdate(t *testing.T) { var expectedTPS *utils.TPSharedGroups - if err := tpSharedGroupRPC.Call(utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &expectedTPS); err != nil { + if err := tpSharedGroupRPC.Call(context.Background(), utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &expectedTPS); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpSharedGroups.TPid, expectedTPS.TPid) { t.Errorf("Expecting: %+v, received: %+v", tpSharedGroups.TPid, expectedTPS.TPid) @@ -212,7 +213,7 @@ func testTpSharedGroupsGetTPSharedGroupsAfterUpdate(t *testing.T) { func testTPSharedGroupsRemoveTPSharedGroups(t *testing.T) { var resp string - if err := tpSharedGroupRPC.Call(utils.APIerSv1RemoveTPSharedGroups, &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &resp); err != nil { + if err := tpSharedGroupRPC.Call(context.Background(), utils.APIerSv1RemoveTPSharedGroups, &AttrGetTPSharedGroups{TPid: tpSharedGroups.TPid, ID: tpSharedGroups.ID}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) @@ -221,7 +222,7 @@ func testTPSharedGroupsRemoveTPSharedGroups(t *testing.T) { func testTPSharedGroupsGetTPSharedGroupsAfterRemove(t *testing.T) { var reply *utils.TPSharedGroups - if err := tpSharedGroupRPC.Call(utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: "TPS1", ID: "Group1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := tpSharedGroupRPC.Call(context.Background(), utils.APIerSv1GetTPSharedGroups, &AttrGetTPSharedGroups{TPid: "TPS1", ID: "Group1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } diff --git a/apier/v1/tpstats.go b/apier/v1/tpstats.go index 99456fb61..fbf42214a 100644 --- a/apier/v1/tpstats.go +++ b/apier/v1/tpstats.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPStat creates a new stat within a tariff plan -func (apierSv1 *APIerSv1) SetTPStat(attr *utils.TPStatProfile, reply *string) error { +func (apierSv1 *APIerSv1) SetTPStat(ctx *context.Context, attr *utils.TPStatProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -38,7 +39,7 @@ func (apierSv1 *APIerSv1) SetTPStat(attr *utils.TPStatProfile, reply *string) er } // GetTPStat queries specific Stat on Tariff plan -func (apierSv1 *APIerSv1) GetTPStat(attr *utils.TPTntID, reply *utils.TPStatProfile) error { +func (apierSv1 *APIerSv1) GetTPStat(ctx *context.Context, attr *utils.TPTntID, reply *utils.TPStatProfile) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -63,7 +64,7 @@ type AttrGetTPStatIds struct { } // GetTPStatIDs queries Stat identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPStatIDs(attrs *AttrGetTPStatIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPStatIDs(ctx *context.Context, attrs *AttrGetTPStatIds, reply *[]string) error { if missing := utils.MissingStructFields(&attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -83,7 +84,7 @@ func (apierSv1 *APIerSv1) GetTPStatIDs(attrs *AttrGetTPStatIds, reply *[]string) } // RemoveTPStat removes specific Stat on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPStat(attrs *utils.TPTntID, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPStat(ctx *context.Context, attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpstats_it_test.go b/apier/v1/tpstats_it_test.go index 271ee2472..de9334db3 100644 --- a/apier/v1/tpstats_it_test.go +++ b/apier/v1/tpstats_it_test.go @@ -22,14 +22,15 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "sort" "strings" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ import ( var ( tpStatCfgPath string tpStatCfg *config.CGRConfig - tpStatRPC *rpc.Client + tpStatRPC *birpc.Client tpStat *utils.TPStatProfile tpStatDelay int tpStatConfigDIR string //run tests for specific configuration @@ -113,7 +114,7 @@ func testTPStatsRpcConn(t *testing.T) { func testTPStatsGetTPStatBeforeSet(t *testing.T) { var reply *utils.TPStatProfile - if err := tpStatRPC.Call(utils.APIerSv1GetTPStat, + if err := tpStatRPC.Call(context.Background(), utils.APIerSv1GetTPStat, &utils.TPTntID{TPid: "TPS1", Tenant: "cgrates.org", ID: "Stat1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -144,7 +145,7 @@ func testTPStatsSetTPStat(t *testing.T) { } sort.Strings(tpStat.ThresholdIDs) var result string - if err := tpStatRPC.Call(utils.APIerSv1SetTPStat, tpStat, &result); err != nil { + if err := tpStatRPC.Call(context.Background(), utils.APIerSv1SetTPStat, tpStat, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -153,7 +154,7 @@ func testTPStatsSetTPStat(t *testing.T) { func testTPStatsGetTPStatAfterSet(t *testing.T) { var respond *utils.TPStatProfile - if err := tpStatRPC.Call(utils.APIerSv1GetTPStat, + if err := tpStatRPC.Call(context.Background(), utils.APIerSv1GetTPStat, &utils.TPTntID{TPid: "TPS1", Tenant: "cgrates.org", ID: "Stat1"}, &respond); err != nil { t.Fatal(err) } @@ -177,7 +178,7 @@ func testTPStatsUpdateTPStat(t *testing.T) { sort.Slice(tpStat.Metrics, func(i, j int) bool { return strings.Compare(tpStat.Metrics[i].MetricID, tpStat.Metrics[j].MetricID) == -1 }) - if err := tpStatRPC.Call(utils.APIerSv1SetTPStat, tpStat, &result); err != nil { + if err := tpStatRPC.Call(context.Background(), utils.APIerSv1SetTPStat, tpStat, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -186,7 +187,7 @@ func testTPStatsUpdateTPStat(t *testing.T) { func testTPStatsGetTPStatAfterUpdate(t *testing.T) { var expectedTPS *utils.TPStatProfile - if err := tpStatRPC.Call(utils.APIerSv1GetTPStat, + if err := tpStatRPC.Call(context.Background(), utils.APIerSv1GetTPStat, &utils.TPTntID{TPid: "TPS1", Tenant: "cgrates.org", ID: "Stat1"}, &expectedTPS); err != nil { t.Fatal(err) } @@ -201,7 +202,7 @@ func testTPStatsGetTPStatAfterUpdate(t *testing.T) { func testTPStatsRemoveTPStat(t *testing.T) { var resp string - if err := tpStatRPC.Call(utils.APIerSv1RemoveTPStat, + if err := tpStatRPC.Call(context.Background(), utils.APIerSv1RemoveTPStat, &utils.TPTntID{TPid: "TPS1", Tenant: "cgrates.org", ID: "Stat1"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -211,7 +212,7 @@ func testTPStatsRemoveTPStat(t *testing.T) { func testTPStatsGetTPStatAfterRemove(t *testing.T) { var respond *utils.TPStatProfile - if err := tpStatRPC.Call(utils.APIerSv1GetTPStat, + if err := tpStatRPC.Call(context.Background(), utils.APIerSv1GetTPStat, &utils.TPTntID{TPid: "TPS1", Tenant: "cgrates.org", ID: "Stat1"}, &respond); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) diff --git a/apier/v1/tpthresholds.go b/apier/v1/tpthresholds.go index 7b9aabad7..378ca145d 100644 --- a/apier/v1/tpthresholds.go +++ b/apier/v1/tpthresholds.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPThreshold creates a new threshold within a tariff plan -func (apierSv1 *APIerSv1) SetTPThreshold(attr *utils.TPThresholdProfile, reply *string) error { +func (apierSv1 *APIerSv1) SetTPThreshold(ctx *context.Context, attr *utils.TPThresholdProfile, reply *string) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -38,7 +39,7 @@ func (apierSv1 *APIerSv1) SetTPThreshold(attr *utils.TPThresholdProfile, reply * } // GetTPThreshold queries specific Threshold on Tariff plan -func (apierSv1 *APIerSv1) GetTPThreshold(attr *utils.TPTntID, reply *utils.TPThresholdProfile) error { +func (apierSv1 *APIerSv1) GetTPThreshold(ctx *context.Context, attr *utils.TPTntID, reply *utils.TPThresholdProfile) error { if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -63,7 +64,7 @@ type AttrGetTPThresholdIds struct { } // GetTPThresholdIDs queries Threshold identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPThresholdIDs(attrs *AttrGetTPThresholdIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPThresholdIDs(ctx *context.Context, attrs *AttrGetTPThresholdIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -83,7 +84,7 @@ func (apierSv1 *APIerSv1) GetTPThresholdIDs(attrs *AttrGetTPThresholdIds, reply } // RemoveTPThreshold removes specific Threshold on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPThreshold(attrs *utils.TPTntID, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPThreshold(ctx *context.Context, attrs *utils.TPTntID, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tpthresholds_it_test.go b/apier/v1/tpthresholds_it_test.go index 64dc61303..e4e718129 100644 --- a/apier/v1/tpthresholds_it_test.go +++ b/apier/v1/tpthresholds_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "sort" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( tpThresholdCfgPath string tpThresholdCfg *config.CGRConfig - tpThresholdRPC *rpc.Client + tpThresholdRPC *birpc.Client tpThreshold *utils.TPThresholdProfile tpThresholdDelay int tpThresholdConfigDIR string //run tests for specific configuration @@ -114,7 +115,7 @@ func testTPThreholdRpcConn(t *testing.T) { func testTPThreholdGetTPThreholdBeforeSet(t *testing.T) { var reply *utils.TPThresholdProfile - if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThreshold, + if err := tpThresholdRPC.Call(context.Background(), utils.APIerSv1GetTPThreshold, &utils.TPTntID{TPid: "TH1", Tenant: "cgrates.org", ID: "Threshold"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -140,7 +141,7 @@ func testTPThreholdSetTPThrehold(t *testing.T) { sort.Strings(tpThreshold.FilterIDs) sort.Strings(tpThreshold.ActionIDs) var result string - if err := tpThresholdRPC.Call(utils.APIerSv1SetTPThreshold, tpThreshold, &result); err != nil { + if err := tpThresholdRPC.Call(context.Background(), utils.APIerSv1SetTPThreshold, tpThreshold, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -149,7 +150,7 @@ func testTPThreholdSetTPThrehold(t *testing.T) { func testTPThreholdGetTPThreholdAfterSet(t *testing.T) { var respond *utils.TPThresholdProfile - if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThreshold, + if err := tpThresholdRPC.Call(context.Background(), utils.APIerSv1GetTPThreshold, &utils.TPTntID{TPid: "TH1", Tenant: "cgrates.org", ID: "Threshold"}, &respond); err != nil { t.Fatal(err) } @@ -163,7 +164,7 @@ func testTPThreholdGetTPThreholdAfterSet(t *testing.T) { func testTPThreholdGetTPThreholdIds(t *testing.T) { var result []string expectedTPID := []string{"cgrates.org:Threshold"} - if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThresholdIDs, + if err := tpThresholdRPC.Call(context.Background(), utils.APIerSv1GetTPThresholdIDs, &AttrGetTPThresholdIds{TPid: tpThreshold.TPid}, &result); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(result, expectedTPID) { @@ -174,7 +175,7 @@ func testTPThreholdGetTPThreholdIds(t *testing.T) { func testTPThreholdUpdateTPThrehold(t *testing.T) { var result string tpThreshold.FilterIDs = []string{"FLTR_1", "FLTR_2", "FLTR_3"} - if err := tpThresholdRPC.Call(utils.APIerSv1SetTPThreshold, tpThreshold, &result); err != nil { + if err := tpThresholdRPC.Call(context.Background(), utils.APIerSv1SetTPThreshold, tpThreshold, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -183,7 +184,7 @@ func testTPThreholdUpdateTPThrehold(t *testing.T) { func testTPThreholdGetTPThreholdAfterUpdate(t *testing.T) { var respond *utils.TPThresholdProfile - if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThreshold, + if err := tpThresholdRPC.Call(context.Background(), utils.APIerSv1GetTPThreshold, &utils.TPTntID{TPid: "TH1", Tenant: "cgrates.org", ID: "Threshold"}, &respond); err != nil { t.Fatal(err) } @@ -196,7 +197,7 @@ func testTPThreholdGetTPThreholdAfterUpdate(t *testing.T) { func testTPThreholdRemTPThrehold(t *testing.T) { var resp string - if err := tpThresholdRPC.Call(utils.APIerSv1RemoveTPThreshold, + if err := tpThresholdRPC.Call(context.Background(), utils.APIerSv1RemoveTPThreshold, &utils.TPTntID{TPid: "TH1", Tenant: "cgrates.org", ID: "Threshold"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -206,7 +207,7 @@ func testTPThreholdRemTPThrehold(t *testing.T) { func testTPThreholdGetTPThreholdAfterRemove(t *testing.T) { var reply *utils.TPThresholdProfile - if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThreshold, + if err := tpThresholdRPC.Call(context.Background(), utils.APIerSv1GetTPThreshold, &utils.TPTntID{TPid: "TH1", Tenant: "cgrates.org", ID: "Threshold"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) diff --git a/apier/v1/tptimings.go b/apier/v1/tptimings.go index 37e3b8994..68b4bd19d 100644 --- a/apier/v1/tptimings.go +++ b/apier/v1/tptimings.go @@ -19,11 +19,12 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // SetTPTiming creates a new timing within a tariff plan -func (apierSv1 *APIerSv1) SetTPTiming(attrs *utils.ApierTPTiming, reply *string) error { +func (apierSv1 *APIerSv1) SetTPTiming(ctx *context.Context, attrs *utils.ApierTPTiming, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.YearsFieldName, utils.MonthsFieldName, utils.MonthDaysFieldName, utils.WeekDaysFieldName, utils.Time}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -40,7 +41,7 @@ type AttrGetTPTiming struct { } // GetTPTiming queries specific Timing on Tariff plan -func (apierSv1 *APIerSv1) GetTPTiming(attrs *AttrGetTPTiming, reply *utils.ApierTPTiming) error { +func (apierSv1 *APIerSv1) GetTPTiming(ctx *context.Context, attrs *AttrGetTPTiming, reply *utils.ApierTPTiming) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -61,7 +62,7 @@ type AttrGetTPTimingIds struct { } // GetTPTimingIds queries timing identities on specific tariff plan. -func (apierSv1 *APIerSv1) GetTPTimingIds(attrs *AttrGetTPTimingIds, reply *[]string) error { +func (apierSv1 *APIerSv1) GetTPTimingIds(ctx *context.Context, attrs *AttrGetTPTimingIds, reply *[]string) error { if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -78,7 +79,7 @@ func (apierSv1 *APIerSv1) GetTPTimingIds(attrs *AttrGetTPTimingIds, reply *[]str } // RemoveTPTiming removes specific Timing on Tariff plan -func (apierSv1 *APIerSv1) RemoveTPTiming(attrs AttrGetTPTiming, reply *string) error { +func (apierSv1 *APIerSv1) RemoveTPTiming(ctx *context.Context, attrs AttrGetTPTiming, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/tptimings_it_test.go b/apier/v1/tptimings_it_test.go index 84dab39f3..9dd450867 100644 --- a/apier/v1/tptimings_it_test.go +++ b/apier/v1/tptimings_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package v1 import ( - "net/rpc" - "net/rpc/jsonrpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( tpTimingCfgPath string tpTimingCfg *config.CGRConfig - tpTimingRPC *rpc.Client + tpTimingRPC *birpc.Client tpTiming *utils.ApierTPTiming tpTimingDelay int tpTimingConfigDIR string //run tests for specific configuration @@ -117,7 +118,7 @@ func testTPTimingsRpcConn(t *testing.T) { func testTPTimingsGetTPTimingBeforeSet(t *testing.T) { var reply *utils.ApierTPTiming - if err := tpTimingRPC.Call(utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: "TPT1", ID: "Timining"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := tpTimingRPC.Call(context.Background(), utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: "TPT1", ID: "Timining"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } @@ -133,7 +134,7 @@ func testTPTimingsSetTPTiming(t *testing.T) { Time: "15:00:00Z", } var result string - if err := tpTimingRPC.Call(utils.APIerSv1SetTPTiming, &tpTiming, &result); err != nil { + if err := tpTimingRPC.Call(context.Background(), utils.APIerSv1SetTPTiming, &tpTiming, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -142,7 +143,7 @@ func testTPTimingsSetTPTiming(t *testing.T) { func testTPTimingsGetTPTimingAfterSet(t *testing.T) { var respond *utils.ApierTPTiming - if err := tpTimingRPC.Call(utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &respond); err != nil { + if err := tpTimingRPC.Call(context.Background(), utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &respond); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpTiming, respond) { t.Errorf("Expecting: %+v, received: %+v", tpTiming, respond) @@ -152,7 +153,7 @@ func testTPTimingsGetTPTimingAfterSet(t *testing.T) { func testTPTimingsGetTPTimingIds(t *testing.T) { var result []string expectedTPID := []string{"Timing"} - if err := tpTimingRPC.Call(utils.APIerSv1GetTPTimingIds, &AttrGetTPTimingIds{TPid: tpTiming.TPid}, &result); err != nil { + if err := tpTimingRPC.Call(context.Background(), utils.APIerSv1GetTPTimingIds, &AttrGetTPTimingIds{TPid: tpTiming.TPid}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(result, expectedTPID) { t.Errorf("Expecting: %+v, received: %+v", result, expectedTPID) @@ -162,7 +163,7 @@ func testTPTimingsGetTPTimingIds(t *testing.T) { func testTPTimingsUpdateTPTiming(t *testing.T) { var result string tpTiming.Years = "2015" - if err := tpTimingRPC.Call(utils.APIerSv1SetTPTiming, &tpTiming, &result); err != nil { + if err := tpTimingRPC.Call(context.Background(), utils.APIerSv1SetTPTiming, &tpTiming, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -171,7 +172,7 @@ func testTPTimingsUpdateTPTiming(t *testing.T) { func testTPTimingsGetTPTimingAfterUpdate(t *testing.T) { var expectedTPS *utils.ApierTPTiming - if err := tpTimingRPC.Call(utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &expectedTPS); err != nil { + if err := tpTimingRPC.Call(context.Background(), utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &expectedTPS); err != nil { t.Error(err) } else if !reflect.DeepEqual(tpTiming, expectedTPS) { t.Errorf("Expecting: %+v, received: %+v", tpTiming, expectedTPS) @@ -180,7 +181,7 @@ func testTPTimingsGetTPTimingAfterUpdate(t *testing.T) { func testTPTimingsRemoveTPTiming(t *testing.T) { var resp string - if err := tpTimingRPC.Call(utils.APIerSv1RemoveTPTiming, &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &resp); err != nil { + if err := tpTimingRPC.Call(context.Background(), utils.APIerSv1RemoveTPTiming, &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) @@ -189,7 +190,7 @@ func testTPTimingsRemoveTPTiming(t *testing.T) { func testTPTimingsGetTPTimingAfterRemove(t *testing.T) { var reply *utils.ApierTPTiming - if err := tpTimingRPC.Call(utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: "TPT1", ID: "Timining"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := tpTimingRPC.Call(context.Background(), utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: "TPT1", ID: "Timining"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } diff --git a/apier/v1/triggers.go b/apier/v1/triggers.go index 6cd9de00c..c0b1ee02c 100644 --- a/apier/v1/triggers.go +++ b/apier/v1/triggers.go @@ -23,6 +23,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/guardian" @@ -30,7 +31,7 @@ import ( ) // Returns a list of ActionTriggers on an account -func (apierSv1 *APIerSv1) GetAccountActionTriggers(attrs *utils.TenantAccount, reply *engine.ActionTriggers) error { +func (apierSv1 *APIerSv1) GetAccountActionTriggers(ctx *context.Context, attrs *utils.TenantAccount, reply *engine.ActionTriggers) error { if missing := utils.MissingStructFields(attrs, []string{utils.AccountField}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -59,7 +60,7 @@ type AttrAddAccountActionTriggers struct { Executed bool } -func (apierSv1 *APIerSv1) AddAccountActionTriggers(attr *AttrAddAccountActionTriggers, reply *string) (err error) { +func (apierSv1 *APIerSv1) AddAccountActionTriggers(ctx *context.Context, attr *AttrAddAccountActionTriggers, reply *string) (err error) { if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -118,7 +119,7 @@ type AttrRemoveAccountActionTriggers struct { UniqueID string } -func (apierSv1 *APIerSv1) RemoveAccountActionTriggers(attr *AttrRemoveAccountActionTriggers, reply *string) error { +func (apierSv1 *APIerSv1) RemoveAccountActionTriggers(ctx *context.Context, attr *AttrRemoveAccountActionTriggers, reply *string) error { if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -163,7 +164,7 @@ type AttrResetAccountActionTriggers struct { Executed bool } -func (apierSv1 *APIerSv1) ResetAccountActionTriggers(attr *AttrResetAccountActionTriggers, reply *string) error { +func (apierSv1 *APIerSv1) ResetAccountActionTriggers(ctx *context.Context, attr *AttrResetAccountActionTriggers, reply *string) error { if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -351,7 +352,7 @@ func (attr *AttrSetActionTrigger) UpdateActionTrigger(at *engine.ActionTrigger, } // SetAccountActionTriggers updates or creates if not present the ActionTrigger for an Account -func (apierSv1 *APIerSv1) SetAccountActionTriggers(attr *AttrSetAccountActionTriggers, reply *string) error { +func (apierSv1 *APIerSv1) SetAccountActionTriggers(ctx *context.Context, attr *AttrSetAccountActionTriggers, reply *string) error { if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -401,7 +402,7 @@ type AttrRemoveActionTrigger struct { UniqueID string } -func (apierSv1 *APIerSv1) RemoveActionTrigger(attr *AttrRemoveActionTrigger, reply *string) (err error) { +func (apierSv1 *APIerSv1) RemoveActionTrigger(ctx *context.Context, attr *AttrRemoveActionTrigger, reply *string) (err error) { if missing := utils.MissingStructFields(attr, []string{"GroupID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -428,7 +429,7 @@ func (apierSv1 *APIerSv1) RemoveActionTrigger(attr *AttrRemoveActionTrigger, rep return } // CacheReload - if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err = apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ActionTriggerIDs: []string{attr.GroupID}, }, reply); err != nil { @@ -443,7 +444,7 @@ func (apierSv1 *APIerSv1) RemoveActionTrigger(attr *AttrRemoveActionTrigger, rep } // SetActionTrigger updates a ActionTrigger -func (apierSv1 *APIerSv1) SetActionTrigger(attr *AttrSetActionTrigger, reply *string) (err error) { +func (apierSv1 *APIerSv1) SetActionTrigger(ctx *context.Context, attr *AttrSetActionTrigger, reply *string) (err error) { if missing := utils.MissingStructFields(attr, []string{"GroupID"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -478,7 +479,7 @@ func (apierSv1 *APIerSv1) SetActionTrigger(attr *AttrSetActionTrigger, reply *st return } // CacheReload - if err = apierSv1.ConnMgr.Call(apierSv1.Config.ApierCfg().CachesConns, nil, + if err = apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ActionTriggerIDs: []string{attr.GroupID}, }, reply); err != nil { @@ -496,7 +497,7 @@ type AttrGetActionTriggers struct { GroupIDs []string } -func (apierSv1 *APIerSv1) GetActionTriggers(attr *AttrGetActionTriggers, atrs *engine.ActionTriggers) error { +func (apierSv1 *APIerSv1) GetActionTriggers(ctx *context.Context, attr *AttrGetActionTriggers, atrs *engine.ActionTriggers) error { var allAttrs engine.ActionTriggers if len(attr.GroupIDs) > 0 { for _, key := range attr.GroupIDs { @@ -545,7 +546,7 @@ type AttrAddActionTrigger struct { } // Deprecated in rc8, replaced by AddAccountActionTriggers -func (apierSv1 *APIerSv1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string) error { +func (apierSv1 *APIerSv1) AddTriggeredAction(ctx *context.Context, attr AttrAddActionTrigger, reply *string) error { if missing := utils.MissingStructFields(&attr, []string{utils.AccountField}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/versions.go b/apier/v1/versions.go index 7ec3cafe9..17ad90a5c 100644 --- a/apier/v1/versions.go +++ b/apier/v1/versions.go @@ -19,12 +19,13 @@ along with this program. If not, see package v1 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // Queries all versions from dataDB -func (apierSv1 *APIerSv1) GetDataDBVersions(ign *string, reply *engine.Versions) error { +func (apierSv1 *APIerSv1) GetDataDBVersions(ctx *context.Context, ign *string, reply *engine.Versions) error { if vrs, err := apierSv1.DataManager.DataDB().GetVersions(""); err != nil { return utils.NewErrServerError(err) } else if len(vrs) == 0 { @@ -36,7 +37,7 @@ func (apierSv1 *APIerSv1) GetDataDBVersions(ign *string, reply *engine.Versions) } // Queries all versions from stordb -func (apierSv1 *APIerSv1) GetStorDBVersions(ign *string, reply *engine.Versions) error { +func (apierSv1 *APIerSv1) GetStorDBVersions(ctx *context.Context, ign *string, reply *engine.Versions) error { if vrs, err := apierSv1.StorDb.GetVersions(""); err != nil { return utils.NewErrServerError(err) } else if len(vrs) == 0 { @@ -53,7 +54,7 @@ type SetVersionsArg struct { } // Queries all versions from dataDB -func (apierSv1 *APIerSv1) SetDataDBVersions(arg *SetVersionsArg, reply *string) error { +func (apierSv1 *APIerSv1) SetDataDBVersions(ctx *context.Context, arg *SetVersionsArg, reply *string) error { if arg.Versions == nil { arg.Versions = engine.CurrentDataDBVersions() } @@ -65,7 +66,7 @@ func (apierSv1 *APIerSv1) SetDataDBVersions(arg *SetVersionsArg, reply *string) } // Queries all versions from stordb -func (apierSv1 *APIerSv1) SetStorDBVersions(arg *SetVersionsArg, reply *string) error { +func (apierSv1 *APIerSv1) SetStorDBVersions(ctx *context.Context, arg *SetVersionsArg, reply *string) error { if arg.Versions == nil { arg.Versions = engine.CurrentDataDBVersions() } diff --git a/apier/v1/versions_it_test.go b/apier/v1/versions_it_test.go index e1ccb1188..adda062fe 100644 --- a/apier/v1/versions_it_test.go +++ b/apier/v1/versions_it_test.go @@ -22,10 +22,11 @@ along with this program. If not, see package v1 import ( - "net/rpc" "path" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -34,7 +35,7 @@ import ( var ( vrsCfgPath string vrsCfg *config.CGRConfig - vrsRPC *rpc.Client + vrsRPC *birpc.Client vrsDelay int vrsConfigDIR string //run tests for specific configuration vrsStorageType string @@ -125,7 +126,7 @@ func testVrsDataDB(t *testing.T) { "RatingProfile": 1, "Accounts": 3, "ActionPlans": 3, "Chargers": 2, "Destinations": 1, "LoadIDs": 1, "SharedGroups": 2, "Stats": 4, "Resource": 1, "Subscribers": 1, "Routes": 2, "Thresholds": 4, "Timing": 1, "Dispatchers": 2} - if err := vrsRPC.Call(utils.APIerSv1GetDataDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil { + if err := vrsRPC.Call(context.Background(), utils.APIerSv1GetDataDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil { t.Error(err) } else if expectedVrs.Compare(result, vrsStorageType, true) != "" { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedVrs), utils.ToJSON(result)) @@ -139,7 +140,7 @@ func testVrsStorDB(t *testing.T) { "TpSharedGroups": 1, "TpRoutes": 1, "SessionSCosts": 3, "TpRatingProfiles": 1, "TpStats": 1, "TpTiming": 1, "CostDetails": 2, "TpAccountActions": 1, "TpActionPlans": 1, "TpChargers": 1, "TpRatingProfile": 1, "TpRatingPlan": 1, "TpResources": 1} - if err := vrsRPC.Call(utils.APIerSv1GetStorDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil { + if err := vrsRPC.Call(context.Background(), utils.APIerSv1GetStorDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil { t.Error(err) } else if expectedVrs.Compare(result, vrsStorageType, true) != "" { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(result), utils.ToJSON(expectedVrs)) @@ -153,7 +154,7 @@ func testVrsSetDataDBVrs(t *testing.T) { "Attributes": 3, }, } - if err := vrsRPC.Call(utils.APIerSv1SetDataDBVersions, &args, &reply); err != nil { + if err := vrsRPC.Call(context.Background(), utils.APIerSv1SetDataDBVersions, &args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply) @@ -166,7 +167,7 @@ func testVrsSetDataDBVrs(t *testing.T) { "Destinations": 1, "LoadIDs": 1, "SharedGroups": 2, "Stats": 4, "Resource": 1, "Subscribers": 1, "Routes": 2, "Thresholds": 4, "Timing": 1, "Dispatchers": 2} - if err := vrsRPC.Call(utils.APIerSv1GetDataDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil { + if err := vrsRPC.Call(context.Background(), utils.APIerSv1GetDataDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil { t.Error(err) } else if expectedVrs.Compare(result, vrsStorageType, true) != "" { t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedVrs), utils.ToJSON(result)) @@ -175,7 +176,7 @@ func testVrsSetDataDBVrs(t *testing.T) { args = SetVersionsArg{ Versions: nil, } - if err := vrsRPC.Call(utils.APIerSv1SetDataDBVersions, &args, &reply); err != nil { + if err := vrsRPC.Call(context.Background(), utils.APIerSv1SetDataDBVersions, &args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply) @@ -189,7 +190,7 @@ func testVrsSetStorDBVrs(t *testing.T) { "TpResources": 2, }, } - if err := vrsRPC.Call(utils.APIerSv1SetStorDBVersions, &args, &reply); err != nil { + if err := vrsRPC.Call(context.Background(), utils.APIerSv1SetStorDBVersions, &args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply) @@ -201,7 +202,7 @@ func testVrsSetStorDBVrs(t *testing.T) { "TpSharedGroups": 1, "TpRoutes": 1, "SessionSCosts": 3, "TpRatingProfiles": 1, "TpStats": 1, "TpTiming": 1, "CostDetails": 2, "TpAccountActions": 1, "TpActionPlans": 1, "TpChargers": 1, "TpRatingProfile": 1, "TpRatingPlan": 1, "TpResources": 2} - if err := vrsRPC.Call(utils.APIerSv1GetStorDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil { + if err := vrsRPC.Call(context.Background(), utils.APIerSv1GetStorDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil { t.Error(err) } else if expectedVrs.Compare(result, vrsStorageType, true) != "" { t.Errorf("Expecting: %+v, received: %+v", result, expectedVrs) @@ -210,7 +211,7 @@ func testVrsSetStorDBVrs(t *testing.T) { args = SetVersionsArg{ Versions: nil, } - if err := vrsRPC.Call(utils.APIerSv1SetStorDBVersions, &args, &reply); err != nil { + if err := vrsRPC.Call(context.Background(), utils.APIerSv1SetStorDBVersions, &args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply) diff --git a/apier/v2/accounts.go b/apier/v2/accounts.go index 4bdbe2e71..3b396f9bd 100644 --- a/apier/v2/accounts.go +++ b/apier/v2/accounts.go @@ -22,13 +22,14 @@ import ( "errors" "math" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" ) -func (apiv2 *APIerSv2) GetAccounts(attr *utils.AttrGetAccounts, reply *[]*engine.Account) error { +func (apiv2 *APIerSv2) GetAccounts(ctx *context.Context, attr *utils.AttrGetAccounts, reply *[]*engine.Account) error { tnt := attr.Tenant if tnt == utils.EmptyString { tnt = apiv2.Config.GeneralCfg().DefaultTenant @@ -83,7 +84,7 @@ func (apiv2 *APIerSv2) GetAccounts(attr *utils.AttrGetAccounts, reply *[]*engine // GetAccountsCount sets in reply var the total number of accounts registered for the received tenant // returns ErrNotFound in case of 0 accounts -func (apiv2 *APIerSv2) GetAccountsCount(attr *utils.AttrGetAccountsCount, reply *int) (err error) { +func (apiv2 *APIerSv2) GetAccountsCount(ctx *context.Context, attr *utils.AttrGetAccountsCount, reply *int) (err error) { tnt := attr.Tenant if tnt == utils.EmptyString { tnt = apiv2.Config.GeneralCfg().DefaultTenant @@ -101,7 +102,7 @@ func (apiv2 *APIerSv2) GetAccountsCount(attr *utils.AttrGetAccountsCount, reply } // Get balance -func (apiv2 *APIerSv2) GetAccount(attr *utils.AttrGetAccount, reply *engine.Account) error { +func (apiv2 *APIerSv2) GetAccount(ctx *context.Context, attr *utils.AttrGetAccount, reply *engine.Account) error { tnt := attr.Tenant if tnt == utils.EmptyString { tnt = apiv2.Config.GeneralCfg().DefaultTenant @@ -126,7 +127,7 @@ type AttrSetAccount struct { ReloadScheduler bool } -func (apiv2 *APIerSv2) SetAccount(attr *AttrSetAccount, reply *string) error { +func (apiv2 *APIerSv2) SetAccount(ctx *context.Context, attr *AttrSetAccount, reply *string) error { if missing := utils.MissingStructFields(attr, []string{utils.AccountField}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -215,7 +216,7 @@ func (apiv2 *APIerSv2) SetAccount(attr *AttrSetAccount, reply *string) error { if err := apiv2.DataManager.SetAccountActionPlans(accID, acntAPids, true); err != nil { return err } - return apiv2.ConnMgr.Call(apiv2.Config.ApierCfg().CachesConns, nil, + return apiv2.ConnMgr.Call(context.TODO(), apiv2.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ AccountActionPlanIDs: []string{accID}, ActionPlanIDs: apIDs, diff --git a/apier/v2/accounts_it_test.go b/apier/v2/accounts_it_test.go index a5a91cb82..e49cabedb 100644 --- a/apier/v2/accounts_it_test.go +++ b/apier/v2/accounts_it_test.go @@ -22,11 +22,13 @@ along with this program. If not, see package v2 import ( - "net/rpc" "path" "reflect" "testing" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -37,7 +39,7 @@ var ( accConfigDIR string //run tests for specific configuration accCfgPath string accCfg *config.CGRConfig - accRPC *rpc.Client + accRPC *birpc.Client sTestsAcc = []func(t *testing.T){ testAccountsInitCfg, @@ -120,7 +122,7 @@ func testAccountsRPCConn(t *testing.T) { func testApierSetActions(t *testing.T) { var reply string - if err := accRPC.Call(utils.APIerSv1SetActions, &v1.V1AttrSetActions{ + if err := accRPC.Call(context.Background(), utils.APIerSv1SetActions, &v1.V1AttrSetActions{ ActionsId: "TestAccountAction", Actions: []*v1.V1TPAction{{ Identifier: utils.MetaTopUpReset, @@ -138,7 +140,7 @@ func testApierSetActions(t *testing.T) { func testAccountsSetActPlans(t *testing.T) { var reply string - if err := accRPC.Call(utils.APIerSv1SetActionPlan, &v1.AttrSetActionPlan{ + if err := accRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &v1.AttrSetActionPlan{ Id: "TestAccountAP1", ActionPlan: []*v1.AttrActionPlan{{ ActionsId: "TestAccountAction", @@ -151,7 +153,7 @@ func testAccountsSetActPlans(t *testing.T) { } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply) } - if err := accRPC.Call(utils.APIerSv1SetActionPlan, &v1.AttrSetActionPlan{ + if err := accRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &v1.AttrSetActionPlan{ Id: "TestAccountAP2", ActionPlan: []*v1.AttrActionPlan{{ ActionsId: "TestAccountAction", @@ -164,7 +166,7 @@ func testAccountsSetActPlans(t *testing.T) { } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply) } - if err := accRPC.Call(utils.APIerSv1SetActionPlan, &v1.AttrSetActionPlan{ + if err := accRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &v1.AttrSetActionPlan{ Id: "TestAccountAP3", ActionPlan: []*v1.AttrActionPlan{{ ActionsId: "TestAccountAction", @@ -181,7 +183,7 @@ func testAccountsSetActPlans(t *testing.T) { func testAccountsSet1(t *testing.T) { var reply string - if err := accRPC.Call(utils.APIerSv2SetAccount, AttrSetAccount{ + if err := accRPC.Call(context.Background(), utils.APIerSv2SetAccount, AttrSetAccount{ Tenant: "cgrates.org", Account: "dan", ReloadScheduler: true, @@ -192,7 +194,7 @@ func testAccountsSet1(t *testing.T) { } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetAccount received: %s", reply) } - if err := accRPC.Call(utils.APIerSv2SetAccount, AttrSetAccount{ + if err := accRPC.Call(context.Background(), utils.APIerSv2SetAccount, AttrSetAccount{ Tenant: "cgrates.org", Account: "dan2", ReloadScheduler: true, @@ -211,7 +213,7 @@ func testAccountsGetActionPlan1(t *testing.T) { "cgrates.org:dan": true, "cgrates.org:dan2": true, } - if err := accRPC.Call(utils.APIerSv1GetActionPlan, + if err := accRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, v1.AttrGetActionPlan{ID: "TestAccountAP1"}, &aps); err != nil { t.Error(err) } else if len(aps) != 1 { @@ -225,7 +227,7 @@ func testAccountsGetActionPlan1(t *testing.T) { func testAccountsSet2(t *testing.T) { var reply string - if err := accRPC.Call(utils.APIerSv2SetAccount, AttrSetAccount{ + if err := accRPC.Call(context.Background(), utils.APIerSv2SetAccount, AttrSetAccount{ Tenant: "cgrates.org", Account: "dan", ReloadScheduler: true, @@ -240,7 +242,7 @@ func testAccountsSet2(t *testing.T) { func testAccountsGetAccountActionPlan(t *testing.T) { var reply []*v1.AccountActionTiming - if err := accRPC.Call(utils.APIerSv1GetAccountActionPlan, utils.TenantAccount{ + if err := accRPC.Call(context.Background(), utils.APIerSv1GetAccountActionPlan, utils.TenantAccount{ Tenant: "cgrates.org", Account: "dan", }, &reply); err != nil { @@ -257,7 +259,7 @@ func testAccountsGetActionPlan2(t *testing.T) { accIDsStrMp := utils.StringMap{ "cgrates.org:dan2": true, } - if err := accRPC.Call(utils.APIerSv1GetActionPlan, + if err := accRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, v1.AttrGetActionPlan{ID: "TestAccountAP1"}, &aps); err != nil { t.Error(err) } else if len(aps) != 1 { diff --git a/apier/v2/apier.go b/apier/v2/apier.go index 1490810a7..99255ef56 100644 --- a/apier/v2/apier.go +++ b/apier/v2/apier.go @@ -27,6 +27,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -38,8 +39,8 @@ type APIerSv2 struct { v1.APIerSv1 } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (apiv2 *APIerSv2) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (apiv2 *APIerSv2) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(apiv2, serviceMethod, args, reply) } @@ -50,7 +51,7 @@ type AttrLoadRatingProfile struct { } // Process dependencies and load a specific rating profile from storDb into dataDb. -func (apiv2 *APIerSv2) LoadRatingProfile(attrs *AttrLoadRatingProfile, reply *string) error { +func (apiv2 *APIerSv2) LoadRatingProfile(ctx *context.Context, attrs *AttrLoadRatingProfile, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing("TPid") } @@ -80,7 +81,7 @@ type AttrLoadAccountActions struct { } // Process dependencies and load a specific AccountActions profile from storDb into dataDb. -func (apiv2 *APIerSv2) LoadAccountActions(attrs *AttrLoadAccountActions, reply *string) error { +func (apiv2 *APIerSv2) LoadAccountActions(ctx *context.Context, attrs *AttrLoadAccountActions, reply *string) error { if len(attrs.TPid) == 0 { return utils.NewErrMandatoryIeMissing("TPid") } @@ -106,7 +107,7 @@ func (apiv2 *APIerSv2) LoadAccountActions(attrs *AttrLoadAccountActions, reply * return nil } -func (apiv2 *APIerSv2) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolder, reply *utils.LoadInstance) error { +func (apiv2 *APIerSv2) LoadTariffPlanFromFolder(ctx *context.Context, attrs *utils.AttrLoadTpFromFolder, reply *utils.LoadInstance) error { if len(attrs.FolderPath) == 0 { return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "FolderPath") } @@ -184,7 +185,7 @@ type AttrGetActions struct { } // Retrieves actions attached to specific ActionsId within cache -func (apiv2 *APIerSv2) GetActions(attr *AttrGetActions, reply *map[string]engine.Actions) error { +func (apiv2 *APIerSv2) GetActions(ctx *context.Context, attr *AttrGetActions, reply *map[string]engine.Actions) error { var actionKeys []string var err error if len(attr.ActionIDs) == 0 { @@ -236,7 +237,7 @@ type AttrGetActionsCount struct{} // GetActionsCount sets in reply var the total number of actions registered for the received tenant // returns ErrNotFound in case of 0 actions -func (apiv2 *APIerSv2) GetActionsCount(attr *AttrGetActionsCount, reply *int) (err error) { +func (apiv2 *APIerSv2) GetActionsCount(ctx *context.Context, attr *AttrGetActionsCount, reply *int) (err error) { var actionKeys []string if actionKeys, err = apiv2.DataManager.DataDB().GetKeysForPrefix(utils.ActionPrefix); err != nil { return err @@ -253,7 +254,7 @@ type AttrGetDestinations struct { } // GetDestinations returns a list of destination based on the destinationIDs given -func (apiv2 *APIerSv2) GetDestinations(attr *AttrGetDestinations, reply *[]*engine.Destination) (err error) { +func (apiv2 *APIerSv2) GetDestinations(ctx *context.Context, attr *AttrGetDestinations, reply *[]*engine.Destination) (err error) { if len(attr.DestinationIDs) == 0 { // get all destination ids if attr.DestinationIDs, err = apiv2.DataManager.DataDB().GetKeysForPrefix(utils.DestinationPrefix); err != nil { @@ -273,7 +274,7 @@ func (apiv2 *APIerSv2) GetDestinations(attr *AttrGetDestinations, reply *[]*engi return } -func (apiv2 *APIerSv2) SetActions(attrs *utils.AttrSetActions, reply *string) error { +func (apiv2 *APIerSv2) SetActions(ctx *context.Context, attrs *utils.AttrSetActions, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"ActionsId", "Actions"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -363,7 +364,7 @@ func (apiv2 *APIerSv2) SetActions(attrs *utils.AttrSetActions, reply *string) er return utils.NewErrServerError(err) } //CacheReload - if err := apiv2.ConnMgr.Call(apiv2.Config.ApierCfg().CachesConns, nil, + if err := apiv2.ConnMgr.Call(context.TODO(), apiv2.Config.ApierCfg().CachesConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ActionIDs: []string{attrs.ActionsId}, }, reply); err != nil { @@ -378,7 +379,7 @@ func (apiv2 *APIerSv2) SetActions(attrs *utils.AttrSetActions, reply *string) er } // Ping return pong if the service is active -func (apiv2 *APIerSv2) Ping(ign *utils.CGREvent, reply *string) error { +func (apiv2 *APIerSv2) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } diff --git a/apier/v2/apierv2_it_test.go b/apier/v2/apierv2_it_test.go index 26ee8642b..8b322d447 100644 --- a/apier/v2/apierv2_it_test.go +++ b/apier/v2/apierv2_it_test.go @@ -22,12 +22,13 @@ package v2 import ( "fmt" - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -37,7 +38,7 @@ import ( var ( apierCfgPath string apierCfg *config.CGRConfig - apierRPC *rpc.Client + apierRPC *birpc.Client dm *engine.DataManager // share db connection here so we can check data we set through APIs APIerSv2ConfDIR string @@ -142,11 +143,11 @@ func testAPIerSv2itAddBalance(t *testing.T) { }, } var reply string - if err := apierRPC.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } var acnt engine.Account - if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary][0].Value != 5.0 { t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary][0]) @@ -158,11 +159,11 @@ func testAPIerSv2itSetAction(t *testing.T) { {Identifier: utils.MetaDisableAccount, Weight: 10.0}, }} var reply string - if err := apierRPC.Call(utils.APIerSv2SetActions, &attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetActions, &attrs, &reply); err != nil { t.Error(err) } var acts map[string]engine.Actions - if err := apierRPC.Call(utils.APIerSv2GetActions, &AttrGetActions{ActionIDs: []string{attrs.ActionsId}}, &acts); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetActions, &AttrGetActions{ActionIDs: []string{attrs.ActionsId}}, &acts); err != nil { t.Error(err) } else if len(acts) != 1 { t.Errorf("Received actions: %+v", acts) @@ -184,20 +185,20 @@ func testAPIerSv2itSetAccountActionTriggers(t *testing.T) { }, } var reply string - if err := apierRPC.Call(utils.APIerSv2SetAccountActionTriggers, attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetAccountActionTriggers, attrs, &reply); err != nil { t.Error(err) } var ats engine.ActionTriggers - if err := apierRPC.Call(utils.APIerSv2GetAccountActionTriggers, utils.TenantAccount{Tenant: "cgrates.org", Account: "dan"}, &ats); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccountActionTriggers, utils.TenantAccount{Tenant: "cgrates.org", Account: "dan"}, &ats); err != nil { t.Error(err) } else if len(ats) != 1 || ats[0].ID != attrs.GroupID || ats[0].ThresholdValue != 50.0 { t.Errorf("Received: %+v", ats) } attrs.ActionTrigger[utils.ThresholdValue] = 55 // Change the threshold - if err := apierRPC.Call(utils.APIerSv2SetAccountActionTriggers, attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetAccountActionTriggers, attrs, &reply); err != nil { t.Error(err) } - if err := apierRPC.Call(utils.APIerSv2GetAccountActionTriggers, utils.TenantAccount{Tenant: "cgrates.org", Account: "dan"}, &ats); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccountActionTriggers, utils.TenantAccount{Tenant: "cgrates.org", Account: "dan"}, &ats); err != nil { t.Error(err) } else if len(ats) != 1 || ats[0].ID != attrs.GroupID || ats[0].ThresholdValue != 55.0 { t.Errorf("Received: %+v", ats) @@ -216,11 +217,11 @@ func testAPIerSv2itFraudMitigation(t *testing.T) { }, } var reply string - if err := apierRPC.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } var acnt engine.Account - if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaMonetary][0].Value != 60.0 { t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary][0]) @@ -234,11 +235,11 @@ func testAPIerSv2itFraudMitigation(t *testing.T) { utils.Disabled: false, }, } - if err := apierRPC.Call(utils.APIerSv2SetAccount, attrSetAcnt, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetAccount, attrSetAcnt, &reply); err != nil { t.Fatal(err) } acnt = engine.Account{} // gob doesn't update the fields with default values - if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaMonetary][0].Value != 60.0 { t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary][0]) @@ -254,7 +255,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { BalanceType: utils.MetaMonetary, Units: "5.0", Weight: 20.0}, }} var reply string - if err := apierRPC.Call(utils.APIerSv2SetActions, &argActs1, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetActions, &argActs1, &reply); err != nil { t.Error(err) } tNow := time.Now().Add(time.Minute) @@ -266,7 +267,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { if _, err := dm.GetActionPlan(argAP1.Id, false, true, utils.NonTransactional); err == nil || err != utils.ErrNotFound { t.Error(err) } - if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &argAP1, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &argAP1, &reply); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply) @@ -280,7 +281,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { if _, err := dm.GetAccountActionPlans(acntID, false, true, utils.NonTransactional); err == nil || err != utils.ErrNotFound { t.Error(err) } - if err := apierRPC.Call(utils.APIerSv2SetAccount, &argSetAcnt1, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetAccount, &argSetAcnt1, &reply); err != nil { t.Fatal(err) } if ap, err := dm.GetActionPlan(argAP1.Id, false, true, utils.NonTransactional); err != nil { @@ -301,7 +302,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { if _, err := dm.GetActionPlan(argAP2.Id, false, true, utils.NonTransactional); err == nil || err != utils.ErrNotFound { t.Error(err) } - if err := apierRPC.Call(utils.APIerSv2SetActionPlan, argAP2, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetActionPlan, argAP2, &reply); err != nil { t.Error("Got error on APIerSv2.SetActionPlan: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActionPlan received: %s", reply) @@ -312,7 +313,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { Account: "TestAPIerSv2itSetAccountWithAP1", ActionPlanIDs: []string{argAP2.Id}, } - if err := apierRPC.Call(utils.APIerSv2SetAccount, &argSetAcnt2, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetAccount, &argSetAcnt2, &reply); err != nil { t.Fatal(err) } if ap, err := dm.GetActionPlan(argAP2.Id, false, true, utils.NonTransactional); err != nil { @@ -338,7 +339,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { ActionPlanIDs: []string{argAP2.Id}, ActionPlansOverwrite: true, } - if err := apierRPC.Call(utils.APIerSv2SetAccount, &argSetAcnt2, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetAccount, &argSetAcnt2, &reply); err != nil { t.Fatal(err) } if ap, err := dm.GetActionPlan(argAP1.Id, false, true, utils.NonTransactional); err != nil { @@ -362,7 +363,7 @@ func testAPIerSv2itSetAccountWithAP(t *testing.T) { func testAPIerSv2itSetActionWithCategory(t *testing.T) { var reply string attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "TestAPIerSv2itSetActionWithCategory"} - if err := apierRPC.Call(utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -374,19 +375,19 @@ func testAPIerSv2itSetActionWithCategory(t *testing.T) { BalanceType: utils.MetaMonetary, Categories: "test", Units: "5.0", Weight: 20.0}, }} - if err := apierRPC.Call(utils.APIerSv2SetActions, &argActs1, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetActions, &argActs1, &reply); err != nil { t.Error(err) } attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: argActs1.ActionsId} - if err := apierRPC.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } var acnt engine.Account - if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "TestAPIerSv2itSetActionWithCategory"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaMonetary][0].Value != 5.0 { @@ -410,7 +411,7 @@ func testAPIerSv2itSetActionPlanWithWrongTiming(t *testing.T) { }, } - if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &argAP1, &reply); err == nil || + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &argAP1, &reply); err == nil || err.Error() != fmt.Sprintf("UNSUPPORTED_FORMAT:%s", tNow) { t.Error("Expecting error ", err) } @@ -428,7 +429,7 @@ func testAPIerSv2itSetActionPlanWithWrongTiming2(t *testing.T) { }, } - if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &argAP1, &reply); err == nil || + if err := apierRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &argAP1, &reply); err == nil || err.Error() != fmt.Sprintf("UNSUPPORTED_FORMAT:aa:bb:cc") { t.Error("Expecting error ", err) } @@ -436,7 +437,7 @@ func testAPIerSv2itSetActionPlanWithWrongTiming2(t *testing.T) { func testAPIerSv2itBackwardsCompatible(t *testing.T) { var reply string - if err := apierRPC.Call("ApierV2.Ping", new(utils.CGREvent), &reply); err != nil { + if err := apierRPC.Call(context.Background(), "ApierV2.Ping", new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Expecting : %+v, received: %+v", utils.Pong, reply) @@ -445,26 +446,26 @@ func testAPIerSv2itBackwardsCompatible(t *testing.T) { func testAPIerSv2itGetAccountsCount(t *testing.T) { var reply1 int - if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{ + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{ Tenant: "cgrates.org"}, &reply1); err != nil { t.Error(err) } else if reply1 != 3 { t.Errorf("Expecting: 3, received: %+v", reply1) } var reply string - if err := apierRPC.Call(utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ + if err := apierRPC.Call(context.Background(), utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ Account: "dan", Tenant: "cgrates.org"}, &reply); err != nil { t.Errorf("Unexpected error : %+v", err) } - if err := apierRPC.Call(utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ + if err := apierRPC.Call(context.Background(), utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ Account: "TestAPIerSv2itSetAccountWithAP1", Tenant: "cgrates.org"}, &reply); err != nil { t.Errorf("Unexpected error : %+v", err) } - if err := apierRPC.Call(utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ + if err := apierRPC.Call(context.Background(), utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ Account: "TestAPIerSv2itSetActionWithCategory", Tenant: "cgrates.org"}, &reply); err != nil { t.Errorf("Unexpected error : %+v", err) } - if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{ + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{ Tenant: "cgrates.org"}, &reply1); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting %+v, received: %+v", utils.ErrNotFound, err) } @@ -472,15 +473,15 @@ func testAPIerSv2itGetAccountsCount(t *testing.T) { Tenant: "cgrates.org", Account: "TestAPIerSv2CountAccounts", } - if err := apierRPC.Call(utils.APIerSv2SetAccount, &argSetAccount, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetAccount, &argSetAccount, &reply); err != nil { t.Fatal(err) } var acnt engine.Account - if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{ + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: "cgrates.org", Account: "TestAPIerSv2CountAccounts"}, &acnt); err != nil { t.Error(err) } - if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{Tenant: "cgrates.org"}, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{Tenant: "cgrates.org"}, &reply1); err != nil { t.Error(err) } else if reply1 != 1 { t.Errorf("Expecting: 1, received: %+v", reply1) @@ -489,32 +490,32 @@ func testAPIerSv2itGetAccountsCount(t *testing.T) { Tenant: "cgrates.org", Account: "TestAPIerSv2CountAccounts2", } - if err := apierRPC.Call(utils.APIerSv2SetAccount, &argSetAccount, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetAccount, &argSetAccount, &reply); err != nil { t.Fatal(err) } - if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{ + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: "cgrates.org", Account: "TestAPIerSv2CountAccounts2"}, &acnt); err != nil { t.Error(err) } - if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{Tenant: "cgrates.org"}, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{Tenant: "cgrates.org"}, &reply1); err != nil { t.Error(err) } else if reply1 != 2 { t.Errorf("Expecting: 2, received: %+v", reply1) } - if err := apierRPC.Call(utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ + if err := apierRPC.Call(context.Background(), utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ Account: "TestAPIerSv2CountAccounts2", Tenant: "cgrates.org"}, &reply); err != nil { t.Errorf("Unexpected error : %+v", err) } - if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{Tenant: "cgrates.org"}, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{Tenant: "cgrates.org"}, &reply1); err != nil { t.Error(err) } else if reply1 != 1 { t.Errorf("Expecting: 1, received: %+v", reply1) } - if err := apierRPC.Call(utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ + if err := apierRPC.Call(context.Background(), utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{ Account: "TestAPIerSv2CountAccounts", Tenant: "cgrates.org"}, &reply); err != nil { t.Errorf("Unexpected error : %+v", err) } - if err := apierRPC.Call(utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{ + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetAccountsCount, &utils.AttrGetAccountsCount{ Tenant: "cgrates.org"}, &reply1); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting %+v, received: %+v", utils.ErrNotFound, err) } @@ -522,7 +523,7 @@ func testAPIerSv2itGetAccountsCount(t *testing.T) { func testAPIerSv2itGetActionsCount(t *testing.T) { var reply1 int - if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil { t.Error(err) } else if reply1 != 3 { t.Errorf("Expecting: 3, received : %+v", reply1) @@ -531,10 +532,10 @@ func testAPIerSv2itGetActionsCount(t *testing.T) { {Identifier: utils.MetaDisableAccount, Weight: 0.7}, }} var reply string - if err := apierRPC.Call(utils.APIerSv2SetActions, &attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetActions, &attrs, &reply); err != nil { t.Error(err) } - if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil { t.Error(err) } else if reply1 != 4 { t.Errorf("Expecting: 4, received : %+v", reply1) @@ -543,10 +544,10 @@ func testAPIerSv2itGetActionsCount(t *testing.T) { attrRemoveActions := &v1.AttrRemoveActions{ ActionIDs: []string{"DISABLE_ACCOUNT", "DISABLE_ACCOUNT2", "TestAPIerSv2itSetAccountWithAP_ACT_1"}, } - if err := apierRPC.Call(utils.APIerSv2RemoveActions, &attrRemoveActions, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2RemoveActions, &attrRemoveActions, &reply); err != nil { t.Error(err) } - if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil { t.Error(err) } else if reply1 != 1 { t.Errorf("Expecting: 1, received : %+v", reply1) @@ -554,19 +555,19 @@ func testAPIerSv2itGetActionsCount(t *testing.T) { attrRemoveActions = &v1.AttrRemoveActions{ ActionIDs: []string{"TestAPIerSv2itSetActionWithCategory_ACT"}, } - if err := apierRPC.Call(utils.APIerSv2RemoveActions, &attrRemoveActions, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2RemoveActions, &attrRemoveActions, &reply); err != nil { t.Error(err) } - if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting %+v, received: %+v", utils.ErrNotFound, err) } attrs = utils.AttrSetActions{ActionsId: "Test", Actions: []*utils.TPAction{ {Identifier: utils.MetaDisableAccount, Weight: 0.7}, }} - if err := apierRPC.Call(utils.APIerSv2SetActions, &attrs, &reply); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2SetActions, &attrs, &reply); err != nil { t.Error(err) } - if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil { + if err := apierRPC.Call(context.Background(), utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil { t.Error(err) } else if reply1 != 1 { t.Errorf("Expecting: 1, received : %+v", reply1) diff --git a/apier/v2/attributes.go b/apier/v2/attributes.go index db907a81d..badd917bf 100644 --- a/apier/v2/attributes.go +++ b/apier/v2/attributes.go @@ -21,6 +21,7 @@ package v2 import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -31,7 +32,7 @@ type AttributeWithAPIOpts struct { } // SetAttributeProfile add/update a new Attribute Profile -func (APIerSv2 *APIerSv2) SetAttributeProfile(arg *AttributeWithAPIOpts, reply *string) error { +func (APIerSv2 *APIerSv2) SetAttributeProfile(ctx *context.Context, arg *AttributeWithAPIOpts, reply *string) error { if missing := utils.MissingStructFields(arg.APIAttributeProfile, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v2/attributes_it_test.go b/apier/v2/attributes_it_test.go index 6592422f4..abe2aa00c 100644 --- a/apier/v2/attributes_it_test.go +++ b/apier/v2/attributes_it_test.go @@ -22,13 +22,15 @@ along with this program. If not, see package v2 import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +39,7 @@ import ( var ( alsPrfCfgPath string alsPrfCfg *config.CGRConfig - attrSRPC *rpc.Client + attrSRPC *birpc.Client alsPrfConfigDIR string //run tests for specific configuration sTestsAlsPrf = []func(t *testing.T){ @@ -132,7 +134,7 @@ func testAttributeSSetAlsPrf(t *testing.T) { }, } var result string - if err := attrSRPC.Call(utils.APIerSv2SetAttributeProfile, extAlsPrf, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv2SetAttributeProfile, extAlsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -159,7 +161,7 @@ func testAttributeSSetAlsPrf(t *testing.T) { } alsPrf.Compile() var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ExternalAttribute"}}, &reply); err != nil { t.Fatal(err) } @@ -194,7 +196,7 @@ func testAttributeSUpdateAlsPrf(t *testing.T) { }, } var result string - if err := attrSRPC.Call(utils.APIerSv2SetAttributeProfile, extAlsPrf, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv2SetAttributeProfile, extAlsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -226,7 +228,7 @@ func testAttributeSUpdateAlsPrf(t *testing.T) { sort.Strings(alsPrf.AttributeProfile.Contexts) alsPrf.Compile() var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ExternalAttribute"}}, &reply); err != nil { t.Fatal(err) } @@ -263,7 +265,7 @@ func testAttributeSSetAlsPrfWithoutTenant(t *testing.T) { }, } var result string - if err := attrSRPC.Call(utils.APIerSv2SetAttributeProfile, extAlsPrf, &result); err != nil { + if err := attrSRPC.Call(context.Background(), utils.APIerSv2SetAttributeProfile, extAlsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -290,7 +292,7 @@ func testAttributeSSetAlsPrfWithoutTenant(t *testing.T) { } alsPrf.Compile() var reply *engine.AttributeProfile - if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrSRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "ExternalAttribute"}}, &reply); err != nil { t.Fatal(err) } diff --git a/apier/v2/cdrs.go b/apier/v2/cdrs.go index 7558b9430..cc3a4c594 100644 --- a/apier/v2/cdrs.go +++ b/apier/v2/cdrs.go @@ -19,6 +19,7 @@ along with this program. If not, see package v2 import ( + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/engine" @@ -26,7 +27,7 @@ import ( ) // Retrieves CDRs based on the filters -func (apier *APIerSv2) GetCDRs(attrs *utils.RPCCDRsFilter, reply *[]*engine.ExternalCDR) error { +func (apier *APIerSv2) GetCDRs(ctx *context.Context, attrs *utils.RPCCDRsFilter, reply *[]*engine.ExternalCDR) error { cdrsFltr, err := attrs.AsCDRsFilter(apier.Config.GeneralCfg().DefaultTimezone) if err != nil { return utils.NewErrServerError(err) @@ -46,7 +47,7 @@ func (apier *APIerSv2) GetCDRs(attrs *utils.RPCCDRsFilter, reply *[]*engine.Exte return nil } -func (apier *APIerSv2) CountCDRs(attrs *utils.RPCCDRsFilter, reply *int64) error { +func (apier *APIerSv2) CountCDRs(ctx *context.Context, attrs *utils.RPCCDRsFilter, reply *int64) error { cdrsFltr, err := attrs.AsCDRsFilter(apier.Config.GeneralCfg().DefaultTimezone) if err != nil { if err.Error() != utils.NotFoundCaps { @@ -68,11 +69,11 @@ type CDRsV2 struct { v1.CDRsV1 } -func (cdrSv2 *CDRsV2) StoreSessionCost(args *engine.ArgsV2CDRSStoreSMCost, reply *string) error { - return cdrSv2.CDRs.V2StoreSessionCost(args, reply) +func (cdrSv2 *CDRsV2) StoreSessionCost(ctx *context.Context, args *engine.ArgsV2CDRSStoreSMCost, reply *string) error { + return cdrSv2.CDRs.V2StoreSessionCost(ctx, args, reply) } // ProcessEvent will process an Event based on the flags attached -func (cdrSv2 *CDRsV2) ProcessEvent(arg *engine.ArgV1ProcessEvent, evs *[]*utils.EventWithFlags) error { - return cdrSv2.CDRs.V2ProcessEvent(arg, evs) +func (cdrSv2 *CDRsV2) ProcessEvent(ctx *context.Context, arg *engine.ArgV1ProcessEvent, evs *[]*utils.EventWithFlags) error { + return cdrSv2.CDRs.V2ProcessEvent(ctx, arg, evs) } diff --git a/apier/v2/cdrs_it_test.go b/apier/v2/cdrs_it_test.go index 4bf0b7418..67f522a63 100644 --- a/apier/v2/cdrs_it_test.go +++ b/apier/v2/cdrs_it_test.go @@ -21,13 +21,14 @@ along with this program. If not, see package v2 import ( - "net/rpc" "path" "reflect" "sync" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -37,7 +38,7 @@ import ( var ( cdrsCfgPath string cdrsCfg *config.CGRConfig - cdrsRpc *rpc.Client + cdrsRpc *birpc.Client cdrsConfDIR string // run the tests for specific configuration // subtests to be executed for each confDIR @@ -139,7 +140,7 @@ func testV2CDRsRpcConn(t *testing.T) { func testV2CDRsLoadTariffPlanFromFolder(t *testing.T) { var loadInst utils.LoadInstance - if err := cdrsRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, &utils.AttrLoadTpFromFolder{FolderPath: path.Join( *dataDir, "tariffplans", "testit")}, &loadInst); err != nil { t.Error(err) @@ -170,7 +171,7 @@ func testV2CDRsProcessCDR(t *testing.T) { } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -180,14 +181,14 @@ func testV2CDRsProcessCDR(t *testing.T) { func testV2CDRsGetCdrs(t *testing.T) { var cdrCnt int64 req := utils.AttrGetCdrs{} - if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 3 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) } var cdrs []*engine.ExternalCDR args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -201,7 +202,7 @@ func testV2CDRsGetCdrs(t *testing.T) { } } args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -215,7 +216,7 @@ func testV2CDRsGetCdrs(t *testing.T) { } } args = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -248,7 +249,7 @@ func testV2CDRsRateCDRs(t *testing.T) { }, }, } - if err := cdrsRpc.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err) } else if !reflect.DeepEqual(expected, rpl) { t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) @@ -265,7 +266,7 @@ func testV2CDRsRateCDRs(t *testing.T) { Overwrite: true, } var reply string - if err := cdrsRpc.Call(utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply) @@ -280,13 +281,13 @@ func testV2CDRsRateCDRs(t *testing.T) { }, }, } - if err := cdrsRpc.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil { t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err) } else if !reflect.DeepEqual(expected, rpl) { t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl)) } - if err := cdrsRpc.Call(utils.CDRsV1RateCDRs, &engine.ArgRateCDRs{ + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1RateCDRs, &engine.ArgRateCDRs{ RPCCDRsFilter: utils.RPCCDRsFilter{NotRunIDs: []string{"raw"}}, Flags: []string{"*chargers:false", utils.MetaRerate}, }, &reply); err != nil { @@ -299,14 +300,14 @@ func testV2CDRsRateCDRs(t *testing.T) { func testV2CDRsGetCdrs2(t *testing.T) { var cdrCnt int64 req := utils.AttrGetCdrs{} - if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 3 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) } var cdrs []*engine.ExternalCDR args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -316,7 +317,7 @@ func testV2CDRsGetCdrs2(t *testing.T) { } } args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -326,7 +327,7 @@ func testV2CDRsGetCdrs2(t *testing.T) { } } args = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -359,7 +360,7 @@ func testV2CDRsUsageNegative(t *testing.T) { }, } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsCdr, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsCdr, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -367,7 +368,7 @@ func testV2CDRsUsageNegative(t *testing.T) { var cdrs []*engine.ExternalCDR args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}, OriginIDs: []string{"testV2CDRsUsageNegative"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -381,7 +382,7 @@ func testV2CDRsUsageNegative(t *testing.T) { } cdrs = nil // gob doesn't modify zero-value fields args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"testV2CDRsUsageNegative"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -395,7 +396,7 @@ func testV2CDRsUsageNegative(t *testing.T) { } cdrs = nil // gob doesn't modify zero-value fields args = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}, OriginIDs: []string{"testV2CDRsUsageNegative"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -449,13 +450,13 @@ func testV2CDRsDifferentTenants(t *testing.T) { } alsPrf.Compile() var result string - if err := cdrsRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.AttributeProfile - if err := cdrsRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.com", ID: "ATTR_Tenant"}}, &reply); err != nil { t.Fatal(err) } @@ -480,13 +481,13 @@ func testV2CDRsDifferentTenants(t *testing.T) { utils.CacheOpt: utils.MetaReload, }, } - if err := cdrsRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply2 *engine.ChargerProfile - if err := cdrsRpc.Call(utils.APIerSv1GetChargerProfile, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "CustomTenant", ID: "CustomCharger"}, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply2) { @@ -514,7 +515,7 @@ func testV2CDRsDifferentTenants(t *testing.T) { }, } var reply3 string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsCdr, &reply3); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsCdr, &reply3); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply3 != utils.OK { t.Error("Unexpected reply received: ", reply3) @@ -522,7 +523,7 @@ func testV2CDRsDifferentTenants(t *testing.T) { var cdrs []*engine.ExternalCDR args := utils.RPCCDRsFilter{Tenants: []string{"CustomTenant"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { // no raw Charger defined t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -531,7 +532,7 @@ func testV2CDRsDifferentTenants(t *testing.T) { func testV2CDRsRemoveRatingProfiles(t *testing.T) { var reply string - if err := cdrsRpc.Call(utils.APIerSv1RemoveRatingProfile, &v1.AttrRemoveRatingProfile{ + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1RemoveRatingProfile, &v1.AttrRemoveRatingProfile{ Tenant: "cgrates.org", Category: utils.Call, Subject: utils.MetaAny, @@ -540,7 +541,7 @@ func testV2CDRsRemoveRatingProfiles(t *testing.T) { } else if reply != utils.OK { t.Errorf("Expected: %s, received: %s ", utils.OK, reply) } - if err := cdrsRpc.Call(utils.APIerSv1RemoveRatingProfile, &v1.AttrRemoveRatingProfile{ + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1RemoveRatingProfile, &v1.AttrRemoveRatingProfile{ Tenant: "cgrates.org", Category: utils.Call, Subject: "SUPPLIER1", @@ -573,7 +574,7 @@ func testV2CDRsProcessCDRNoRattingPlan(t *testing.T) { } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -583,14 +584,14 @@ func testV2CDRsProcessCDRNoRattingPlan(t *testing.T) { func testV2CDRsGetCdrsNoRattingPlan(t *testing.T) { var cdrCnt int64 req := utils.AttrGetCdrs{} - if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 10 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) } var cdrs []*engine.ExternalCDR args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}, Accounts: []string{"testV2CDRsProcessCDR4"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -600,7 +601,7 @@ func testV2CDRsGetCdrsNoRattingPlan(t *testing.T) { } } args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, Accounts: []string{"testV2CDRsProcessCDR4"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -613,7 +614,7 @@ func testV2CDRsGetCdrsNoRattingPlan(t *testing.T) { } } args = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}, Accounts: []string{"testV2CDRsProcessCDR4"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -640,7 +641,7 @@ func testV2CDRsRateCDRsWithRatingPlan(t *testing.T) { Overwrite: true, } var reply string - if err := cdrsRpc.Call(utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply) @@ -656,13 +657,13 @@ func testV2CDRsRateCDRsWithRatingPlan(t *testing.T) { RatingPlanId: "RP_TESTIT1"}}, Overwrite: true, } - if err := cdrsRpc.Call(utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil { t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply) } - if err := cdrsRpc.Call(utils.CDRsV1RateCDRs, &engine.ArgRateCDRs{ + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1RateCDRs, &engine.ArgRateCDRs{ RPCCDRsFilter: utils.RPCCDRsFilter{NotRunIDs: []string{"raw"}, Accounts: []string{"testV2CDRsProcessCDR4"}}, Flags: []string{"*chargers:true", utils.MetaRerate}, }, &reply); err != nil { @@ -675,14 +676,14 @@ func testV2CDRsRateCDRsWithRatingPlan(t *testing.T) { func testV2CDRsGetCdrsWithRatingPlan(t *testing.T) { var cdrCnt int64 req := utils.AttrGetCdrs{} - if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 10 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) } var cdrs []*engine.ExternalCDR args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}, Accounts: []string{"testV2CDRsProcessCDR4"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -693,7 +694,7 @@ func testV2CDRsGetCdrsWithRatingPlan(t *testing.T) { } cdrs = []*engine.ExternalCDR{} // gob will not update zero value fields args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, Accounts: []string{"testV2CDRsProcessCDR4"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -707,7 +708,7 @@ func testV2CDRsGetCdrsWithRatingPlan(t *testing.T) { } cdrs = []*engine.ExternalCDR{} // gob will not update zero value fields args = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}, Accounts: []string{"testV2CDRsProcessCDR4"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -723,7 +724,7 @@ func testV2CDRsGetCdrsWithRatingPlan(t *testing.T) { func testV2CDRsSetThreshold(t *testing.T) { var reply string - if err := cdrsRpc.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{ + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2SetActions, &utils.AttrSetActions{ ActionsId: "ACT_LOG", Actions: []*utils.TPAction{{Identifier: utils.MetaLog}}, }, &reply); err != nil && err.Error() != utils.ErrExists.Error() { @@ -744,7 +745,7 @@ func testV2CDRsSetThreshold(t *testing.T) { ActionIDs: []string{"ACT_LOG"}, }, } - if err := cdrsRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -756,7 +757,7 @@ func testV2CDRsSetThreshold(t *testing.T) { utils.AllowNegative: true, }, } - if err := cdrsRpc.Call(utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { t.Fatal(err) } attrs := &utils.AttrSetBalance{ @@ -769,7 +770,7 @@ func testV2CDRsSetThreshold(t *testing.T) { utils.Weight: 10.0, }, } - if err := cdrsRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } } @@ -796,7 +797,7 @@ func testV2CDRsProcessCDRWithThreshold(t *testing.T) { }, } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -805,7 +806,7 @@ func testV2CDRsProcessCDRWithThreshold(t *testing.T) { func testV2CDRsGetThreshold(t *testing.T) { var td engine.Threshold - if err := cdrsRpc.Call(utils.ThresholdSv1GetThreshold, + if err := cdrsRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &td); err != nil { t.Error(err) } else if td.Hits != 1 { @@ -836,14 +837,14 @@ func testv2CDRsGetCDRsDest(t *testing.T) { }, } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } var cdrs []*engine.ExternalCDR - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{DestinationPrefixes: []string{"+4915117174963"}}, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{DestinationPrefixes: []string{"+4915117174963"}}, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 3 { @@ -853,7 +854,7 @@ func testv2CDRsGetCDRsDest(t *testing.T) { func testV2CDRsRerate(t *testing.T) { var reply string - if err := cdrsRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := cdrsRpc.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ CacheIDs: nil, }, &reply); err != nil { t.Error(err) @@ -876,7 +877,7 @@ func testV2CDRsRerate(t *testing.T) { utils.CacheOpt: utils.MetaReload, }, } - if err := cdrsRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -886,7 +887,7 @@ func testV2CDRsRerate(t *testing.T) { Tenant: "cgrates.org", Account: "voiceAccount", } - if err := cdrsRpc.Call(utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { t.Fatal(err) } attrs := &utils.AttrSetBalance{ @@ -900,12 +901,12 @@ func testV2CDRsRerate(t *testing.T) { utils.Weight: 10.0, }, } - if err := cdrsRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } var acnt *engine.Account - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "voiceAccount"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 600000000000 { @@ -933,11 +934,11 @@ func testV2CDRsRerate(t *testing.T) { } var rplProcEv []*utils.EventWithFlags - if err := cdrsRpc.Call(utils.CDRsV2ProcessEvent, args, &rplProcEv); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV2ProcessEvent, args, &rplProcEv); err != nil { t.Error("Unexpected error: ", err.Error()) } - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "voiceAccount"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 480000000000 { @@ -964,11 +965,11 @@ func testV2CDRsRerate(t *testing.T) { }, } - if err := cdrsRpc.Call(utils.CDRsV2ProcessEvent, args2, &rplProcEv); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV2ProcessEvent, args2, &rplProcEv); err != nil { t.Error("Unexpected error: ", err.Error()) } - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "voiceAccount"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 540000000000 { @@ -978,7 +979,7 @@ func testV2CDRsRerate(t *testing.T) { func testv2CDRsDynaPrepaid(t *testing.T) { var acnt engine.Account - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "CreatedAccount"}, &acnt); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -1003,13 +1004,13 @@ func testv2CDRsDynaPrepaid(t *testing.T) { } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "CreatedAccount"}, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary][0].Value != 9.9694 { @@ -1019,7 +1020,7 @@ func testv2CDRsDynaPrepaid(t *testing.T) { func testV2CDRsDuplicateCDRs(t *testing.T) { var reply string - if err := cdrsRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := cdrsRpc.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ CacheIDs: nil, }, &reply); err != nil { t.Error(err) @@ -1042,7 +1043,7 @@ func testV2CDRsDuplicateCDRs(t *testing.T) { utils.CacheOpt: utils.MetaReload, }, } - if err := cdrsRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -1052,7 +1053,7 @@ func testV2CDRsDuplicateCDRs(t *testing.T) { Tenant: "cgrates.org", Account: "testV2CDRsDuplicateCDRs", } - if err := cdrsRpc.Call(utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { t.Fatal(err) } attrs := &utils.AttrSetBalance{ @@ -1066,12 +1067,12 @@ func testV2CDRsDuplicateCDRs(t *testing.T) { utils.Weight: 10.0, }, } - if err := cdrsRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } var acnt *engine.Account - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV2CDRsDuplicateCDRs"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 600000000000 { @@ -1099,11 +1100,11 @@ func testV2CDRsDuplicateCDRs(t *testing.T) { } var rplProcEv []*utils.EventWithFlags - if err := cdrsRpc.Call(utils.CDRsV2ProcessEvent, args, &rplProcEv); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV2ProcessEvent, args, &rplProcEv); err != nil { t.Error("Unexpected error: ", err.Error()) } - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV2CDRsDuplicateCDRs"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 480000000000 { @@ -1134,7 +1135,7 @@ func testV2CDRsDuplicateCDRs(t *testing.T) { }, }, } - if err := cdrsRpc.Call(utils.CDRsV2ProcessEvent, args2, &rplProcEv); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV2ProcessEvent, args2, &rplProcEv); err != nil { t.Error("Unexpected error: ", err.Error()) } wg.Done() @@ -1142,7 +1143,7 @@ func testV2CDRsDuplicateCDRs(t *testing.T) { } wg.Wait() - if err := cdrsRpc.Call(utils.APIerSv2GetAccount, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV2CDRsDuplicateCDRs"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 540000000000 { @@ -1158,7 +1159,7 @@ func testV2CDRsKillEngine(t *testing.T) { func testV2CDRsResetThresholdAction(t *testing.T) { var reply string - if err := cdrsRpc.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{ + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2SetActions, &utils.AttrSetActions{ ActionsId: "ACT_RESET_THD", Actions: []*utils.TPAction{{Identifier: utils.MetaResetThreshold, ExtraParameters: "cgrates.org:THD_Test"}}, }, &reply); err != nil { @@ -1167,11 +1168,11 @@ func testV2CDRsResetThresholdAction(t *testing.T) { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrs := utils.AttrExecuteAction{Tenant: "cgrates.org", ActionsId: "ACT_RESET_THD"} - if err := cdrsRpc.Call(utils.APIerSv1ExecuteAction, attrs, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrs, &reply); err != nil { t.Error(err) } var td engine.Threshold - if err := cdrsRpc.Call(utils.ThresholdSv1GetThreshold, + if err := cdrsRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &td); err != nil { t.Error(err) } else if td.Hits != 0 { diff --git a/apier/v2/cdrs_offline_it_test.go b/apier/v2/cdrs_offline_it_test.go index 0113ba6f5..c1e39f302 100644 --- a/apier/v2/cdrs_offline_it_test.go +++ b/apier/v2/cdrs_offline_it_test.go @@ -21,12 +21,14 @@ along with this program. If not, see package v2 import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" @@ -37,7 +39,7 @@ import ( var ( cdrsOfflineCfgPath string cdrsOfflineCfg *config.CGRConfig - cdrsOfflineRpc *rpc.Client + cdrsOfflineRpc *birpc.Client cdrsOfflineConfDIR string // run the tests for specific configuration // subtests to be executed for each confDIR @@ -111,7 +113,7 @@ func testV2cdrsOfflineRpcConn(t *testing.T) { func testV2CDRsOfflineLoadData(t *testing.T) { var loadInst utils.LoadInstance - if err := cdrsOfflineRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, &utils.AttrLoadTpFromFolder{FolderPath: path.Join( *dataDir, "tariffplans", "testit")}, &loadInst); err != nil { t.Error(err) @@ -132,11 +134,11 @@ func testV2CDRsOfflineBalanceUpdate(t *testing.T) { }, } var reply string - if err := cdrsOfflineRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } var acnt *engine.Account - if err := cdrsOfflineRpc.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "test"}, &acnt); err != nil { + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "test"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaMonetary][0].Value != 10.0 { t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary][0]) @@ -149,13 +151,13 @@ func testV2CDRsOfflineBalanceUpdate(t *testing.T) { attrsAA := &utils.AttrSetActions{ActionsId: "ACT_LOG", Actions: []*utils.TPAction{ {Identifier: utils.MetaLog}, }} - if err := cdrsOfflineRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } //make sure that the threshold don't exit - if err := cdrsOfflineRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &thReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -174,12 +176,12 @@ func testV2CDRsOfflineBalanceUpdate(t *testing.T) { Async: false, }, } - if err := cdrsOfflineRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := cdrsOfflineRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &thReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, thReply) { @@ -207,7 +209,7 @@ func testV2CDRsOfflineBalanceUpdate(t *testing.T) { t.Error("Unexpected error received: ", err) } //process cdr should trigger balance update event - if err := cdrsOfflineRpc.Call(utils.CDRsV1ProcessCDR, &engine.CDRWithAPIOpts{CDR: cdr}, &reply); err != nil { + if err := cdrsOfflineRpc.Call(context.Background(), utils.CDRsV1ProcessCDR, &engine.CDRWithAPIOpts{CDR: cdr}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -224,7 +226,7 @@ func testV2CDRsOfflineExpiryBalance(t *testing.T) { {Identifier: utils.MetaTopUp, BalanceType: utils.MetaMonetary, BalanceId: "NewBalance", Units: "10", ExpiryTime: utils.MetaUnlimited, BalanceWeight: "10", Weight: 20.0}, }} - if err := cdrsOfflineRpc.Call(utils.APIerSv2SetActions, acc, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2SetActions, acc, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -232,13 +234,13 @@ func testV2CDRsOfflineExpiryBalance(t *testing.T) { atm1 := &v1.AttrActionPlan{ActionsId: "ACT_TOPUP_TEST2", Time: "*asap", Weight: 20.0} atms1 := &v1.AttrSetActionPlan{Id: "AP_TEST2", ActionPlan: []*v1.AttrActionPlan{atm1}} - if err := cdrsOfflineRpc.Call(utils.APIerSv1SetActionPlan, &atms1, &reply); err != nil { + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv1SetActionPlan, &atms1, &reply); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply) } - if err := cdrsOfflineRpc.Call(utils.APIerSv2SetAccount, + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2SetAccount, &AttrSetAccount{Tenant: "cgrates.org", Account: "test2", ActionPlanIDs: []string{"AP_TEST2"}, ReloadScheduler: true}, &reply); err != nil { @@ -249,7 +251,7 @@ func testV2CDRsOfflineExpiryBalance(t *testing.T) { var acnt *engine.Account //verify if the third balance was added - if err := cdrsOfflineRpc.Call(utils.APIerSv2GetAccount, + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "test2"}, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].Len() != 1 { @@ -263,13 +265,13 @@ func testV2CDRsOfflineExpiryBalance(t *testing.T) { attrsA := &utils.AttrSetActions{ActionsId: "ACT_LOG", Actions: []*utils.TPAction{ {Identifier: utils.MetaLog}, }} - if err := cdrsOfflineRpc.Call(utils.APIerSv2SetActions, attrsA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } //make sure that the threshold don't exit - if err := cdrsOfflineRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test2"}, &thReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -292,12 +294,12 @@ func testV2CDRsOfflineExpiryBalance(t *testing.T) { Async: false, }, } - if err := cdrsOfflineRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := cdrsOfflineRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test2"}, &thReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, thReply) { @@ -322,7 +324,7 @@ func testV2CDRsOfflineExpiryBalance(t *testing.T) { }, } //process cdr should trigger balance update event - if err := cdrsOfflineRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsOfflineRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -342,15 +344,15 @@ func testV2CDRsBalancesWithSameWeight(t *testing.T) { }, } var reply string - if err := cdrsOfflineRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } attrs.Balance[utils.ID] = "SpecialBalance2" - if err := cdrsOfflineRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } var acnt *engine.Account - if err := cdrsOfflineRpc.Call(utils.APIerSv2GetAccount, + if err := cdrsOfflineRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "specialTest"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || len(acnt.BalanceMap[utils.MetaMonetary]) != 2 { @@ -378,7 +380,7 @@ func testV2CDRsBalancesWithSameWeight(t *testing.T) { t.Error("Unexpected error received: ", err) } //process cdr should trigger balance update event - if err := cdrsOfflineRpc.Call(utils.CDRsV1ProcessCDR, &engine.CDRWithAPIOpts{CDR: cdr}, &reply); err != nil { + if err := cdrsOfflineRpc.Call(context.Background(), utils.CDRsV1ProcessCDR, &engine.CDRWithAPIOpts{CDR: cdr}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) diff --git a/apier/v2/dispatcher.go b/apier/v2/dispatcher.go index 705af186d..1c9402701 100644 --- a/apier/v2/dispatcher.go +++ b/apier/v2/dispatcher.go @@ -19,6 +19,7 @@ along with this program. If not, see package v2 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -33,10 +34,10 @@ type DispatcherSCDRsV2 struct { dS *dispatchers.DispatcherService } -func (dS *DispatcherSCDRsV2) StoreSessionCost(args *engine.ArgsV2CDRSStoreSMCost, reply *string) error { - return dS.dS.CDRsV2StoreSessionCost(args, reply) +func (dS *DispatcherSCDRsV2) StoreSessionCost(ctx *context.Context, args *engine.ArgsV2CDRSStoreSMCost, reply *string) error { + return dS.dS.CDRsV2StoreSessionCost(ctx, args, reply) } -func (dS *DispatcherSCDRsV2) ProcessEvent(args *engine.ArgV1ProcessEvent, reply *[]*utils.EventWithFlags) error { - return dS.dS.CDRsV2ProcessEvent(args, reply) +func (dS *DispatcherSCDRsV2) ProcessEvent(ctx *context.Context, args *engine.ArgV1ProcessEvent, reply *[]*utils.EventWithFlags) error { + return dS.dS.CDRsV2ProcessEvent(ctx, args, reply) } diff --git a/apier/v2/lib_test.go b/apier/v2/lib_test.go index 8bdd01564..e2636c3fc 100644 --- a/apier/v2/lib_test.go +++ b/apier/v2/lib_test.go @@ -21,9 +21,9 @@ package v2 import ( "errors" "flag" - "net/rpc" - "net/rpc/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -35,12 +35,12 @@ var ( dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/apier/v2/tp_it_test.go b/apier/v2/tp_it_test.go index df9ae5d27..543881d1a 100644 --- a/apier/v2/tp_it_test.go +++ b/apier/v2/tp_it_test.go @@ -22,11 +22,13 @@ along with this program. If not, see package v2 import ( - "net/rpc" "path" "reflect" "testing" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -36,7 +38,7 @@ import ( var ( tpCfgPath string tpCfg *config.CGRConfig - tpRPC *rpc.Client + tpRPC *birpc.Client err error delay int configDIR string // relative path towards a config directory under samples prefix @@ -174,7 +176,7 @@ func testTPitTimings(t *testing.T) { // Test set var reply string for _, tm := range []*utils.ApierTPTiming{tmPeak, tmOffPeakMorning, tmOffPeakEvening, tmOffPeakWeekend, tmDummyRemove} { - if err := tpRPC.Call(utils.APIerSv2SetTPTiming, tm, &reply); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2SetTPTiming, tm, &reply); err != nil { t.Error("Got error on APIerSv2.SetTPTiming: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv2.SetTPTiming: ", reply) @@ -182,20 +184,20 @@ func testTPitTimings(t *testing.T) { } // Test get var rplyTmDummy *utils.ApierTPTiming - if err := tpRPC.Call(utils.APIerSv2GetTPTiming, v1.AttrGetTPTiming{tmDummyRemove.TPid, tmDummyRemove.ID}, &rplyTmDummy); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetTPTiming, v1.AttrGetTPTiming{tmDummyRemove.TPid, tmDummyRemove.ID}, &rplyTmDummy); err != nil { t.Error("Calling APIerSv2.GetTPTiming, got error: ", err.Error()) } else if !reflect.DeepEqual(tmDummyRemove, rplyTmDummy) { t.Errorf("Calling APIerSv2.GetTPTiming expected: %v, received: %v", tmDummyRemove, rplyTmDummy) } var rplyTmIDs []string expectedTmIDs := []string{"OFFPEAK_EVENING", "OFFPEAK_MORNING", "OFFPEAK_WEEKEND", "PEAK", tmDummyRemove.ID} - if err := tpRPC.Call(utils.APIerSv1GetTPTimingIds, &v1.AttrGetTPTimingIds{testTPid, utils.PaginatorWithSearch{}}, &rplyTmIDs); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv1GetTPTimingIds, &v1.AttrGetTPTimingIds{testTPid, utils.PaginatorWithSearch{}}, &rplyTmIDs); err != nil { t.Error("Calling APIerSv1.GetTPTimingIds, got error: ", err.Error()) } else if len(expectedTmIDs) != len(rplyTmIDs) { t.Errorf("Calling APIerSv1.GetTPTimingIds expected: %v, received: %v", expectedTmIDs, rplyTmIDs) } // Test remove - if err := tpRPC.Call(utils.APIerSv2RemoveTPTiming, v1.AttrGetTPTiming{tmDummyRemove.TPid, tmDummyRemove.ID}, &reply); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2RemoveTPTiming, v1.AttrGetTPTiming{tmDummyRemove.TPid, tmDummyRemove.ID}, &reply); err != nil { t.Error("Calling APIerSv2.RemoveTPTiming, got error: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv2.RemoveTPTiming received: ", reply) @@ -203,7 +205,7 @@ func testTPitTimings(t *testing.T) { // Test getIds rplyTmIDs = []string{} expectedTmIDs = []string{"OFFPEAK_EVENING", "OFFPEAK_MORNING", "OFFPEAK_WEEKEND", "PEAK"} - if err := tpRPC.Call(utils.APIerSv1GetTPTimingIds, &v1.AttrGetTPTimingIds{testTPid, utils.PaginatorWithSearch{}}, &rplyTmIDs); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv1GetTPTimingIds, &v1.AttrGetTPTimingIds{testTPid, utils.PaginatorWithSearch{}}, &rplyTmIDs); err != nil { t.Error("Calling APIerSv1.GetTPTimingIds, got error: ", err.Error()) } else if len(expectedTmIDs) != len(rplyTmIDs) { t.Errorf("Calling APIerSv1.GetTPTimingIds expected: %v, received: %v", expectedTmIDs, rplyTmIDs) @@ -226,7 +228,7 @@ func testTPitDestinations(t *testing.T) { dstDEMobile := &utils.TPDestination{TPid: testTPid, ID: "DST_DE_MOBILE", Prefixes: []string{"+49151", "+49161", "+49171"}} dstDUMMY := &utils.TPDestination{TPid: testTPid, ID: "DUMMY_REMOVE", Prefixes: []string{"999"}} for _, dst := range []*utils.TPDestination{dst1002, dst1003, dst1007, dstFS, dstDEMobile, dstDUMMY} { - if err := tpRPC.Call(utils.APIerSv2SetTPDestination, dst, &reply); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2SetTPDestination, dst, &reply); err != nil { t.Error("Got error on APIerSv2.SetTPDestination: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv2.SetTPDestination: ", reply) @@ -234,13 +236,13 @@ func testTPitDestinations(t *testing.T) { } // Test get var rplyDst *utils.TPDestination - if err := tpRPC.Call(utils.APIerSv2GetTPDestination, &AttrGetTPDestination{testTPid, dstDEMobile.ID}, &rplyDst); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetTPDestination, &AttrGetTPDestination{testTPid, dstDEMobile.ID}, &rplyDst); err != nil { t.Error("Calling APIerSv2.GetTPDestination, got error: ", err.Error()) } else if len(dstDEMobile.Prefixes) != len(rplyDst.Prefixes) { t.Errorf("Calling APIerSv2.GetTPDestination expected: %v, received: %v", dstDEMobile, rplyDst) } // Test remove - if err := tpRPC.Call(utils.APIerSv2RemoveTPDestination, &AttrGetTPDestination{testTPid, dstDUMMY.ID}, &reply); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2RemoveTPDestination, &AttrGetTPDestination{testTPid, dstDUMMY.ID}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Received: ", reply) @@ -248,7 +250,7 @@ func testTPitDestinations(t *testing.T) { // Test getIds var rplyDstIds []string expectedDstIds := []string{"DST_1002", "DST_1003", "DST_1007", "DST_DE_MOBILE", "DST_FS"} - if err := tpRPC.Call(utils.APIerSv2GetTPDestinationIDs, v1.AttrGetTPDestinationIds{TPid: testTPid}, &rplyDstIds); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetTPDestinationIDs, v1.AttrGetTPDestinationIds{TPid: testTPid}, &rplyDstIds); err != nil { t.Error("Calling APIerSv1.GetTPDestinationIDs, got error: ", err.Error()) } else if len(expectedDstIds) != len(rplyDstIds) { t.Errorf("Calling APIerSv2.GetTPDestinationIDs expected: %v, received: %v", expectedDstIds, rplyDstIds) diff --git a/apier/v2/tpdestinations.go b/apier/v2/tpdestinations.go index c46efb20c..40a8d2ab1 100644 --- a/apier/v2/tpdestinations.go +++ b/apier/v2/tpdestinations.go @@ -19,11 +19,12 @@ along with this program. If not, see package v2 import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // Creates a new destination within a tariff plan -func (self *APIerSv2) SetTPDestination(attrs *utils.TPDestination, reply *string) error { +func (self *APIerSv2) SetTPDestination(ctx *context.Context, attrs *utils.TPDestination, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "ID", "Prefixes"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -40,7 +41,7 @@ type AttrGetTPDestination struct { } // Queries a specific destination -func (self *APIerSv2) GetTPDestination(attrs *AttrGetTPDestination, reply *utils.TPDestination) error { +func (self *APIerSv2) GetTPDestination(ctx *context.Context, attrs *AttrGetTPDestination, reply *utils.TPDestination) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tag"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -54,7 +55,7 @@ func (self *APIerSv2) GetTPDestination(attrs *AttrGetTPDestination, reply *utils return nil } -func (self *APIerSv2) RemoveTPDestination(attrs *AttrGetTPDestination, reply *string) error { +func (self *APIerSv2) RemoveTPDestination(ctx *context.Context, attrs *AttrGetTPDestination, reply *string) error { if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tag"}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/cmd/cgr-console/cgr-console.go b/cmd/cgr-console/cgr-console.go index 98feb200a..dce983fd7 100644 --- a/cmd/cgr-console/cgr-console.go +++ b/cmd/cgr-console/cgr-console.go @@ -28,6 +28,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/console" "github.com/cgrates/cgrates/utils" "github.com/cgrates/rpcclient" @@ -35,21 +36,24 @@ import ( ) var ( - cgrConsoleFlags = flag.NewFlagSet(utils.CgrConsole, flag.ContinueOnError) - historyFN = os.Getenv(utils.HomeCgr) + utils.HistoryCgr - version = cgrConsoleFlags.Bool(utils.VersionCgr, false, "Prints the application version.") - verbose = cgrConsoleFlags.Bool(utils.VerboseCgr, false, "Show extra info about command execution.") - server = cgrConsoleFlags.String(utils.MailerServerCfg, "127.0.0.1:2012", "server address host:port") - rpcEncoding = cgrConsoleFlags.String(utils.RpcEncodingCgr, utils.MetaJSON, "RPC encoding used <*gob|*json>") - certificatePath = cgrConsoleFlags.String(utils.CertPathCgr, utils.EmptyString, "path to certificate for tls connection") - keyPath = cgrConsoleFlags.String(utils.KeyPathCgr, utils.EmptyString, "path to key for tls connection") - caPath = cgrConsoleFlags.String(utils.CAPathCgr, utils.EmptyString, "path to CA for tls connection(only for self sign certificate)") - tls = cgrConsoleFlags.Bool(utils.TLSNoCaps, false, "TLS connection") - replyTimeOut = cgrConsoleFlags.Int(utils.ReplyTimeoutCfg, 300, "Reply timeout in seconds ") - client *rpcclient.RPCClient + cgrConsoleFlags = flag.NewFlagSet(utils.CgrConsole, flag.ContinueOnError) + historyFN = os.Getenv(utils.HomeCgr) + utils.HistoryCgr + version = cgrConsoleFlags.Bool(utils.VersionCgr, false, "Prints the application version.") + verbose = cgrConsoleFlags.Bool(utils.VerboseCgr, false, "Show extra info about command execution.") + server = cgrConsoleFlags.String(utils.MailerServerCfg, "127.0.0.1:2012", "server address host:port") + rpcEncoding = cgrConsoleFlags.String(utils.RpcEncodingCgr, utils.MetaJSON, "RPC encoding used <*gob|*json>") + certificatePath = cgrConsoleFlags.String(utils.CertPathCgr, utils.EmptyString, "path to certificate for tls connection") + keyPath = cgrConsoleFlags.String(utils.KeyPathCgr, utils.EmptyString, "path to key for tls connection") + caPath = cgrConsoleFlags.String(utils.CAPathCgr, utils.EmptyString, "path to CA for tls connection(only for self sign certificate)") + tls = cgrConsoleFlags.Bool(utils.TLSNoCaps, false, "TLS connection") + connectAttempts = cgrConsoleFlags.Int(utils.ConnectAttemptsCfg, 3, "Connect attempts") + reconnects = cgrConsoleFlags.Int(utils.ReconnectsCfg, 3, "Reconnect attempts") + maxReconnectInterval = cgrConsoleFlags.Int(utils.MaxReconnectIntervalCfg, 0, "Maximum reconnect interval") + connectTimeout = cgrConsoleFlags.Int(utils.ConnectTimeoutCfg, 1, "Connect timeout in seconds ") + replyTimeout = cgrConsoleFlags.Int(utils.ReplyTimeoutCfg, 300, "Reply timeout in seconds ") ) -func executeCommand(command string) { +func executeCommand(command string, client *rpcclient.RPCClient) { if strings.TrimSpace(command) == utils.EmptyString { return } @@ -106,7 +110,7 @@ func executeCommand(command string) { param = param.(*console.StringMapWrapper).Items } - if rpcErr := client.Call(cmd.RpcMethod(), param, res); rpcErr != nil { + if rpcErr := client.Call(context.TODO(), cmd.RpcMethod(), param, res); rpcErr != nil { fmt.Println("Error executing command: " + rpcErr.Error()) } else { fmt.Println(cmd.GetFormatedResult(res)) @@ -128,17 +132,17 @@ func main() { } return } - var err error - client, err = rpcclient.NewRPCClient(utils.TCP, *server, *tls, *keyPath, *certificatePath, *caPath, 3, 3, - time.Second, time.Duration(*replyTimeOut)*time.Second, *rpcEncoding, nil, false, nil) + client, err := rpcclient.NewRPCClient(context.TODO(), utils.TCP, *server, *tls, *keyPath, *certificatePath, *caPath, *connectAttempts, *reconnects, + time.Duration(*maxReconnectInterval)*time.Second, utils.FibDuration, time.Duration(*connectTimeout)*time.Second, + time.Duration(*replyTimeout)*time.Second, *rpcEncoding, nil, false, nil) if err != nil { cgrConsoleFlags.PrintDefaults() log.Fatal("Could not connect to server " + *server) } if len(cgrConsoleFlags.Args()) != 0 { - executeCommand(strings.Join(cgrConsoleFlags.Args(), utils.SepCgr)) + executeCommand(strings.Join(cgrConsoleFlags.Args(), utils.SepCgr), client) return } @@ -190,7 +194,7 @@ func main() { fmt.Println("\nbye!") stop = true default: - executeCommand(command) + executeCommand(command, client) } } } diff --git a/cmd/cgr-console/cgr-console_flags_test.go b/cmd/cgr-console/cgr-console_flags_test.go index 526ab7696..44050a50b 100644 --- a/cmd/cgr-console/cgr-console_flags_test.go +++ b/cmd/cgr-console/cgr-console_flags_test.go @@ -71,7 +71,7 @@ func TestCgrConsoleFlags(t *testing.T) { if err := cgrConsoleFlags.Parse([]string{"-reply_timeout", "200"}); err != nil { t.Fatal(err) - } else if *replyTimeOut != 200 { + } else if *replyTimeout != 200 { t.Errorf("Expected 200 but received %+v", *rpcEncoding) } } diff --git a/cmd/cgr-console/cgr-console_it_test.go b/cmd/cgr-console/cgr-console_it_test.go index 2053c34e6..54f3684ce 100644 --- a/cmd/cgr-console/cgr-console_it_test.go +++ b/cmd/cgr-console/cgr-console_it_test.go @@ -27,8 +27,6 @@ import ( "errors" "flag" "fmt" - "net/rpc" - "net/rpc/jsonrpc" "os" "os/exec" "path" @@ -38,6 +36,10 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/engine" @@ -50,7 +52,7 @@ var ( dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") waitRater = flag.Int("wait_rater", 100, "Number of milliseconds to wait for rater to start and cache") encoding = flag.String("rpc", utils.MetaJSON, "what encoding whould be uused for rpc comunication") - cnslRPC *rpc.Client + cnslRPC *birpc.Client ) var ( @@ -312,12 +314,12 @@ func testConsoleItStartEngine(t *testing.T) { } } -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } @@ -3584,7 +3586,7 @@ func testConsoleItActiveSessions(t *testing.T) { func testConsoleItPassiveSessions(t *testing.T) { var reply string - err := cnslRPC.Call(utils.SessionSv1DeactivateSessions, &utils.SessionIDsWithArgsDispatcher{}, &reply) + err := cnslRPC.Call(context.Background(), utils.SessionSv1DeactivateSessions, &utils.SessionIDsWithArgsDispatcher{}, &reply) if err != nil { t.Error(err) } else if reply != utils.OK { @@ -3594,7 +3596,7 @@ func testConsoleItPassiveSessions(t *testing.T) { APIOpts: make(map[string]any), } var reply2 []*sessions.ExternalSession - if err := cnslRPC.Call(utils.SessionSv1GetPassiveSessions, args, &reply2); err != nil { + if err := cnslRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, args, &reply2); err != nil { t.Error(err) } expected := []*sessions.ExternalSession{ diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 8ad6c14ba..f26ea1a6c 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -34,6 +34,8 @@ import ( "syscall" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/loaders" "github.com/cgrates/cgrates/registrarc" @@ -76,11 +78,11 @@ func startFilterService(filterSChan chan *engine.FilterS, cacheS *engine.CacheS, } // initCacheS inits the CacheS and starts precaching as well as populating internal channel for RPC conns -func initCacheS(internalCacheSChan chan rpcclient.ClientConnector, +func initCacheS(internalCacheSChan chan birpc.ClientConnector, server *cores.Server, dm *engine.DataManager, shdChan *utils.SyncedChan, anz *services.AnalyzerService, - cpS *engine.CapsStats) (chS *engine.CacheS) { - chS = engine.NewCacheS(cfg, dm, cpS) + cpS *engine.CapsStats) (*engine.CacheS, error) { + chS := engine.NewCacheS(cfg, dm, cpS) go func() { if err := chS.Precache(); err != nil { utils.Logger.Crit(fmt.Sprintf("<%s> could not init, error: %s", utils.CacheS, err.Error())) @@ -88,55 +90,63 @@ func initCacheS(internalCacheSChan chan rpcclient.ClientConnector, } }() - chSv1 := v1.NewCacheSv1(chS) + srv, err := engine.NewService(chS) + if err != nil { + return nil, err + } if !cfg.DispatcherSCfg().Enabled { - server.RpcRegister(chSv1) + for _, s := range srv { + server.RpcRegister(s) + } } - var rpc rpcclient.ClientConnector = chS - if anz.IsRunning() { - rpc = anz.GetAnalyzerS().NewAnalyzerConnector(rpc, utils.MetaInternal, utils.EmptyString, utils.CacheS) - } - internalCacheSChan <- rpc - return + internalCacheSChan <- anz.GetInternalCodec(srv, utils.CacheS) + return chS, nil } -func initGuardianSv1(internalGuardianSChan chan rpcclient.ClientConnector, server *cores.Server, - anz *services.AnalyzerService) { - grdSv1 := v1.NewGuardianSv1() +func initGuardianSv1(internalGuardianSChan chan birpc.ClientConnector, server *cores.Server, + anz *services.AnalyzerService) error { + srv, err := engine.NewService(v1.NewGuardianSv1()) + if err != nil { + return err + } if !cfg.DispatcherSCfg().Enabled { - server.RpcRegister(grdSv1) + for _, s := range srv { + server.RpcRegister(s) + } } - var rpc rpcclient.ClientConnector = grdSv1 - if anz.IsRunning() { - rpc = anz.GetAnalyzerS().NewAnalyzerConnector(rpc, utils.MetaInternal, utils.EmptyString, utils.GuardianS) - } - internalGuardianSChan <- rpc + internalGuardianSChan <- anz.GetInternalCodec(srv, utils.GuardianS) + return nil } -func initServiceManagerV1(internalServiceManagerChan chan rpcclient.ClientConnector, +func initServiceManagerV1(internalServiceManagerChan chan birpc.ClientConnector, srvMngr *servmanager.ServiceManager, server *cores.Server, - anz *services.AnalyzerService) { + anz *services.AnalyzerService) error { + srv, err := engine.NewService(v1.NewServiceManagerV1(srvMngr)) + if err != nil { + return err + } if !cfg.DispatcherSCfg().Enabled { - server.RpcRegister(v1.NewServiceManagerV1(srvMngr)) + for _, s := range srv { + server.RpcRegister(s) + } } - var rpc rpcclient.ClientConnector = srvMngr - if anz.IsRunning() { - rpc = anz.GetAnalyzerS().NewAnalyzerConnector(rpc, utils.MetaInternal, utils.EmptyString, utils.ServiceManager) - } - internalServiceManagerChan <- rpc + internalServiceManagerChan <- anz.GetInternalCodec(srv, utils.ServiceManager) + return nil } -func initConfigSv1(internalConfigChan chan rpcclient.ClientConnector, - server *cores.Server, anz *services.AnalyzerService) { - cfgSv1 := v1.NewConfigSv1(cfg) +func initConfigSv1(internalConfigChan chan birpc.ClientConnector, + server *cores.Server, anz *services.AnalyzerService) error { + srv, err := engine.NewService(v1.NewConfigSv1(cfg)) + if err != nil { + return err + } if !cfg.DispatcherSCfg().Enabled { - server.RpcRegister(cfgSv1) + for _, s := range srv { + server.RpcRegister(s) + } } - var rpc rpcclient.ClientConnector = cfgSv1 - if anz.IsRunning() { - rpc = anz.GetAnalyzerS().NewAnalyzerConnector(rpc, utils.MetaInternal, utils.EmptyString, utils.ConfigSv1) - } - internalConfigChan <- rpc + internalConfigChan <- anz.GetInternalCodec(srv, utils.ConfigSv1) + return nil } func startRPC(server *cores.Server, internalRaterChan, @@ -144,7 +154,7 @@ func startRPC(server *cores.Server, internalRaterChan, internalAttrSChan, internalChargerSChan, internalThdSChan, internalSuplSChan, internalSMGChan, internalAnalyzerSChan, internalDispatcherSChan, internalLoaderSChan, internalRALsv1Chan, internalCacheSChan, - internalEEsChan chan rpcclient.ClientConnector, + internalEEsChan chan birpc.ClientConnector, shdChan *utils.SyncedChan) { if !cfg.DispatcherSCfg().Enabled { select { // Any of the rpc methods will unlock listening to rpc requests @@ -277,6 +287,7 @@ func singnalHandler(shdWg *sync.WaitGroup, shdChan *utils.SyncedChan) { go func() { var reply string if err := config.CgrConfig().V1ReloadConfig( + context.TODO(), &config.ReloadArgs{ Section: utils.EmptyString, Path: config.CgrConfig().ConfigPath, // use the same path @@ -289,7 +300,7 @@ func singnalHandler(shdWg *sync.WaitGroup, shdChan *utils.SyncedChan) { } } -func runPreload(loader *services.LoaderService, internalLoaderSChan chan rpcclient.ClientConnector, +func runPreload(loader *services.LoaderService, internalLoaderSChan chan birpc.ClientConnector, shdChan *utils.SyncedChan) { if !cfg.LoaderCfg().Enabled() { utils.Logger.Err(fmt.Sprintf("<%s> not enabled but required by preload mechanism", utils.LoaderS)) @@ -302,11 +313,12 @@ func runPreload(loader *services.LoaderService, internalLoaderSChan chan rpcclie var reply string for _, loaderID := range strings.Split(*preload, utils.FieldsSep) { - if err := loader.GetLoaderS().V1Load(&loaders.ArgsProcessFolder{ - ForceLock: true, // force lock will unlock the file in case is locked and return error - LoaderID: loaderID, - StopOnError: true, - }, &reply); err != nil { + if err := loader.GetLoaderS().V1Load(context.TODO(), + &loaders.ArgsProcessFolder{ + ForceLock: true, // force lock will unlock the file in case is locked and return error + LoaderID: loaderID, + StopOnError: true, + }, &reply); err != nil { utils.Logger.Err(fmt.Sprintf("<%s> preload failed on loadID <%s> , err: <%s>", utils.LoaderS, loaderID, err.Error())) shdChan.CloseOnce() return @@ -436,32 +448,32 @@ func main() { cfg.LazySanityCheck() // init the channel here because we need to pass them to connManager - internalServeManagerChan := make(chan rpcclient.ClientConnector, 1) - internalConfigChan := make(chan rpcclient.ClientConnector, 1) - internalCoreSv1Chan := make(chan rpcclient.ClientConnector, 1) - internalCacheSChan := make(chan rpcclient.ClientConnector, 1) - internalGuardianSChan := make(chan rpcclient.ClientConnector, 1) - internalAnalyzerSChan := make(chan rpcclient.ClientConnector, 1) - internalCDRServerChan := make(chan rpcclient.ClientConnector, 1) - internalAttributeSChan := make(chan rpcclient.ClientConnector, 1) - internalDispatcherSChan := make(chan rpcclient.ClientConnector, 1) - internalSessionSChan := make(chan rpcclient.ClientConnector, 1) - internalChargerSChan := make(chan rpcclient.ClientConnector, 1) - internalThresholdSChan := make(chan rpcclient.ClientConnector, 1) - internalStatSChan := make(chan rpcclient.ClientConnector, 1) - internalResourceSChan := make(chan rpcclient.ClientConnector, 1) - internalRouteSChan := make(chan rpcclient.ClientConnector, 1) - internalSchedulerSChan := make(chan rpcclient.ClientConnector, 1) - internalRALsChan := make(chan rpcclient.ClientConnector, 1) - internalResponderChan := make(chan rpcclient.ClientConnector, 1) - internalAPIerSv1Chan := make(chan rpcclient.ClientConnector, 1) - internalAPIerSv2Chan := make(chan rpcclient.ClientConnector, 1) - internalLoaderSChan := make(chan rpcclient.ClientConnector, 1) - internalEEsChan := make(chan rpcclient.ClientConnector, 1) + internalServeManagerChan := make(chan birpc.ClientConnector, 1) + internalConfigChan := make(chan birpc.ClientConnector, 1) + internalCoreSv1Chan := make(chan birpc.ClientConnector, 1) + internalCacheSChan := make(chan birpc.ClientConnector, 1) + internalGuardianSChan := make(chan birpc.ClientConnector, 1) + internalAnalyzerSChan := make(chan birpc.ClientConnector, 1) + internalCDRServerChan := make(chan birpc.ClientConnector, 1) + internalAttributeSChan := make(chan birpc.ClientConnector, 1) + internalDispatcherSChan := make(chan birpc.ClientConnector, 1) + internalSessionSChan := make(chan birpc.ClientConnector, 1) + internalChargerSChan := make(chan birpc.ClientConnector, 1) + internalThresholdSChan := make(chan birpc.ClientConnector, 1) + internalStatSChan := make(chan birpc.ClientConnector, 1) + internalResourceSChan := make(chan birpc.ClientConnector, 1) + internalRouteSChan := make(chan birpc.ClientConnector, 1) + internalSchedulerSChan := make(chan birpc.ClientConnector, 1) + internalRALsChan := make(chan birpc.ClientConnector, 1) + internalResponderChan := make(chan birpc.ClientConnector, 1) + internalAPIerSv1Chan := make(chan birpc.ClientConnector, 1) + internalAPIerSv2Chan := make(chan birpc.ClientConnector, 1) + internalLoaderSChan := make(chan birpc.ClientConnector, 1) + internalEEsChan := make(chan birpc.ClientConnector, 1) // initialize the connManager before creating the DMService // because we need to pass the connection to it - connManager := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connManager := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAnalyzer): internalAnalyzerSChan, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier): internalAPIerSv2Chan, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): internalAttributeSChan, @@ -575,11 +587,17 @@ func main() { cS = coreS.GetCoreS() // init CacheS - cacheS := initCacheS(internalCacheSChan, server, dmService.GetDM(), shdChan, anz, coreS.GetCoreS().CapsStats) + cacheS, err := initCacheS(internalCacheSChan, server, dmService.GetDM(), shdChan, anz, coreS.GetCoreS().CapsStats) + if err != nil { + log.Fatal(err) + } engine.Cache = cacheS // init GuardianSv1 - initGuardianSv1(internalGuardianSChan, server, anz) + err = initGuardianSv1(internalGuardianSChan, server, anz) + if err != nil { + log.Fatal(err) + } // Start ServiceManager srvManager := servmanager.NewServiceManager(cfg, shdChan, shdWg, connManager) @@ -636,7 +654,10 @@ func main() { go startFilterService(filterSChan, cacheS, connManager, cfg, dmService.GetDM()) - initServiceManagerV1(internalServeManagerChan, srvManager, server, anz) + err = initServiceManagerV1(internalServeManagerChan, srvManager, server, anz) + if err != nil { + log.Fatal(err) + } // init internalRPCSet to share internal connections among the engine engine.IntRPC = engine.NewRPCClientSet() @@ -664,7 +685,10 @@ func main() { engine.IntRPC.AddInternalRPCClient(utils.EeSv1, internalEEsChan) engine.IntRPC.AddInternalRPCClient(utils.DispatcherSv1, internalDispatcherSChan) - initConfigSv1(internalConfigChan, server, anz) + err = initConfigSv1(internalConfigChan, server, anz) + if err != nil { + log.Fatal(err) + } if *preload != utils.EmptyString { runPreload(ldrs, internalLoaderSChan, shdChan) diff --git a/cmd/cgr-loader/cgr-loader_remove_it_test.go b/cmd/cgr-loader/cgr-loader_remove_it_test.go index 5507aed85..7aba1b131 100644 --- a/cmd/cgr-loader/cgr-loader_remove_it_test.go +++ b/cmd/cgr-loader/cgr-loader_remove_it_test.go @@ -24,8 +24,6 @@ package main import ( "bytes" "errors" - "net/rpc" - "net/rpc/jsonrpc" "os/exec" "path" "reflect" @@ -33,6 +31,10 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -42,7 +44,7 @@ var ( cgrLdrCfgPath string cgrLdrCfgDir string cgrLdrCfg *config.CGRConfig - cgrLdrRPC *rpc.Client + cgrLdrRPC *birpc.Client cgrLdrTests = []func(t *testing.T){ testCgrLdrInitCfg, testCgrLdrInitDataDB, @@ -125,7 +127,7 @@ func testCgrLdrRPCConn(t *testing.T) { func testCgrLdrGetSubsystemsNotLoadedLoad(t *testing.T) { //attributesPrf var replyAttr *engine.AttributeProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_ACNT_1001"}}, &replyAttr); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+q, received %v", utils.ErrNotFound.Error(), err) @@ -133,7 +135,7 @@ func testCgrLdrGetSubsystemsNotLoadedLoad(t *testing.T) { //filtersPrf var replyFltr *engine.Filter - if err := cgrLdrRPC.Call(utils.APIerSv1GetFilter, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_1"}}, &replyFltr); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+q, received %v", utils.ErrNotFound.Error(), err) @@ -141,7 +143,7 @@ func testCgrLdrGetSubsystemsNotLoadedLoad(t *testing.T) { // resourcesPrf var replyResPrf *engine.ResourceProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetResourceProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RES_ACNT_1001"}}, &replyResPrf); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+q, received %v", utils.ErrNotFound.Error(), err) @@ -149,7 +151,7 @@ func testCgrLdrGetSubsystemsNotLoadedLoad(t *testing.T) { // resource var replyRes *engine.Resource - if err := cgrLdrRPC.Call(utils.ResourceSv1GetResource, + if err := cgrLdrRPC.Call(context.Background(), utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RES_ACNT_1001"}}, &replyRes); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+q, received %v", utils.ErrNotFound.Error(), err) @@ -157,7 +159,7 @@ func testCgrLdrGetSubsystemsNotLoadedLoad(t *testing.T) { // routesPrf var replyRts *engine.RouteProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetRouteProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}}, &replyRts); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+q, received %v", utils.ErrNotFound.Error(), err) @@ -165,7 +167,7 @@ func testCgrLdrGetSubsystemsNotLoadedLoad(t *testing.T) { // statsPrf var replySts *engine.StatQueueProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_1"}}, &replySts); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+q, received %v", utils.ErrNotFound.Error(), err) @@ -173,7 +175,7 @@ func testCgrLdrGetSubsystemsNotLoadedLoad(t *testing.T) { // statQueue var replyStQue *engine.StatQueue - if err := cgrLdrRPC.Call(utils.StatSv1GetStatQueue, + if err := cgrLdrRPC.Call(context.Background(), utils.StatSv1GetStatQueue, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_1"}}, &replyStQue); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+q, received %v", utils.ErrNotFound.Error(), err) @@ -181,7 +183,7 @@ func testCgrLdrGetSubsystemsNotLoadedLoad(t *testing.T) { // thresholdPrf var replyThdPrf *engine.ThresholdProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1"}}, &replyThdPrf); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+q, received %v", utils.ErrNotFound.Error(), err) @@ -189,7 +191,7 @@ func testCgrLdrGetSubsystemsNotLoadedLoad(t *testing.T) { // threshold var rplyThd *engine.Threshold - if err := cgrLdrRPC.Call(utils.ThresholdSv1GetThreshold, + if err := cgrLdrRPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1"}}, &rplyThd); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+q, received %v", utils.ErrNotFound.Error(), err) @@ -197,7 +199,7 @@ func testCgrLdrGetSubsystemsNotLoadedLoad(t *testing.T) { //chargers var replyChrgr *engine.ChargerProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetChargerProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Raw"}, &replyChrgr); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+v, received %v", utils.ErrNotFound.Error(), err) @@ -237,7 +239,7 @@ func testCgrLdrGetAttributeProfileAfterLoad(t *testing.T) { }, } var replyAttr *engine.AttributeProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_ACNT_1001"}}, &replyAttr); err != nil { t.Error(err) @@ -278,7 +280,7 @@ func testCgrLdrGetFilterAfterLoad(t *testing.T) { }, } var replyFltr *engine.Filter - if err := cgrLdrRPC.Call(utils.APIerSv1GetFilter, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_1"}}, &replyFltr); err != nil { t.Error(err) @@ -298,7 +300,7 @@ func testCgrLdrGetResourceProfileAfterLoad(t *testing.T) { ThresholdIDs: []string{}, } var replyRes *engine.ResourceProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetResourceProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RES_ACNT_1001"}}, &replyRes); err != nil { t.Error(err) @@ -314,7 +316,7 @@ func testCgrLdrGetResourceAfterLoad(t *testing.T) { Usages: map[string]*engine.ResourceUsage{}, } var replyRes *engine.Resource - if err := cgrLdrRPC.Call(utils.ResourceSv1GetResource, + if err := cgrLdrRPC.Call(context.Background(), utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RES_ACNT_1001"}}, &replyRes); err != nil { t.Error(err) @@ -343,7 +345,7 @@ func testCgrLdrGetRouteProfileAfterLoad(t *testing.T) { }, } var replyRts *engine.RouteProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetRouteProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}}, &replyRts); err != nil { t.Error(err) @@ -387,7 +389,7 @@ func testCgrLdrGetStatsProfileAfterLoad(t *testing.T) { }, } var replySts *engine.StatQueueProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_1"}}, &replySts); err != nil { t.Error(err) @@ -411,7 +413,7 @@ func testCgrLdrGetStatQueueAfterLoad(t *testing.T) { "*asr": "N/A", } replyStQue := make(map[string]string) - if err := cgrLdrRPC.Call(utils.StatSv1GetQueueStringMetrics, + if err := cgrLdrRPC.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_1"}}, &replyStQue); err != nil { t.Error(err) @@ -434,7 +436,7 @@ func testCgrLdrGetThresholdProfileAfterLoad(t *testing.T) { ActionIDs: []string{"TOPUP_MONETARY_10"}, } var replyThdPrf *engine.ThresholdProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}}, &replyThdPrf); err != nil { t.Error(err) @@ -450,7 +452,7 @@ func testCgrLdrGetThresholdAfterLoad(t *testing.T) { Hits: 0, } var replyThdPrf *engine.Threshold - if err := cgrLdrRPC.Call(utils.ThresholdSv1GetThreshold, + if err := cgrLdrRPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}}, &replyThdPrf); err != nil { t.Error(err) @@ -470,7 +472,7 @@ func testCgrLdrGetChargerProfileAfterLoad(t *testing.T) { } var replyChrgr *engine.ChargerProfile - if err := cgrLdrRPC.Call(utils.APIerSv1GetChargerProfile, + if err := cgrLdrRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Raw"}, &replyChrgr); err != nil { t.Error(err) @@ -501,12 +503,12 @@ func testCgrLdrKillEngine(t *testing.T) { } } -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/cmd/cgr-tester/cdr_repl/process_cdr.go b/cmd/cgr-tester/cdr_repl/process_cdr.go index 735064d5f..740a9bc3a 100644 --- a/cmd/cgr-tester/cdr_repl/process_cdr.go +++ b/cmd/cgr-tester/cdr_repl/process_cdr.go @@ -25,6 +25,7 @@ import ( "path" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -43,8 +44,8 @@ func main() { if cdrsMasterCfg, err = config.NewCGRConfigFromPath(cdrsMasterCfgPath); err != nil { log.Fatal("Got config error: ", err.Error()) } - cdrsMasterRpc, err = rpcclient.NewRPCClient(utils.TCP, cdrsMasterCfg.ListenCfg().RPCJSONListen, false, "", "", "", 1, 1, - time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) + cdrsMasterRpc, err = rpcclient.NewRPCClient(context.TODO(), utils.TCP, cdrsMasterCfg.ListenCfg().RPCJSONListen, false, "", "", "", 1, 1, + 0, utils.FibDuration, time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) if err != nil { log.Fatal("Could not connect to rater: ", err.Error()) } @@ -59,7 +60,7 @@ func main() { } var reply string for _, cdr := range cdrs { - if err := cdrsMasterRpc.Call(utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { + if err := cdrsMasterRpc.Call(context.TODO(), utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { log.Fatal("Unexpected error: ", err.Error()) } else if reply != utils.OK { log.Fatal("Unexpected reply received: ", reply) diff --git a/cmd/cgr-tester/cgr-tester.go b/cmd/cgr-tester/cgr-tester.go index ee8bfad5a..c4f195e0d 100644 --- a/cmd/cgr-tester/cgr-tester.go +++ b/cmd/cgr-tester/cgr-tester.go @@ -23,14 +23,15 @@ import ( "fmt" "log" "math" - "net/rpc" - "net/rpc/jsonrpc" "os" "runtime" "runtime/pprof" "sync" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -144,12 +145,12 @@ func durInternalRater(cd *engine.CallDescriptorWithAPIOpts) (time.Duration, erro func durRemoteRater(cd *engine.CallDescriptorWithAPIOpts) (time.Duration, error) { result := engine.CallCost{} - var client *rpc.Client + var client *birpc.Client var err error if *json { client, err = jsonrpc.Dial(utils.TCP, *raterAddress) } else { - client, err = rpc.Dial(utils.TCP, *raterAddress) + client, err = birpc.Dial(utils.TCP, *raterAddress) } if err != nil { @@ -164,7 +165,7 @@ func durRemoteRater(cd *engine.CallDescriptorWithAPIOpts) (time.Duration, error) for i := 0; i < *runs; i++ { go func() { sem <- 1 - client.Call(utils.ResponderGetCost, cd, &result) + client.Call(context.Background(), utils.ResponderGetCost, cd, &result) <-sem finish <- 1 // divCall = client.Go(utils.ResponderGetCost, cd, &result, nil) @@ -176,7 +177,7 @@ func durRemoteRater(cd *engine.CallDescriptorWithAPIOpts) (time.Duration, error) // <-divCall.Done } else { for j := 0; j < *runs; j++ { - client.Call(utils.ResponderGetCost, cd, &result) + client.Call(context.Background(), utils.ResponderGetCost, cd, &result) } } log.Printf("Result:%s\n", utils.ToJSON(result)) @@ -370,7 +371,7 @@ func main() { tmpTime = timeoutStamp timeout = time.After(totalUsage + *timeoutDur + 140*time.Millisecond) } - if err := callSessions(&authDur, &initDur, &updateDur, &terminateDur, &cdrDur, + if err := callSessions(context.TODO(), &authDur, &initDur, &updateDur, &terminateDur, &cdrDur, &reqAuth, &reqInit, &reqUpdate, &reqTerminate, &reqCdr, digitMin, digitMax, totalUsage); err != nil { log.Fatal(err.Error()) diff --git a/cmd/cgr-tester/sessions.go b/cmd/cgr-tester/sessions.go index 1ee8453d7..f00e6c2fe 100644 --- a/cmd/cgr-tester/sessions.go +++ b/cmd/cgr-tester/sessions.go @@ -26,24 +26,27 @@ import ( "sync/atomic" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" ) var ( - brpc *rpc2.Client + brpc *birpc.BirpcClient disconnectEvChan = make(chan *utils.AttrDisconnectSession, 1) ) -func handleDisconnectSession(clnt *rpc2.Client, +type smock struct{} + +func (*smock) DisconnectSession(ctx *context.Context, args *utils.AttrDisconnectSession, reply *string) error { disconnectEvChan <- args *reply = utils.OK return nil } -func callSessions(authDur, initDur, updateDur, terminateDur, cdrDur *[]time.Duration, +func callSessions(ctx *context.Context, authDur, initDur, updateDur, terminateDur, cdrDur *[]time.Duration, reqAuth, reqInit, reqUpdate, reqTerminate, reqCdr *uint64, digitMin, digitMax int64, totalUsage time.Duration) (err error) { @@ -71,11 +74,13 @@ func callSessions(authDur, initDur, updateDur, terminateDur, cdrDur *[]time.Dura APIOpts: map[string]any{}, } - clntHandlers := map[string]any{ - utils.SessionSv1DisconnectSession: handleDisconnectSession} - brpc, err = utils.NewBiJSONrpcClient(tstCfg.SessionSCfg().ListenBijson, clntHandlers) + srv, err := birpc.NewService(new(smock), utils.SessionSv1, true) if err != nil { - return + return err + } + brpc, err = utils.NewBiJSONrpcClient(tstCfg.SessionSCfg().ListenBijson, srv) + if err != nil { + return err } // @@ -90,7 +95,7 @@ func callSessions(authDur, initDur, updateDur, terminateDur, cdrDur *[]time.Dura var authRply sessions.V1AuthorizeReply atomic.AddUint64(reqAuth, 1) authStartTime := time.Now() - if err = brpc.Call(utils.SessionSv1AuthorizeEvent, authArgs, &authRply); err != nil { + if err = brpc.Call(ctx, utils.SessionSv1AuthorizeEvent, authArgs, &authRply); err != nil { return } appendMu.Lock() @@ -115,7 +120,7 @@ func callSessions(authDur, initDur, updateDur, terminateDur, cdrDur *[]time.Dura var initRply sessions.V1InitSessionReply atomic.AddUint64(reqInit, 1) initStartTime := time.Now() - if err = brpc.Call(utils.SessionSv1InitiateSession, initArgs, &initRply); err != nil { + if err = brpc.Call(ctx, utils.SessionSv1InitiateSession, initArgs, &initRply); err != nil { return } appendMu.Lock() @@ -141,7 +146,7 @@ func callSessions(authDur, initDur, updateDur, terminateDur, cdrDur *[]time.Dura var upRply sessions.V1UpdateSessionReply atomic.AddUint64(reqUpdate, 1) updateStartTime := time.Now() - if err = brpc.Call(utils.SessionSv1UpdateSession, upArgs, &upRply); err != nil { + if err = brpc.Call(ctx, utils.SessionSv1UpdateSession, upArgs, &upRply); err != nil { return } appendMu.Lock() @@ -167,7 +172,7 @@ func callSessions(authDur, initDur, updateDur, terminateDur, cdrDur *[]time.Dura var tRply string atomic.AddUint64(reqTerminate, 1) terminateStartTime := time.Now() - if err = brpc.Call(utils.SessionSv1TerminateSession, tArgs, &tRply); err != nil { + if err = brpc.Call(ctx, utils.SessionSv1TerminateSession, tArgs, &tRply); err != nil { return } appendMu.Lock() @@ -187,7 +192,7 @@ func callSessions(authDur, initDur, updateDur, terminateDur, cdrDur *[]time.Dura var pRply string atomic.AddUint64(reqCdr, 1) cdrStartTime := time.Now() - if err = brpc.Call(utils.SessionSv1ProcessCDR, procArgs, &pRply); err != nil { + if err = brpc.Call(ctx, utils.SessionSv1ProcessCDR, procArgs, &pRply); err != nil { return } appendMu.Lock() diff --git a/config/config.go b/config/config.go index aa882e89c..9183db6f0 100644 --- a/config/config.go +++ b/config/config.go @@ -33,6 +33,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/rpcclient" "github.com/cgrates/cgrates/utils" @@ -1163,8 +1164,8 @@ func (cfg *CGRConfig) GetReloadChan(sectID string) chan struct{} { return cfg.rldChans[sectID] } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (cfg *CGRConfig) Call(serviceMethod string, +// Call implements birpc.ClientConnector interface for internal RPC +func (cfg *CGRConfig) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.APIerRPCCall(cfg, serviceMethod, args, reply) } @@ -1582,7 +1583,7 @@ type ReloadArgs struct { } // V1ReloadConfig reloads the configuration -func (cfg *CGRConfig) V1ReloadConfig(args *ReloadArgs, reply *string) (err error) { +func (cfg *CGRConfig) V1ReloadConfig(ctx *context.Context, args *ReloadArgs, reply *string) (err error) { if missing := utils.MissingStructFields(args, []string{"Path"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } @@ -1623,7 +1624,7 @@ type SectionWithAPIOpts struct { } // V1GetConfig will retrieve from CGRConfig a section -func (cfg *CGRConfig) V1GetConfig(args *SectionWithAPIOpts, reply *map[string]any) (err error) { +func (cfg *CGRConfig) V1GetConfig(ctx *context.Context, args *SectionWithAPIOpts, reply *map[string]any) (err error) { args.Section = utils.FirstNonEmpty(args.Section, utils.MetaAll) cfg.cacheDPMux.RLock() if mp, has := cfg.cacheDP[args.Section]; has && mp != nil { @@ -1747,7 +1748,7 @@ type SetConfigArgs struct { } // V1SetConfig reloads the sections of config -func (cfg *CGRConfig) V1SetConfig(args *SetConfigArgs, reply *string) (err error) { +func (cfg *CGRConfig) V1SetConfig(ctx *context.Context, args *SetConfigArgs, reply *string) (err error) { if len(args.Config) == 0 { *reply = utils.OK return @@ -1787,7 +1788,7 @@ func (cfg *CGRConfig) V1SetConfig(args *SetConfigArgs, reply *string) (err error } // V1GetConfigAsJSON will retrieve from CGRConfig a section as a string -func (cfg *CGRConfig) V1GetConfigAsJSON(args *SectionWithAPIOpts, reply *string) (err error) { +func (cfg *CGRConfig) V1GetConfigAsJSON(ctx *context.Context, args *SectionWithAPIOpts, reply *string) (err error) { args.Section = utils.FirstNonEmpty(args.Section, utils.MetaAll) cfg.cacheDPMux.RLock() if mp, has := cfg.cacheDP[args.Section]; has && mp != nil { @@ -1914,7 +1915,7 @@ type SetConfigFromJSONArgs struct { } // V1SetConfigFromJSON reloads the sections of config -func (cfg *CGRConfig) V1SetConfigFromJSON(args *SetConfigFromJSONArgs, reply *string) (err error) { +func (cfg *CGRConfig) V1SetConfigFromJSON(ctx *context.Context, args *SetConfigFromJSONArgs, reply *string) (err error) { if len(args.Config) == 0 { *reply = utils.OK return diff --git a/config/config_it_test.go b/config/config_it_test.go index ae17beb60..4bf9af8b0 100644 --- a/config/config_it_test.go +++ b/config/config_it_test.go @@ -33,6 +33,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" "github.com/cgrates/rpcclient" ) @@ -138,10 +139,11 @@ func testCGRConfigReloadAttributeS(t *testing.T) { cfg.rldChans[section] = make(chan struct{}, 1) } var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: ATTRIBUTE_JSN, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: ATTRIBUTE_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -172,11 +174,12 @@ func testCGRConfigReloadChargerSDryRun(t *testing.T) { cfg.rldChans[section] = make(chan struct{}, 1) } var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: ChargerSCfgJson, - DryRun: true, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: ChargerSCfgJson, + DryRun: true, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -194,10 +197,11 @@ func testCGRConfigReloadChargerS(t *testing.T) { cfg.rldChans[section] = make(chan struct{}, 1) } var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: ChargerSCfgJson, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: ChargerSCfgJson, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -221,10 +225,11 @@ func testCGRConfigReloadThresholdS(t *testing.T) { cfg.rldChans[section] = make(chan struct{}, 1) } var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: THRESHOLDS_JSON, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: THRESHOLDS_JSON, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -250,10 +255,11 @@ func testCGRConfigReloadStatS(t *testing.T) { cfg.rldChans[section] = make(chan struct{}, 1) } var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: STATS_JSON, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: STATS_JSON, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -280,10 +286,11 @@ func testCGRConfigReloadResourceS(t *testing.T) { cfg.rldChans[section] = make(chan struct{}, 1) } var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: RESOURCES_JSON, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: RESOURCES_JSON, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -311,10 +318,11 @@ func testCGRConfigReloadSupplierS(t *testing.T) { cfg.rldChans[section] = make(chan struct{}, 1) } var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: RouteSJson, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: RouteSJson, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -348,17 +356,19 @@ func testCGRConfigV1ReloadConfigFromPathInvalidSection(t *testing.T) { } expectedErr := "Invalid section: " var reply string - if err := cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: "InvalidSection", - }, &reply); err == nil || err.Error() != expectedErr { + if err := cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: "InvalidSection", + }, &reply); err == nil || err.Error() != expectedErr { t.Errorf("Expected %+v. received %+v", expectedErr, err) } expectedErr = utils.NewErrMandatoryIeMissing("Path").Error() - if err := cfg.V1ReloadConfig(&ReloadArgs{ - Section: "InvalidSection", - }, &reply); err == nil || err.Error() != expectedErr { + if err := cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Section: "InvalidSection", + }, &reply); err == nil || err.Error() != expectedErr { t.Errorf("Expected %+v. received %+v", expectedErr, err) } } @@ -370,9 +380,10 @@ func testV1ReloadConfigFromPathConfigSanity(t *testing.T) { for _, section := range sortedCfgSections { cfg.rldChans[section] = make(chan struct{}, 1) } - if err := cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutinternal"), - Section: ChargerSCfgJson}, &reply); err == nil || err.Error() != expectedErr { + if err := cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutinternal"), + Section: ChargerSCfgJson}, &reply); err == nil || err.Error() != expectedErr { t.Errorf("Expected %+v, received %+v", expectedErr, err) } } @@ -392,10 +403,11 @@ func testCGRConfigReloadSchedulerS(t *testing.T) { cfg.rldChans[section] = make(chan struct{}, 1) } var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: SCHEDULER_JSN, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: SCHEDULER_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -420,10 +432,11 @@ func testCGRConfigReloadCDRs(t *testing.T) { } cfg.RalsCfg().Enabled = true var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: CDRS_JSN, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: CDRS_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -458,10 +471,11 @@ func testCGRConfigReloadRALs(t *testing.T) { blMap := cfg.RalsCfg().BalanceRatingSubject maxComp := cfg.RalsCfg().MaxComputedUsage var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: RALS_JSN, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: RALS_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -490,10 +504,11 @@ func testCGRConfigReloadSessionS(t *testing.T) { cfg.ChargerSCfg().Enabled = true cfg.CdrsCfg().Enabled = true var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: SessionSJson, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: SessionSJson, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -549,10 +564,11 @@ func testCGRConfigReloadERs(t *testing.T) { } cfg.SessionSCfg().Enabled = true var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "ers_example"), - Section: ERsJson, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "ers_example"), + Section: ERsJson, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -654,10 +670,11 @@ func testCGRConfigReloadDNSAgent(t *testing.T) { } cfg.SessionSCfg().Enabled = true var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dnsagent_reload"), - Section: DNSAgentJson, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dnsagent_reload"), + Section: DNSAgentJson, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -690,10 +707,11 @@ func testCGRConfigReloadFreeswitchAgent(t *testing.T) { } cfg.SessionSCfg().Enabled = true var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "freeswitch_reload"), - Section: FreeSWITCHAgentJSN, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "freeswitch_reload"), + Section: FreeSWITCHAgentJSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -871,10 +889,11 @@ func testCgrCfgV1ReloadConfigSection(t *testing.T) { var reply string var rcv map[string]any - if err := cfg.V1ReloadConfig(&ReloadArgs{ - Path: "/usr/share/cgrates/conf/samples/ers_example", - Section: ERsJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: "/usr/share/cgrates/conf/samples/ers_example", + Section: ERsJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Errorf("Expected: %s \n,received: %s", utils.OK, reply) @@ -883,7 +902,7 @@ func testCgrCfgV1ReloadConfigSection(t *testing.T) { expected = map[string]any{ ERsJson: expected, } - if err := cfg.V1GetConfig(&SectionWithAPIOpts{Section: ERsJson}, &rcv); err != nil { + if err := cfg.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: ERsJson}, &rcv); err != nil { t.Error(err) } else if utils.ToJSON(expected) != utils.ToJSON(rcv) { t.Errorf("Expected: %+v, \n received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv)) @@ -905,19 +924,20 @@ func testCGRConfigReloadConfigFromJSONSessionS(t *testing.T) { cfg.ChargerSCfg().Enabled = true cfg.CdrsCfg().Enabled = true var reply string - if err = cfg.V1SetConfig(&SetConfigArgs{ - Config: map[string]any{ - "sessions": map[string]any{ - "enabled": true, - "resources_conns": []string{"*localhost"}, - "routes_conns": []string{"*localhost"}, - "attributes_conns": []string{"*localhost"}, - "rals_conns": []string{"*internal"}, - "cdrs_conns": []string{"*internal"}, - "chargers_conns": []string{"*internal"}, + if err = cfg.V1SetConfig(context.Background(), + &SetConfigArgs{ + Config: map[string]any{ + "sessions": map[string]any{ + "enabled": true, + "resources_conns": []string{"*localhost"}, + "routes_conns": []string{"*localhost"}, + "attributes_conns": []string{"*localhost"}, + "rals_conns": []string{"*internal"}, + "cdrs_conns": []string{"*internal"}, + "chargers_conns": []string{"*internal"}, + }, }, - }, - }, &reply); err != nil { + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -966,16 +986,19 @@ func testCGRConfigReloadConfigFromStringSessionS(t *testing.T) { cfg.ChargerSCfg().Enabled = true cfg.CdrsCfg().Enabled = true var reply string - if err = cfg.V1SetConfigFromJSON(&SetConfigFromJSONArgs{ - Config: `{"sessions":{ - "enabled": true, - "resources_conns": ["*localhost"], - "routes_conns": ["*localhost"], - "attributes_conns": ["*localhost"], - "rals_conns": ["*internal"], - "cdrs_conns": ["*internal"], - "chargers_conns": ["*localhost"] - }}`}, &reply); err != nil { + if err = cfg.V1SetConfigFromJSON(context.Background(), + &SetConfigFromJSONArgs{ + Config: `{ + "sessions":{ + "enabled": true, + "resources_conns": ["*localhost"], + "routes_conns": ["*localhost"], + "attributes_conns": ["*localhost"], + "rals_conns": ["*internal"], + "cdrs_conns": ["*internal"], + "chargers_conns": ["*localhost"] + } +}`}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) @@ -1016,7 +1039,7 @@ func testCGRConfigReloadConfigFromStringSessionS(t *testing.T) { var rcv string expected := `{"sessions":{"alterable_fields":[],"attributes_conns":["*localhost"],"cdrs_conns":["*internal"],"channel_sync_interval":"0","chargers_conns":["*localhost"],"client_protocol":1,"debit_interval":"0","default_usage":{"*any":"3h0m0s","*data":"1048576","*sms":"1","*voice":"3h0m0s"},"enabled":true,"listen_bigob":"","listen_bijson":"127.0.0.1:2014","min_dur_low_balance":"0","rals_conns":["*internal"],"replication_conns":[],"resources_conns":["*localhost"],"routes_conns":["*localhost"],"scheduler_conns":[],"session_indexes":[],"session_ttl":"0","stats_conns":[],"stir":{"allowed_attest":["*any"],"default_attest":"A","payload_maxduration":"-1","privatekey_path":"","publickey_path":""},"store_session_costs":false,"terminate_attempts":5,"thresholds_conns":[]}}` - if err := cfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: SessionSJson}, &rcv); err != nil { + if err := cfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: SessionSJson}, &rcv); err != nil { t.Error(err) } else if expected != rcv { t.Errorf("Expected: %+q, \n received: %s", expected, rcv) @@ -1032,10 +1055,11 @@ func testCGRConfigReloadAll(t *testing.T) { cfg.ChargerSCfg().Enabled = true cfg.CdrsCfg().Enabled = true var reply string - if err = cfg.V1ReloadConfig(&ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), - Section: utils.MetaAll, - }, &reply); err != nil { + if err = cfg.V1ReloadConfig(context.Background(), + &ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo2"), + Section: utils.MetaAll, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %s", reply) diff --git a/config/config_test.go b/config/config_test.go index e4734a92c..34f5f6f7c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/rpcclient" "github.com/cgrates/cgrates/utils" @@ -3447,13 +3448,13 @@ func TestCgrCfgV1GetConfigAllConfig(t *testing.T) { t.Error(err) } expected := cgrCfg.AsMapInterface(cgrCfg.GeneralCfg().RSRSep) - if err := cgrCfg.V1GetConfig(&SectionWithAPIOpts{Section: utils.EmptyString}, &rcv); err != nil { + if err := cgrCfg.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: utils.EmptyString}, &rcv); err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, rcv) { t.Errorf("Expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv)) } - if err := cgrCfg.V1GetConfig(&SectionWithAPIOpts{Section: utils.EmptyString}, &rcv); err != nil { + if err := cgrCfg.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: utils.EmptyString}, &rcv); err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, rcv) { @@ -3481,7 +3482,7 @@ func TestCgrCfgV1GetConfigSectionLoader(t *testing.T) { }, } cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfig(&SectionWithAPIOpts{Section: LoaderJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: LoaderJson}, &reply); err != nil { t.Error(err) } else if mp, can := reply[LoaderJson].([]map[string]any); !can { t.Errorf("Unexpected type: %t", reply[LoaderJson]) @@ -3499,7 +3500,7 @@ func TestCgrCfgV1GetConfigSectionHTTPAgent(t *testing.T) { HttpAgentJson: []map[string]any{}, } cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfig(&SectionWithAPIOpts{Section: HttpAgentJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: HttpAgentJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, reply) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3517,7 +3518,7 @@ func TestCgrCfgV1GetConfigSectionCoreS(t *testing.T) { }, } cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfig(&SectionWithAPIOpts{Section: CoreSCfgJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: CoreSCfgJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, reply) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3546,7 +3547,7 @@ func TestCgrCfgV1GetConfigListen(t *testing.T) { var rcv map[string]any if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(jsnCfg); err != nil { t.Error(err) - } else if err := cgrCfg.V1GetConfig(&SectionWithAPIOpts{Section: LISTEN_JSN}, &rcv); err != nil { + } else if err := cgrCfg.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: LISTEN_JSN}, &rcv); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, rcv) { t.Errorf("Expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rcv)) @@ -3597,7 +3598,7 @@ func TestV1GetConfigGeneral(t *testing.T) { if err != nil { t.Error(err) } - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: GENERAL_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: GENERAL_JSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3625,7 +3626,7 @@ func TestV1GetConfigDataDB(t *testing.T) { DATADB_JSN: expected, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: DATADB_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: DATADB_JSN}, &reply); err != nil { t.Error(err) } else if mp, can := reply[DATADB_JSN].(map[string]any); !can { t.Errorf("Unexpected type: %t", reply[DATADB_JSN]) @@ -3667,7 +3668,7 @@ func TestV1GetConfigStorDB(t *testing.T) { STORDB_JSN: expected, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: STORDB_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: STORDB_JSN}, &reply); err != nil { t.Error(err) } else if mp, can := reply[STORDB_JSN].(map[string]any); !can { t.Errorf("Unexpected type: %t", reply[STORDB_JSN]) @@ -3693,7 +3694,7 @@ func TestV1GetConfigTLS(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: TlsCfgJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: TlsCfgJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3710,7 +3711,7 @@ func TestV1GetConfigCache(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: CACHE_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: CACHE_JSN}, &reply); err != nil { t.Error(err) } else if mp, can := reply[CACHE_JSN].(map[string]any); !can { t.Errorf("Unexpected type: %t", reply[CACHE_JSN]) @@ -3752,7 +3753,7 @@ func TestV1GetConfigHTTP(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: HTTP_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: HTTP_JSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3769,7 +3770,7 @@ func TestV1GetConfigFilterS(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: FilterSjsn}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: FilterSjsn}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3800,7 +3801,7 @@ func TestV1GetConfigRals(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: RALS_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: RALS_JSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3820,7 +3821,7 @@ func TestV1GetConfigScheduler(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: SCHEDULER_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: SCHEDULER_JSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3846,7 +3847,7 @@ func TestV1GetConfigCdrs(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: CDRS_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: CDRS_JSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3895,7 +3896,7 @@ func TestV1GetConfigSessionS(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: SessionSJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: SessionSJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3926,7 +3927,7 @@ func TestV1GetConfigFsAgent(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: FreeSWITCHAgentJSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: FreeSWITCHAgentJSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3952,7 +3953,7 @@ func TestV1GetConfigKamailioAgent(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: KamailioAgentJSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: KamailioAgentJSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -3980,7 +3981,7 @@ func TestV1GetConfigAsteriskAgent(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: AsteriskAgentJSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: AsteriskAgentJSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4009,7 +4010,7 @@ func TestV1GetConfigDiameterAgent(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: DA_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: DA_JSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4035,7 +4036,7 @@ func TestV1GetConfigRadiusAgent(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: RA_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: RA_JSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4059,7 +4060,7 @@ func TestV1GetConfigDNSAgent(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: DNSAgentJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: DNSAgentJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4088,7 +4089,7 @@ func TestV1GetConfigAttribute(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: ATTRIBUTE_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: ATTRIBUTE_JSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4108,7 +4109,7 @@ func TestV1GetConfigChargers(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: ChargerSCfgJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: ChargerSCfgJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4133,7 +4134,7 @@ func TestV1GetConfigResourceS(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: RESOURCES_JSON}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: RESOURCES_JSON}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4159,7 +4160,7 @@ func TestV1GetConfigStats(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: STATS_JSON}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: STATS_JSON}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4183,7 +4184,7 @@ func TestV1GetConfigThresholds(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: THRESHOLDS_JSON}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: THRESHOLDS_JSON}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4212,7 +4213,7 @@ func TestV1GetConfigRoutes(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: RouteSJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: RouteSJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4253,7 +4254,7 @@ func TestV1GetConfigSuretax(t *testing.T) { } cfgCgr := NewDefaultCGRConfig() cfgCgr.SureTaxCfg().Timezone = time.UTC - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: SURETAX_JSON}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: SURETAX_JSON}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4275,7 +4276,7 @@ func TestV1GetConfigDispatcherS(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: DispatcherSJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: DispatcherSJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4299,7 +4300,7 @@ func TestV1GetConfigDispatcherH(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: RegistrarCJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: RegistrarCJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4321,7 +4322,7 @@ func TestV1GetConfigSectionLoader(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: CgrLoaderCfgJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: CgrLoaderCfgJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4374,7 +4375,7 @@ func TestV1GetConfigSectionMigrator(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: CgrMigratorCfgJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: CgrMigratorCfgJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4393,7 +4394,7 @@ func TestV1GetConfigSectionApierS(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: ApierS}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: ApierS}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4437,7 +4438,7 @@ func TestV1GetConfigSectionEES(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: EEsJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: EEsJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4480,7 +4481,7 @@ func TestV1GetConfigSectionERS(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: ERsJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: ERsJson}, &reply); err != nil { t.Error(err) } else if mp, can := reply[ERsJson].(map[string]any); !can { t.Errorf("Unexpected type: %t", reply[ERsJson]) @@ -4539,7 +4540,7 @@ func TestV1GetConfigSectionRPConns(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: RPCConnsJsonName}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: RPCConnsJsonName}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4560,7 +4561,7 @@ func TestV1GetConfigSectionSIPAgent(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: SIPAgentJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: SIPAgentJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4600,7 +4601,7 @@ func TestV1GetConfigSectionTemplates(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: TemplatesJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: TemplatesJson}, &reply); err != nil { t.Error(err) } else if mp, can := reply[TemplatesJson].(map[string][]map[string]any); !can { t.Errorf("Unexpected type: %t", reply[TemplatesJson]) @@ -4626,7 +4627,7 @@ func TestV1GetConfigSectionConfigs(t *testing.T) { } cfgCgr := NewDefaultCGRConfig() cfgCgr.ConfigSCfg().Enabled = true - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: ConfigSJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: ConfigSJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4634,7 +4635,7 @@ func TestV1GetConfigSectionConfigs(t *testing.T) { var result string cfgCgr2 := NewDefaultCGRConfig() - if err = cfgCgr2.V1SetConfig(&SetConfigArgs{Config: reply, DryRun: true}, &result); err != nil { + if err = cfgCgr2.V1SetConfig(context.Background(), &SetConfigArgs{Config: reply, DryRun: true}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Errorf("Unexpected result") @@ -4643,7 +4644,7 @@ func TestV1GetConfigSectionConfigs(t *testing.T) { } cfgCgr2 = NewDefaultCGRConfig() - if err = cfgCgr2.V1SetConfig(&SetConfigArgs{Config: reply}, &result); err != nil { + if err = cfgCgr2.V1SetConfig(context.Background(), &SetConfigArgs{Config: reply}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Errorf("Unexpected result") @@ -4660,7 +4661,7 @@ func TestV1GetConfigSectionAPIBans(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: APIBanCfgJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: APIBanCfgJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4678,7 +4679,7 @@ func TestV1GetConfigSectionMailer(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: MAILER_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: MAILER_JSN}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4697,7 +4698,7 @@ func TestV1GetConfigSectionAnalyzer(t *testing.T) { }, } cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: AnalyzerCfgJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: AnalyzerCfgJson}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply)) @@ -4708,7 +4709,7 @@ func TestV1GetConfigSectionInvalidSection(t *testing.T) { var reply map[string]any expected := "Invalid section" cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: "invalidSection"}, &reply); err == nil || err.Error() != expected { + if err := cfgCgr.V1GetConfig(context.Background(), &SectionWithAPIOpts{Section: "invalidSection"}, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -4716,7 +4717,7 @@ func TestV1GetConfigSectionInvalidSection(t *testing.T) { func TestV1ReloadConfigEmptyConfig(t *testing.T) { var reply string cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1SetConfig(&SetConfigArgs{}, &reply); err != nil { + if err := cgrCfg.V1SetConfig(context.Background(), &SetConfigArgs{}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected output: %+v", reply) @@ -4727,11 +4728,12 @@ func TestV1ReloadConfigUnmarshalError(t *testing.T) { var reply string expected := "json: unsupported type: chan int" cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1SetConfig(&SetConfigArgs{ - Config: map[string]any{ - "randomValue": make(chan int), + if err := cgrCfg.V1SetConfig(context.Background(), + &SetConfigArgs{ + Config: map[string]any{ + "randomValue": make(chan int), + }, }, - }, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -4744,7 +4746,7 @@ func TestV1ReloadConfigJSONWithLocks(t *testing.T) { } expected := "Invalid section: " cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1SetConfig(&SetConfigArgs{Config: section}, &reply); err == nil || err.Error() != expected { + if err := cfgCgr.V1SetConfig(context.Background(), &SetConfigArgs{Config: section}, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -4766,7 +4768,7 @@ func TestV1ReloadConfigCheckingSanity(t *testing.T) { expected := ` not enabled but requested by component` if cfgCgr, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil { t.Error(err) - } else if err := cfgCgr.V1SetConfig(&SetConfigArgs{Config: ralsMap}, &reply); err == nil || err.Error() != expected { + } else if err := cfgCgr.V1SetConfig(context.Background(), &SetConfigArgs{Config: ralsMap}, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -4781,7 +4783,7 @@ func TestV1GetConfigAsJSONGeneral(t *testing.T) { expected := `{"general":{"connect_attempts":5,"connect_timeout":"1s","dbdata_encoding":"*msgpack","default_caching":"*reload","default_category":"call","default_request_type":"*rated","default_tenant":"cgrates.org","default_timezone":"Local","digest_equal":":","digest_separator":",","failed_posts_dir":"/var/spool/cgrates/failed_posts","failed_posts_ttl":"5s","locking_timeout":"0","log_level":6,"logger":"*syslog","max_parallel_conns":100,"max_reconnect_interval":"0","node_id":"ENGINE1","poster_attempts":3,"reconnects":-1,"reply_timeout":"2s","rounding_decimals":5,"rsr_separator":";","tpexport_dir":"/var/spool/cgrates/tpe"}}` if cfgCgr, err := NewCGRConfigFromJSONStringWithDefaults(strJSON); err != nil { t.Error(err) - } else if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: GENERAL_JSN}, &reply); err != nil { + } else if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: GENERAL_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4792,7 +4794,7 @@ func TestV1GetConfigAsJSONDataDB(t *testing.T) { var reply string expected := `{"data_db":{"db_host":"127.0.0.1","db_name":"10","db_password":"","db_port":6379,"db_type":"*redis","db_user":"cgrates","items":{"*account_action_plans":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*accounts":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*action_plans":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*action_triggers":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*actions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*attribute_filter_indexes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*attribute_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*charger_filter_indexes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*charger_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*destinations":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*dispatcher_filter_indexes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*dispatcher_hosts":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*dispatcher_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*filters":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*load_ids":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*rating_plans":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*rating_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*resource_filter_indexes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*resource_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*resources":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*reverse_destinations":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*reverse_filter_indexes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*route_filter_indexes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*route_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*shared_groups":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*stat_filter_indexes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*statqueue_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*statqueues":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*threshold_filter_indexes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*threshold_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*thresholds":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*timings":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*versions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false}},"opts":{"mongoQueryTimeout":"10s","redisCACertificate":"","redisClientCertificate":"","redisClientKey":"","redisCluster":false,"redisClusterOndownDelay":"0s","redisClusterSync":"5s","redisConnectAttempts":20,"redisConnectTimeout":"0s","redisMaxConns":10,"redisReadTimeout":"0s","redisSentinel":"","redisTLS":false,"redisWriteTimeout":"0s"},"remote_conn_id":"","remote_conns":[],"replication_cache":"","replication_conns":[],"replication_filtered":false}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: DATADB_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: DATADB_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4803,7 +4805,7 @@ func TestV1GetConfigAsJSONStorDB(t *testing.T) { var reply string expected := `{"stor_db":{"db_host":"127.0.0.1","db_name":"cgrates","db_password":"","db_port":3306,"db_type":"*mysql","db_user":"cgrates","items":{"*cdrs":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*session_costs":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_account_actions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_action_plans":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_action_triggers":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_actions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_attributes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_chargers":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_destination_rates":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_destinations":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_dispatcher_hosts":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_dispatcher_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_filters":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_rates":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_rating_plans":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_rating_profiles":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_resources":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_routes":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_shared_groups":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_stats":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_thresholds":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*tp_timings":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false},"*versions":{"limit":-1,"remote":false,"replicate":false,"static_ttl":false}},"opts":{"mongoQueryTimeout":"10s","mysqlDSNParams":{},"mysqlLocation":"Local","pgSSLMode":"disable","sqlConnMaxLifetime":"0s","sqlMaxIdleConns":10,"sqlMaxOpenConns":100},"prefix_indexed_fields":[],"remote_conns":null,"replication_conns":null,"string_indexed_fields":[]}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: STORDB_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: STORDB_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4814,7 +4816,7 @@ func TestV1GetConfigAsJSONTls(t *testing.T) { var reply string expected := `{"tls":{"ca_certificate":"","client_certificate":"","client_key":"","server_certificate":"","server_key":"","server_name":"","server_policy":4}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: TlsCfgJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: TlsCfgJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4825,7 +4827,7 @@ func TestV1GetConfigAsJSONTCache(t *testing.T) { var reply string expected := `{"caches":{"partitions":{"*account_action_plans":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*action_plans":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*action_triggers":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*actions":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*apiban":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false,"ttl":"2m0s"},"*attribute_filter_indexes":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*attribute_profiles":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*caps_events":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*cdr_ids":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false,"ttl":"10m0s"},"*charger_filter_indexes":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*charger_profiles":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*closed_sessions":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false,"ttl":"10s"},"*destinations":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*diameter_messages":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false,"ttl":"3h0m0s"},"*dispatcher_filter_indexes":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*dispatcher_hosts":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*dispatcher_loads":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*dispatcher_profiles":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*dispatcher_routes":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*dispatchers":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*event_charges":{"limit":0,"precache":false,"remote":false,"replicate":false,"static_ttl":false,"ttl":"10s"},"*event_resources":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*filters":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*load_ids":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*rating_plans":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*rating_profiles":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*replication_hosts":{"limit":0,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*resource_filter_indexes":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*resource_profiles":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*resources":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*reverse_destinations":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*reverse_filter_indexes":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*route_filter_indexes":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*route_profiles":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*rpc_connections":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*rpc_responses":{"limit":0,"precache":false,"remote":false,"replicate":false,"static_ttl":false,"ttl":"2s"},"*sentrypeer":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":true,"ttl":"24h0m0s"},"*shared_groups":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*stat_filter_indexes":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*statqueue_profiles":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*statqueues":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*stir":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false,"ttl":"3h0m0s"},"*threshold_filter_indexes":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*threshold_profiles":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*thresholds":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*timings":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false},"*uch":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false,"ttl":"3h0m0s"}},"remote_conns":[],"replication_conns":[]}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: CACHE_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: CACHE_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4836,7 +4838,7 @@ func TestV1GetConfigAsJSONTListen(t *testing.T) { var reply string expected := `{"listen":{"http":"127.0.0.1:2080","http_tls":"127.0.0.1:2280","rpc_gob":"127.0.0.1:2013","rpc_gob_tls":"127.0.0.1:2023","rpc_json":"127.0.0.1:2012","rpc_json_tls":"127.0.0.1:2022"}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: LISTEN_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: LISTEN_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4847,7 +4849,7 @@ func TestV1GetConfigAsJSONHTTP(t *testing.T) { var reply string expected := `{"http":{"auth_users":{},"client_opts":{"dialFallbackDelay":"300ms","dialKeepAlive":"30s","dialTimeout":"30s","disableCompression":false,"disableKeepAlives":false,"expectContinueTimeout":"0s","forceAttemptHttp2":true,"idleConnTimeout":"1m30s","maxConnsPerHost":0,"maxIdleConns":100,"maxIdleConnsPerHost":2,"responseHeaderTimeout":"0s","skipTlsVerify":false,"tlsHandshakeTimeout":"10s"},"freeswitch_cdrs_url":"/freeswitch_json","http_cdrs":"/cdr_http","json_rpc_url":"/jsonrpc","registrars_url":"/registrar","use_basic_auth":false,"ws_url":"/ws"}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: HTTP_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: HTTP_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4858,7 +4860,7 @@ func TestV1GetConfigAsJSONFilterS(t *testing.T) { var reply string expected := `{"filters":{"apiers_conns":[],"resources_conns":[],"stats_conns":[]}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: FilterSjsn}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: FilterSjsn}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4869,7 +4871,7 @@ func TestV1GetConfigAsJSONRals(t *testing.T) { var reply string expected := `{"rals":{"balance_rating_subject":{"*any":"*zero1ns","*voice":"*zero1s"},"enabled":false,"max_computed_usage":{"*any":"189h0m0s","*data":"107374182400","*mms":"10000","*sms":"10000","*voice":"72h0m0s"},"max_increments":1000000,"remove_expired":true,"rp_subject_prefix_matching":false,"stats_conns":[],"thresholds_conns":[]}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: RALS_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: RALS_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4880,7 +4882,7 @@ func TestV1GetConfigAsJSONScheduler(t *testing.T) { var reply string expected := `{"schedulers":{"cdrs_conns":[],"dynaprepaid_actionplans":[],"enabled":false,"filters":[],"stats_conns":[],"thresholds_conns":[]}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: SCHEDULER_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: SCHEDULER_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4891,7 +4893,7 @@ func TestV1GetConfigAsJSONCdrs(t *testing.T) { var reply string expected := `{"cdrs":{"attributes_conns":[],"chargers_conns":[],"ees_conns":[],"enabled":false,"extra_fields":[],"online_cdr_exports":[],"rals_conns":[],"scheduler_conns":[],"session_cost_retries":5,"stats_conns":[],"store_cdrs":true,"thresholds_conns":[]}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: CDRS_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: CDRS_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4902,7 +4904,7 @@ func TestV1GetConfigAsJSONSessionS(t *testing.T) { var reply string expected := `{"sessions":{"alterable_fields":[],"attributes_conns":[],"cdrs_conns":[],"channel_sync_interval":"0","chargers_conns":[],"client_protocol":1,"debit_interval":"0","default_usage":{"*any":"3h0m0s","*data":"1048576","*sms":"1","*voice":"3h0m0s"},"enabled":false,"listen_bigob":"","listen_bijson":"127.0.0.1:2014","min_dur_low_balance":"0","rals_conns":[],"replication_conns":[],"resources_conns":[],"routes_conns":[],"scheduler_conns":[],"session_indexes":[],"session_ttl":"0","stats_conns":[],"stir":{"allowed_attest":["*any"],"default_attest":"A","payload_maxduration":"-1","privatekey_path":"","publickey_path":""},"store_session_costs":false,"terminate_attempts":5,"thresholds_conns":[]}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: SessionSJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: SessionSJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4913,7 +4915,7 @@ func TestV1GetConfigAsJSONFreeSwitchAgent(t *testing.T) { var reply string expected := `{"freeswitch_agent":{"create_cdr":false,"empty_balance_ann_file":"","empty_balance_context":"","enabled":false,"event_socket_conns":[{"address":"127.0.0.1:8021","alias":"127.0.0.1:8021","max_reconnect_interval":"0s","password":"ClueCon","reconnects":5}],"extra_fields":"","low_balance_ann_file":"","max_wait_connection":"2s","sessions_conns":["*birpc_internal"],"subscribe_park":true}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: FreeSWITCHAgentJSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: FreeSWITCHAgentJSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4924,7 +4926,7 @@ func TestV1GetConfigAsJSONFKamailioAgent(t *testing.T) { var reply string expected := `{"kamailio_agent":{"create_cdr":false,"enabled":false,"evapi_conns":[{"address":"127.0.0.1:8448","alias":"","max_reconnect_interval":"0s","reconnects":5}],"sessions_conns":["*birpc_internal"],"timezone":""}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: KamailioAgentJSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: KamailioAgentJSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4935,7 +4937,7 @@ func TestV1GetConfigAsJSONAsteriskAgent(t *testing.T) { var reply string expected := `{"asterisk_agent":{"asterisk_conns":[{"address":"127.0.0.1:8088","alias":"","connect_attempts":3,"max_reconnect_interval":"0s","password":"CGRateS.org","reconnects":5,"user":"cgrates"}],"create_cdr":false,"enabled":false,"sessions_conns":["*birpc_internal"]}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: AsteriskAgentJSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: AsteriskAgentJSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4946,7 +4948,7 @@ func TestV1GetConfigAsJSONADiameterAgent(t *testing.T) { var reply string expected := `{"diameter_agent":{"asr_template":"","concurrent_requests":-1,"dictionaries_path":"/usr/share/cgrates/diameter/dict/","enabled":false,"forced_disconnect":"*none","listen":"127.0.0.1:3868","listen_net":"tcp","origin_host":"CGR-DA","origin_realm":"cgrates.org","product_name":"CGRateS","rar_template":"","request_processors":[],"sessions_conns":["*birpc_internal"],"synced_conn_requests":false,"vendor_id":0}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: DA_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: DA_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4957,7 +4959,7 @@ func TestV1GetConfigAsJSONARadiusAgent(t *testing.T) { var reply string expected := `{"radius_agent":{"client_dictionaries":{"*default":"/usr/share/cgrates/radius/dict/"},"client_secrets":{"*default":"CGRateS.org"},"enabled":false,"listen_acct":"127.0.0.1:1813","listen_auth":"127.0.0.1:1812","listen_net":"udp","request_processors":[],"sessions_conns":["*internal"]}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: RA_JSN}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: RA_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4968,7 +4970,7 @@ func TestV1GetConfigAsJSONDNSAgent(t *testing.T) { var reply string expected := `{"dns_agent":{"enabled":false,"listeners":[{"address":"127.0.0.1:53","network":"udp"}],"request_processors":[],"sessions_conns":["*internal"],"timezone":""}}` cfgCgr := NewDefaultCGRConfig() - if err := cfgCgr.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: DNSAgentJson}, &reply); err != nil { + if err := cfgCgr.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: DNSAgentJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4979,7 +4981,7 @@ func TestV1GetConfigAsJSONAttributes(t *testing.T) { var reply string expected := `{"attributes":{"any_context":true,"apiers_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"opts":{"*processRuns":1,"*profileIDs":[],"*profileIgnoreFilters":false,"*profileRuns":0},"prefix_indexed_fields":[],"resources_conns":[],"stats_conns":[],"suffix_indexed_fields":[]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: ATTRIBUTE_JSN}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: ATTRIBUTE_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -4990,7 +4992,7 @@ func TestV1GetConfigAsJSONChargerS(t *testing.T) { var reply string expected := `{"chargers":{"attributes_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"suffix_indexed_fields":[]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: ChargerSCfgJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: ChargerSCfgJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5001,7 +5003,7 @@ func TestV1GetConfigAsJSONResourceS(t *testing.T) { var reply string expected := `{"resources":{"enabled":false,"indexed_selects":true,"nested_fields":false,"opts":{"*units":1,"*usageID":""},"prefix_indexed_fields":[],"store_interval":"","suffix_indexed_fields":[],"thresholds_conns":[]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: RESOURCES_JSON}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: RESOURCES_JSON}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5012,7 +5014,7 @@ func TestV1GetConfigAsJSONStatS(t *testing.T) { var reply string expected := `{"stats":{"enabled":false,"indexed_selects":true,"nested_fields":false,"opts":{"*profileIDs":[],"*profileIgnoreFilters":false},"prefix_indexed_fields":[],"store_interval":"","store_uncompressed_limit":0,"suffix_indexed_fields":[],"thresholds_conns":[]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: STATS_JSON}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: STATS_JSON}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5023,7 +5025,7 @@ func TestV1GetConfigAsJSONThresholdS(t *testing.T) { var reply string expected := `{"thresholds":{"enabled":false,"indexed_selects":true,"nested_fields":false,"opts":{"*profileIDs":[],"*profileIgnoreFilters":false},"prefix_indexed_fields":[],"store_interval":"","suffix_indexed_fields":[]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: THRESHOLDS_JSON}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: THRESHOLDS_JSON}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5034,7 +5036,7 @@ func TestV1GetConfigAsJSONRouteS(t *testing.T) { var reply string expected := `{"routes":{"attributes_conns":[],"default_ratio":1,"enabled":false,"indexed_selects":true,"nested_fields":false,"opts":{"*context":"*routes","*ignoreErrors":false,"*maxCost":""},"prefix_indexed_fields":[],"rals_conns":[],"resources_conns":[],"stats_conns":[],"suffix_indexed_fields":[]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: RouteSJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: RouteSJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5047,7 +5049,7 @@ func TestV1GetConfigAsJSONSureTax(t *testing.T) { cgrCfg := NewDefaultCGRConfig() cgrCfg.SureTaxCfg().Timezone = time.UTC - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: SURETAX_JSON}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: SURETAX_JSON}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5058,7 +5060,7 @@ func TestV1GetConfigAsJSONDispatcherS(t *testing.T) { var reply string expected := `{"dispatchers":{"any_subsystem":true,"attributes_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"prevent_loop":false,"suffix_indexed_fields":[]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: DispatcherSJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: DispatcherSJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5069,7 +5071,7 @@ func TestV1GetConfigAsJSONDispatcherH(t *testing.T) { var reply string expected := `{"registrarc":{"dispatchers":{"hosts":[],"refresh_interval":"5m0s","registrars_conns":[]},"rpc":{"hosts":[],"refresh_interval":"5m0s","registrars_conns":[]}}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: RegistrarCJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: RegistrarCJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5080,7 +5082,7 @@ func TestV1GetConfigAsJSONLoaders(t *testing.T) { var reply string expected := `{"loaders":[{"caches_conns":["*internal"],"data":[{"fields":[{"mandatory":true,"path":"Tenant","tag":"TenantID","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ProfileID","type":"*variable","value":"~*req.1"},{"path":"Contexts","tag":"Contexts","type":"*variable","value":"~*req.2"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.3"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.4"},{"path":"AttributeFilterIDs","tag":"AttributeFilterIDs","type":"*variable","value":"~*req.5"},{"path":"Path","tag":"Path","type":"*variable","value":"~*req.6"},{"path":"Type","tag":"Type","type":"*variable","value":"~*req.7"},{"path":"Value","tag":"Value","type":"*variable","value":"~*req.8"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.9"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.10"}],"file_name":"Attributes.csv","flags":null,"type":"*attributes"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"Type","tag":"Type","type":"*variable","value":"~*req.2"},{"path":"Element","tag":"Element","type":"*variable","value":"~*req.3"},{"path":"Values","tag":"Values","type":"*variable","value":"~*req.4"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.5"}],"file_name":"Filters.csv","flags":null,"type":"*filters"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"UsageTTL","tag":"TTL","type":"*variable","value":"~*req.4"},{"path":"Limit","tag":"Limit","type":"*variable","value":"~*req.5"},{"path":"AllocationMessage","tag":"AllocationMessage","type":"*variable","value":"~*req.6"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.7"},{"path":"Stored","tag":"Stored","type":"*variable","value":"~*req.8"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.9"},{"path":"ThresholdIDs","tag":"ThresholdIDs","type":"*variable","value":"~*req.10"}],"file_name":"Resources.csv","flags":null,"type":"*resources"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"QueueLength","tag":"QueueLength","type":"*variable","value":"~*req.4"},{"path":"TTL","tag":"TTL","type":"*variable","value":"~*req.5"},{"path":"MinItems","tag":"MinItems","type":"*variable","value":"~*req.6"},{"path":"MetricIDs","tag":"MetricIDs","type":"*variable","value":"~*req.7"},{"path":"MetricFilterIDs","tag":"MetricFilterIDs","type":"*variable","value":"~*req.8"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.9"},{"path":"Stored","tag":"Stored","type":"*variable","value":"~*req.10"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.11"},{"path":"ThresholdIDs","tag":"ThresholdIDs","type":"*variable","value":"~*req.12"}],"file_name":"Stats.csv","flags":null,"type":"*stats"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"MaxHits","tag":"MaxHits","type":"*variable","value":"~*req.4"},{"path":"MinHits","tag":"MinHits","type":"*variable","value":"~*req.5"},{"path":"MinSleep","tag":"MinSleep","type":"*variable","value":"~*req.6"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.7"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.8"},{"path":"ActionIDs","tag":"ActionIDs","type":"*variable","value":"~*req.9"},{"path":"Async","tag":"Async","type":"*variable","value":"~*req.10"}],"file_name":"Thresholds.csv","flags":null,"type":"*thresholds"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"Sorting","tag":"Sorting","type":"*variable","value":"~*req.4"},{"path":"SortingParameters","tag":"SortingParameters","type":"*variable","value":"~*req.5"},{"path":"RouteID","tag":"RouteID","type":"*variable","value":"~*req.6"},{"path":"RouteFilterIDs","tag":"RouteFilterIDs","type":"*variable","value":"~*req.7"},{"path":"RouteAccountIDs","tag":"RouteAccountIDs","type":"*variable","value":"~*req.8"},{"path":"RouteRatingPlanIDs","tag":"RouteRatingPlanIDs","type":"*variable","value":"~*req.9"},{"path":"RouteResourceIDs","tag":"RouteResourceIDs","type":"*variable","value":"~*req.10"},{"path":"RouteStatIDs","tag":"RouteStatIDs","type":"*variable","value":"~*req.11"},{"path":"RouteWeight","tag":"RouteWeight","type":"*variable","value":"~*req.12"},{"path":"RouteBlocker","tag":"RouteBlocker","type":"*variable","value":"~*req.13"},{"path":"RouteParameters","tag":"RouteParameters","type":"*variable","value":"~*req.14"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.15"}],"file_name":"Routes.csv","flags":null,"type":"*routes"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"RunID","tag":"RunID","type":"*variable","value":"~*req.4"},{"path":"AttributeIDs","tag":"AttributeIDs","type":"*variable","value":"~*req.5"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.6"}],"file_name":"Chargers.csv","flags":null,"type":"*chargers"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"Contexts","tag":"Contexts","type":"*variable","value":"~*req.2"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.3"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.4"},{"path":"Strategy","tag":"Strategy","type":"*variable","value":"~*req.5"},{"path":"StrategyParameters","tag":"StrategyParameters","type":"*variable","value":"~*req.6"},{"path":"ConnID","tag":"ConnID","type":"*variable","value":"~*req.7"},{"path":"ConnFilterIDs","tag":"ConnFilterIDs","type":"*variable","value":"~*req.8"},{"path":"ConnWeight","tag":"ConnWeight","type":"*variable","value":"~*req.9"},{"path":"ConnBlocker","tag":"ConnBlocker","type":"*variable","value":"~*req.10"},{"path":"ConnParameters","tag":"ConnParameters","type":"*variable","value":"~*req.11"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.12"}],"file_name":"DispatcherProfiles.csv","flags":null,"type":"*dispatchers"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"Address","tag":"Address","type":"*variable","value":"~*req.2"},{"path":"Transport","tag":"Transport","type":"*variable","value":"~*req.3"},{"path":"ConnectAttempts","tag":"ConnectAttempts","type":"*variable","value":"~*req.4"},{"path":"Reconnects","tag":"Reconnects","type":"*variable","value":"~*req.5"},{"path":"MaxReconnectInterval","tag":"MaxReconnectInterval","type":"*variable","value":"~*req.6"},{"path":"ConnectTimeout","tag":"ConnectTimeout","type":"*variable","value":"~*req.7"},{"path":"ReplyTimeout","tag":"ReplyTimeout","type":"*variable","value":"~*req.8"},{"path":"TLS","tag":"TLS","type":"*variable","value":"~*req.9"},{"path":"ClientKey","tag":"ClientKey","type":"*variable","value":"~*req.10"},{"path":"ClientCertificate","tag":"ClientCertificate","type":"*variable","value":"~*req.11"},{"path":"CaCertificate","tag":"CaCertificate","type":"*variable","value":"~*req.12"}],"file_name":"DispatcherHosts.csv","flags":null,"type":"*dispatcher_hosts"}],"dry_run":false,"enabled":false,"field_separator":",","id":"*default","lockfile_path":".cgr.lck","run_delay":"0","tenant":"","tp_in_dir":"/var/spool/cgrates/loader/in","tp_out_dir":"/var/spool/cgrates/loader/out"}]}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: LoaderJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: LoaderJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5091,7 +5093,7 @@ func TestV1GetConfigAsJSONCgrLoader(t *testing.T) { var reply string expected := `{"loader":{"caches_conns":["*localhost"],"data_path":"./","disable_reverse":false,"field_separator":",","gapi_credentials":".gapi/credentials.json","gapi_token":".gapi/token.json","scheduler_conns":["*localhost"],"tpid":""}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: CgrLoaderCfgJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: CgrLoaderCfgJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5102,7 +5104,7 @@ func TestV1GetConfigAsJSONCgrMigrator(t *testing.T) { var reply string expected := `{"migrator":{"out_datadb_encoding":"msgpack","out_datadb_host":"127.0.0.1","out_datadb_name":"10","out_datadb_opts":{"mongoQueryTimeout":"0s","redisCACertificate":"","redisClientCertificate":"","redisClientKey":"","redisCluster":false,"redisClusterOndownDelay":"0s","redisClusterSync":"5s","redisConnectAttempts":20,"redisConnectTimeout":"0s","redisMaxConns":10,"redisReadTimeout":"0s","redisSentinel":"","redisTLS":false,"redisWriteTimeout":"0s"},"out_datadb_password":"","out_datadb_port":"6379","out_datadb_type":"*redis","out_datadb_user":"cgrates","out_stordb_host":"127.0.0.1","out_stordb_name":"cgrates","out_stordb_opts":{"mongoQueryTimeout":"0s","mysqlDSNParams":null,"mysqlLocation":"","pgSSLMode":"","sqlConnMaxLifetime":"0s","sqlMaxIdleConns":0,"sqlMaxOpenConns":0},"out_stordb_password":"","out_stordb_port":"3306","out_stordb_type":"*mysql","out_stordb_user":"cgrates","users_filters":[]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: CgrMigratorCfgJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: CgrMigratorCfgJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5113,7 +5115,7 @@ func TestV1GetConfigAsJSONApierS(t *testing.T) { var reply string expected := `{"apiers":{"attributes_conns":[],"caches_conns":["*internal"],"ees_conns":[],"enabled":false,"scheduler_conns":[]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: ApierS}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: ApierS}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5124,7 +5126,7 @@ func TestV1GetConfigAsJSONCfgEES(t *testing.T) { var reply string expected := `{"ees":{"attributes_conns":[],"cache":{"*file_csv":{"limit":-1,"precache":false,"remote":false,"replicate":false,"static_ttl":false,"ttl":"5s"}},"enabled":false,"exporters":[{"attempts":1,"attribute_context":"","attribute_ids":[],"concurrent_requests":0,"export_path":"/var/spool/cgrates/ees","failed_posts_dir":"/var/spool/cgrates/failed_posts","fields":[],"filters":[],"flags":[],"id":"*default","opts":{},"synchronous":false,"timezone":"","type":"*none"}]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: EEsJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: EEsJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5135,7 +5137,7 @@ func TestV1GetConfigAsJSONCfgERS(t *testing.T) { var reply string expected := `{"ers":{"enabled":false,"partial_cache_ttl":"1s","readers":[{"cache_dump_fields":[],"concurrent_requests":1024,"fields":[{"mandatory":true,"path":"*cgreq.ToR","tag":"ToR","type":"*variable","value":"~*req.2"},{"mandatory":true,"path":"*cgreq.OriginID","tag":"OriginID","type":"*variable","value":"~*req.3"},{"mandatory":true,"path":"*cgreq.RequestType","tag":"RequestType","type":"*variable","value":"~*req.4"},{"mandatory":true,"path":"*cgreq.Tenant","tag":"Tenant","type":"*variable","value":"~*req.6"},{"mandatory":true,"path":"*cgreq.Category","tag":"Category","type":"*variable","value":"~*req.7"},{"mandatory":true,"path":"*cgreq.Account","tag":"Account","type":"*variable","value":"~*req.8"},{"mandatory":true,"path":"*cgreq.Subject","tag":"Subject","type":"*variable","value":"~*req.9"},{"mandatory":true,"path":"*cgreq.Destination","tag":"Destination","type":"*variable","value":"~*req.10"},{"mandatory":true,"path":"*cgreq.SetupTime","tag":"SetupTime","type":"*variable","value":"~*req.11"},{"mandatory":true,"path":"*cgreq.AnswerTime","tag":"AnswerTime","type":"*variable","value":"~*req.12"},{"mandatory":true,"path":"*cgreq.Usage","tag":"Usage","type":"*variable","value":"~*req.13"}],"filters":[],"flags":[],"id":"*default","opts":{"csvFieldSeparator":",","csvHeaderDefineChar":":","csvRowLength":0,"natsSubject":"cgrates_cdrs","partialCacheAction":"*none","partialOrderField":"~*req.AnswerTime","xmlRootPath":""},"partial_commit_fields":[],"processed_path":"/var/spool/cgrates/ers/out","run_delay":"0","source_path":"/var/spool/cgrates/ers/in","tenant":"","timezone":"","type":"*none"}],"sessions_conns":["*internal"]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: ERsJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: ERsJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5146,7 +5148,7 @@ func TestV1GetConfigAsJSONSIPAgent(t *testing.T) { var reply string expected := `{"sip_agent":{"enabled":false,"listen":"127.0.0.1:5060","listen_net":"udp","request_processors":[],"retransmission_timer":1000000000,"sessions_conns":["*internal"],"timezone":""}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: SIPAgentJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: SIPAgentJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5157,7 +5159,7 @@ func TestV1GetConfigAsJSONConfigS(t *testing.T) { var reply string expected := `{"configs":{"enabled":false,"root_dir":"/var/spool/cgrates/configs","url":"/configs/"}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: ConfigSJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: ConfigSJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5168,7 +5170,7 @@ func TestV1GetConfigAsJSONApiBan(t *testing.T) { var reply string expected := `{"apiban":{"keys":[]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: APIBanCfgJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: APIBanCfgJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5179,7 +5181,7 @@ func TestV1GetConfigAsJSONSentryPeer(t *testing.T) { var reply string expected := `{"sentrypeer":{"Audience":"https://sentrypeer.com/api","ClientID":"","ClientSecret":"","GrantType":"client_credentials","IpUrl":"https://sentrypeer.com/api/ip-addresses","NumberUrl":"https://sentrypeer.com/api/phone-numbers","TokenURL":"https://authz.sentrypeer.com/oauth/token"}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: SentryPeerCfgJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: SentryPeerCfgJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5190,7 +5192,7 @@ func TestV1GetConfigAsJSONRPCConns(t *testing.T) { var reply string expected := `{"rpc_conns":{"*bijson_localhost":{"conns":[{"address":"127.0.0.1:2014","transport":"*birpc_json"}],"poolSize":0,"strategy":"*first"},"*birpc_internal":{"conns":[{"address":"*birpc_internal","transport":""}],"poolSize":0,"strategy":"*first"},"*internal":{"conns":[{"address":"*internal","transport":""}],"poolSize":0,"strategy":"*first"},"*localhost":{"conns":[{"address":"127.0.0.1:2012","transport":"*json"}],"poolSize":0,"strategy":"*first"}}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: RPCConnsJsonName}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: RPCConnsJsonName}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5201,7 +5203,7 @@ func TestV1GetConfigAsJSONTemplates(t *testing.T) { var reply string expected := `{"templates":{"*asr":[{"mandatory":true,"path":"*diamreq.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"mandatory":true,"path":"*diamreq.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*req.Destination-Host"},{"mandatory":true,"path":"*diamreq.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*req.Destination-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Realm","tag":"DestinationRealm","type":"*variable","value":"~*req.Origin-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Host","tag":"DestinationHost","type":"*variable","value":"~*req.Origin-Host"},{"mandatory":true,"path":"*diamreq.Auth-Application-Id","tag":"AuthApplicationId","type":"*variable","value":"~*vars.*appid"}],"*cca":[{"mandatory":true,"path":"*rep.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"path":"*rep.Result-Code","tag":"ResultCode","type":"*constant","value":"2001"},{"mandatory":true,"path":"*rep.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*vars.OriginHost"},{"mandatory":true,"path":"*rep.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*vars.OriginRealm"},{"mandatory":true,"path":"*rep.Auth-Application-Id","tag":"AuthApplicationId","type":"*variable","value":"~*vars.*appid"},{"mandatory":true,"path":"*rep.CC-Request-Type","tag":"CCRequestType","type":"*variable","value":"~*req.CC-Request-Type"},{"mandatory":true,"path":"*rep.CC-Request-Number","tag":"CCRequestNumber","type":"*variable","value":"~*req.CC-Request-Number"}],"*cdrLog":[{"mandatory":true,"path":"*cdr.ToR","tag":"ToR","type":"*variable","value":"~*req.BalanceType"},{"mandatory":true,"path":"*cdr.OriginHost","tag":"OriginHost","type":"*constant","value":"127.0.0.1"},{"mandatory":true,"path":"*cdr.RequestType","tag":"RequestType","type":"*constant","value":"*none"},{"mandatory":true,"path":"*cdr.Tenant","tag":"Tenant","type":"*variable","value":"~*req.Tenant"},{"mandatory":true,"path":"*cdr.Account","tag":"Account","type":"*variable","value":"~*req.Account"},{"mandatory":true,"path":"*cdr.Subject","tag":"Subject","type":"*variable","value":"~*req.Account"},{"mandatory":true,"path":"*cdr.Cost","tag":"Cost","type":"*variable","value":"~*req.Cost"},{"mandatory":true,"path":"*cdr.Source","tag":"Source","type":"*constant","value":"*cdrLog"},{"mandatory":true,"path":"*cdr.Usage","tag":"Usage","type":"*constant","value":"1"},{"mandatory":true,"path":"*cdr.RunID","tag":"RunID","type":"*variable","value":"~*req.ActionType"},{"mandatory":true,"path":"*cdr.SetupTime","tag":"SetupTime","type":"*constant","value":"*now"},{"mandatory":true,"path":"*cdr.AnswerTime","tag":"AnswerTime","type":"*constant","value":"*now"},{"mandatory":true,"path":"*cdr.PreRated","tag":"PreRated","type":"*constant","value":"true"}],"*err":[{"mandatory":true,"path":"*rep.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"mandatory":true,"path":"*rep.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*vars.OriginHost"},{"mandatory":true,"path":"*rep.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*vars.OriginRealm"}],"*errSip":[{"mandatory":true,"path":"*rep.Request","tag":"Request","type":"*constant","value":"SIP/2.0 500 Internal Server Error"}],"*rar":[{"mandatory":true,"path":"*diamreq.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"mandatory":true,"path":"*diamreq.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*req.Destination-Host"},{"mandatory":true,"path":"*diamreq.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*req.Destination-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Realm","tag":"DestinationRealm","type":"*variable","value":"~*req.Origin-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Host","tag":"DestinationHost","type":"*variable","value":"~*req.Origin-Host"},{"mandatory":true,"path":"*diamreq.Auth-Application-Id","tag":"AuthApplicationId","type":"*variable","value":"~*vars.*appid"},{"path":"*diamreq.Re-Auth-Request-Type","tag":"ReAuthRequestType","type":"*constant","value":"0"}]}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: TemplatesJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: TemplatesJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5212,7 +5214,7 @@ func TestV1GetConfigAsJSONHTTPAgent(t *testing.T) { var reply string expected := `{"http_agent":[]}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: HttpAgentJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: HttpAgentJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5223,7 +5225,7 @@ func TestV1GetConfigAsJSONMailer(t *testing.T) { var reply string expected := `{"mailer":{"auth_password":"CGRateS.org","auth_user":"cgrates","from_address":"cgr-mailer@localhost.localdomain","server":"localhost"}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: MAILER_JSN}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: MAILER_JSN}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5234,7 +5236,7 @@ func TestV1GetConfigAsJSONAnalyzer(t *testing.T) { var reply string expected := `{"analyzers":{"cleanup_interval":"1h0m0s","db_path":"/var/spool/cgrates/analyzers","enabled":false,"index_type":"*scorch","ttl":"24h0m0s"}}` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: AnalyzerCfgJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: AnalyzerCfgJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5247,7 +5249,7 @@ func TestV1GetConfigAsJSONCoreS(t *testing.T) { cgrCfg := NewDefaultCGRConfig() cgrCfg.coreSCfg.Caps = 10 - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: CoreSCfgJson}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: CoreSCfgJson}, &reply); err != nil { t.Error(err) } else if expected != reply { t.Errorf("Expected %+v \n, received %+v", expected, reply) @@ -5258,7 +5260,7 @@ func TestV1GetConfigAsJSONCoreS(t *testing.T) { for _, section := range sortedCfgSections { cfgCgr2.rldChans[section] = make(chan struct{}, 1) } - if err = cfgCgr2.V1SetConfigFromJSON(&SetConfigFromJSONArgs{Config: reply, DryRun: true}, &result); err != nil { + if err = cfgCgr2.V1SetConfigFromJSON(context.Background(), &SetConfigFromJSONArgs{Config: reply, DryRun: true}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Errorf("Unexpected result") @@ -5268,7 +5270,7 @@ func TestV1GetConfigAsJSONCoreS(t *testing.T) { for _, section := range sortedCfgSections { cfgCgr2.rldChans[section] = make(chan struct{}, 1) } - if err = cfgCgr2.V1SetConfigFromJSON(&SetConfigFromJSONArgs{Config: reply}, &result); err != nil { + if err = cfgCgr2.V1SetConfigFromJSON(context.Background(), &SetConfigFromJSONArgs{Config: reply}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Errorf("Unexpected result") @@ -5291,7 +5293,7 @@ func TestV1GetConfigAsJSONCheckConfigSanity(t *testing.T) { cfgCgr2.rldChans[section] = make(chan struct{}, 1) } - if err = cfgCgr2.V1SetConfigFromJSON(&SetConfigFromJSONArgs{Config: args}, &result); err == nil || err.Error() != expected { + if err = cfgCgr2.V1SetConfigFromJSON(context.Background(), &SetConfigFromJSONArgs{Config: args}, &result); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -5300,7 +5302,7 @@ func TestV1GetConfigAsJSONInvalidSection(t *testing.T) { var reply string expected := `Invalid section` cgrCfg := NewDefaultCGRConfig() - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: "InvalidSection"}, &reply); err == nil || err.Error() != expected { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: "InvalidSection"}, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -5318,12 +5320,12 @@ func TestV1GetConfigAsJSONAllConfig(t *testing.T) { t.Fatal(err) } cgrCfg.SureTaxCfg().Timezone = time.UTC - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: utils.EmptyString}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: utils.EmptyString}, &reply); err != nil { t.Fatal(err) } else if expected != reply { t.Fatalf("Expected %+v \n, received %+v", expected, reply) } - if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: utils.EmptyString}, &reply); err != nil { + if err := cgrCfg.V1GetConfigAsJSON(context.Background(), &SectionWithAPIOpts{Section: utils.EmptyString}, &reply); err != nil { t.Fatal(err) } else if expected != reply { t.Fatalf("Expected %+v \n, received %+v", expected, reply) @@ -5336,7 +5338,7 @@ func TestV1ReloadConfigFromJSONEmptyConfig(t *testing.T) { for _, section := range sortedCfgSections { cgrCfg.rldChans[section] = make(chan struct{}, 1) } - if err := cgrCfg.V1SetConfigFromJSON(&SetConfigFromJSONArgs{Config: utils.EmptyString}, &reply); err != nil { + if err := cgrCfg.V1SetConfigFromJSON(context.Background(), &SetConfigFromJSONArgs{Config: utils.EmptyString}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply") @@ -5350,7 +5352,7 @@ func TestV1ReloadConfigFromJSONInvalidSection(t *testing.T) { for _, section := range sortedCfgSections { cgrCfg.rldChans[section] = make(chan struct{}, 1) } - if err := cgrCfg.V1SetConfigFromJSON(&SetConfigFromJSONArgs{Config: "InvalidSection"}, &reply); err == nil || err.Error() != expected { + if err := cgrCfg.V1SetConfigFromJSON(context.Background(), &SetConfigFromJSONArgs{Config: "InvalidSection"}, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -5719,7 +5721,7 @@ func TestLoadConfigFromReaderLoadFunctionsError(t *testing.T) { func TestCallOnCGRConfig(t *testing.T) { expected := "UNSUPPORTED_SERVICE_METHOD" cgrcfg := NewDefaultCGRConfig() - if err := cgrcfg.Call("inexistentMethod", nil, nil); err == nil || err.Error() != expected { + if err := cgrcfg.Call(context.Background(), "inexistentMethod", nil, nil); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } diff --git a/console/account_actionplan_get_test.go b/console/account_actionplan_get_test.go index 814aed328..f45a3d437 100644 --- a/console/account_actionplan_get_test.go +++ b/console/account_actionplan_get_test.go @@ -36,15 +36,15 @@ func TestCmdGetAccountActionPlan(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/account_remove_test.go b/console/account_remove_test.go index e546ec65d..1e9d998a1 100644 --- a/console/account_remove_test.go +++ b/console/account_remove_test.go @@ -36,15 +36,15 @@ func TestCmdRemoveAccount(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/account_set_test.go b/console/account_set_test.go index 9844e67ba..014a4097e 100644 --- a/console/account_set_test.go +++ b/console/account_set_test.go @@ -36,15 +36,15 @@ func TestCmdSetAccount(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/account_trigger_add_test.go b/console/account_trigger_add_test.go index 18a8bc68f..f64726f14 100644 --- a/console/account_trigger_add_test.go +++ b/console/account_trigger_add_test.go @@ -36,16 +36,16 @@ func TestCmdAccountTriggerAdd(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/account_trigger_remove_test.go b/console/account_trigger_remove_test.go index e2b5b15c0..0a77adbf6 100644 --- a/console/account_trigger_remove_test.go +++ b/console/account_trigger_remove_test.go @@ -35,15 +35,15 @@ func TestCmdAccountTriggerRemove(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/account_trigger_reset_test.go b/console/account_trigger_reset_test.go index c9633a69b..e0a785ccd 100644 --- a/console/account_trigger_reset_test.go +++ b/console/account_trigger_reset_test.go @@ -35,15 +35,15 @@ func TestCmdAccountTriggerReset(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/account_trigger_set_test.go b/console/account_trigger_set_test.go index 76e17df91..2786b75dd 100644 --- a/console/account_trigger_set_test.go +++ b/console/account_trigger_set_test.go @@ -35,15 +35,15 @@ func TestCmdAccountTriggerSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/accounts_test.go b/console/accounts_test.go index 0f794a143..5a927d1b9 100644 --- a/console/accounts_test.go +++ b/console/accounts_test.go @@ -36,15 +36,15 @@ func TestCmdAccounts(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/action_execute_test.go b/console/action_execute_test.go index 39646db12..5851b0e83 100644 --- a/console/action_execute_test.go +++ b/console/action_execute_test.go @@ -36,15 +36,15 @@ func TestCmdActionExecute(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/actionplan_get_test.go b/console/actionplan_get_test.go index 96d37af06..29f69a338 100644 --- a/console/actionplan_get_test.go +++ b/console/actionplan_get_test.go @@ -36,15 +36,15 @@ func TestCmdActionPlanGet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/actionplan_remove_test.go b/console/actionplan_remove_test.go index 5e1c722e5..876ab2229 100644 --- a/console/actionplan_remove_test.go +++ b/console/actionplan_remove_test.go @@ -36,15 +36,15 @@ func TestCmdActionPlanRemove(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/actionplan_set_test.go b/console/actionplan_set_test.go index 343e50223..9346f0684 100644 --- a/console/actionplan_set_test.go +++ b/console/actionplan_set_test.go @@ -36,15 +36,15 @@ func TestCmdActionPlanSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/active_sessions_test.go b/console/active_sessions_test.go index cd3880748..03c0bbd68 100644 --- a/console/active_sessions_test.go +++ b/console/active_sessions_test.go @@ -36,15 +36,15 @@ func TestCmdActiveSessions(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/attributes_for_event_test.go b/console/attributes_for_event_test.go index 78a6b16a0..c6636c778 100644 --- a/console/attributes_for_event_test.go +++ b/console/attributes_for_event_test.go @@ -36,15 +36,15 @@ func TestCmdAttributesForEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/attributes_process_event_test.go b/console/attributes_process_event_test.go index 90b5d1c1f..62ce1f2f6 100644 --- a/console/attributes_process_event_test.go +++ b/console/attributes_process_event_test.go @@ -36,15 +36,15 @@ func TestCmdAttributesProcessEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/attributes_profile_ids_test.go b/console/attributes_profile_ids_test.go index fcc4a2beb..8f6feb429 100644 --- a/console/attributes_profile_ids_test.go +++ b/console/attributes_profile_ids_test.go @@ -36,15 +36,15 @@ func TestCmdAttributesProfileIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/attributes_profile_rem_test.go b/console/attributes_profile_rem_test.go index e41d1ae83..33ef6ae72 100644 --- a/console/attributes_profile_rem_test.go +++ b/console/attributes_profile_rem_test.go @@ -36,15 +36,15 @@ func TestCmdAttributesProfileRem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/attributes_profile_set_test.go b/console/attributes_profile_set_test.go index e77ccc3e4..38be3c493 100644 --- a/console/attributes_profile_set_test.go +++ b/console/attributes_profile_set_test.go @@ -36,15 +36,15 @@ func TestCmdAttributesProfileSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/attributes_profile_test.go b/console/attributes_profile_test.go index d406c9696..65e59d91d 100644 --- a/console/attributes_profile_test.go +++ b/console/attributes_profile_test.go @@ -36,15 +36,15 @@ func TestCmdAttributesProfile(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/balance_add_test.go b/console/balance_add_test.go index 79cca09bd..347a8004c 100644 --- a/console/balance_add_test.go +++ b/console/balance_add_test.go @@ -36,15 +36,15 @@ func TestCmdBalanceAdd(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/balance_debit_test.go b/console/balance_debit_test.go index 025d459e1..60a0b544b 100644 --- a/console/balance_debit_test.go +++ b/console/balance_debit_test.go @@ -36,15 +36,15 @@ func TestCmdBalanceDebit(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/balance_remove_test.go b/console/balance_remove_test.go index 1df36f508..4f988d4f4 100644 --- a/console/balance_remove_test.go +++ b/console/balance_remove_test.go @@ -35,15 +35,15 @@ func TestCmdBalanceRemove(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/balance_set_test.go b/console/balance_set_test.go index 1fd75fb97..279f1eff2 100644 --- a/console/balance_set_test.go +++ b/console/balance_set_test.go @@ -36,15 +36,15 @@ func TestCmdBalanceSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_clear_test.go b/console/cache_clear_test.go index efedccc4d..393130f58 100644 --- a/console/cache_clear_test.go +++ b/console/cache_clear_test.go @@ -36,15 +36,15 @@ func TestCmdCacheClear(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_group_item_id_test.go b/console/cache_group_item_id_test.go index 8564fd2f3..cb3a5e4c0 100644 --- a/console/cache_group_item_id_test.go +++ b/console/cache_group_item_id_test.go @@ -36,15 +36,15 @@ func TestCmdCacheGroupItemId(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_has_group_test.go b/console/cache_has_group_test.go index 7da590c51..c658818b3 100644 --- a/console/cache_has_group_test.go +++ b/console/cache_has_group_test.go @@ -36,15 +36,15 @@ func TestCmdCacheHasGroup(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_has_item_test.go b/console/cache_has_item_test.go index 79ec6dd94..aa9e9ffe3 100644 --- a/console/cache_has_item_test.go +++ b/console/cache_has_item_test.go @@ -36,15 +36,15 @@ func TestCmdCacheHasItem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_item_expiry_time_test.go b/console/cache_item_expiry_time_test.go index 1838bc4d0..1ac734f28 100644 --- a/console/cache_item_expiry_time_test.go +++ b/console/cache_item_expiry_time_test.go @@ -36,15 +36,15 @@ func TestCmdCacheExpiryTime(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_item_ids_test.go b/console/cache_item_ids_test.go index 54fd6e715..a2b659d79 100644 --- a/console/cache_item_ids_test.go +++ b/console/cache_item_ids_test.go @@ -36,15 +36,15 @@ func TestCmdCacheItermIds(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_precache_status_test.go b/console/cache_precache_status_test.go index 9af81dc57..0d7300332 100644 --- a/console/cache_precache_status_test.go +++ b/console/cache_precache_status_test.go @@ -36,15 +36,15 @@ func TestCmdCachePrecacheStatus(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_reload_test.go b/console/cache_reload_test.go index c0b0199e0..05b7ab13a 100644 --- a/console/cache_reload_test.go +++ b/console/cache_reload_test.go @@ -36,15 +36,15 @@ func TestCmdCacheReload(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_remove_group_test.go b/console/cache_remove_group_test.go index 4020dff74..9ffcf7ab4 100644 --- a/console/cache_remove_group_test.go +++ b/console/cache_remove_group_test.go @@ -36,15 +36,15 @@ func TestCmdCacheRemoveGroup(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_remove_item_test.go b/console/cache_remove_item_test.go index 57d43e5ec..0cac8bdb9 100644 --- a/console/cache_remove_item_test.go +++ b/console/cache_remove_item_test.go @@ -36,15 +36,15 @@ func TestCmdCacheRemoveItem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cache_stats_test.go b/console/cache_stats_test.go index 92aa609c0..a6083341e 100644 --- a/console/cache_stats_test.go +++ b/console/cache_stats_test.go @@ -36,15 +36,15 @@ func TestCmdCacheStats(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cdrs_test.go b/console/cdrs_test.go index e918a5f89..2ce81b5aa 100644 --- a/console/cdrs_test.go +++ b/console/cdrs_test.go @@ -36,15 +36,15 @@ func TestCmdCdrs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/chargers_for_event_test.go b/console/chargers_for_event_test.go index 5be956e68..6a3c0e322 100644 --- a/console/chargers_for_event_test.go +++ b/console/chargers_for_event_test.go @@ -36,15 +36,15 @@ func TestCmdChargersForEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/chargers_process_event_test.go b/console/chargers_process_event_test.go index a9246c1f3..d57fd8174 100644 --- a/console/chargers_process_event_test.go +++ b/console/chargers_process_event_test.go @@ -35,15 +35,15 @@ func TestCmdChargersProcessEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/chargers_profile_ids_test.go b/console/chargers_profile_ids_test.go index 25332d8a5..9ed499948 100644 --- a/console/chargers_profile_ids_test.go +++ b/console/chargers_profile_ids_test.go @@ -35,15 +35,15 @@ func TestCmdChargersProfileIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/chargers_profile_rem_test.go b/console/chargers_profile_rem_test.go index 033e845f2..b15e69b72 100644 --- a/console/chargers_profile_rem_test.go +++ b/console/chargers_profile_rem_test.go @@ -35,15 +35,15 @@ func TestCmdChargersProfileRem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/chargers_profile_set_test.go b/console/chargers_profile_set_test.go index b68286943..b399d33b9 100644 --- a/console/chargers_profile_set_test.go +++ b/console/chargers_profile_set_test.go @@ -35,15 +35,15 @@ func TestCmdChargersProfileSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/chargers_profile_test.go b/console/chargers_profile_test.go index 2770bda29..27f10f2df 100644 --- a/console/chargers_profile_test.go +++ b/console/chargers_profile_test.go @@ -36,15 +36,15 @@ func TestCmdChargersProfile(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameterme - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/compute_actionplan_indexes_test.go b/console/compute_actionplan_indexes_test.go index 9851d1fae..bb3d54e91 100644 --- a/console/compute_actionplan_indexes_test.go +++ b/console/compute_actionplan_indexes_test.go @@ -35,7 +35,7 @@ func TestCmdComputeActionPlanIndexes(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } @@ -45,7 +45,7 @@ func TestCmdComputeActionPlanIndexes(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(EmptyWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/compute_filter_indexes_test.go b/console/compute_filter_indexes_test.go index 17947664b..ffd6ac23b 100644 --- a/console/compute_filter_indexes_test.go +++ b/console/compute_filter_indexes_test.go @@ -35,15 +35,15 @@ func TestCmdComputeFilterIndexes(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cost_details_test.go b/console/cost_details_test.go index 732b6be35..f1e99beb5 100644 --- a/console/cost_details_test.go +++ b/console/cost_details_test.go @@ -35,15 +35,15 @@ func TestCmdCostDetails(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/cost_test.go b/console/cost_test.go index 9bb44a2d4..ad0a50800 100644 --- a/console/cost_test.go +++ b/console/cost_test.go @@ -35,15 +35,15 @@ func TestCmdCost(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/datacost_test.go b/console/datacost_test.go index 2c2882a71..6ad3a34a0 100644 --- a/console/datacost_test.go +++ b/console/datacost_test.go @@ -35,15 +35,15 @@ func TestCmdDatacost(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/datadb_versions_test.go b/console/datadb_versions_test.go index 8dbb84836..f9aedd6b3 100644 --- a/console/datadb_versions_test.go +++ b/console/datadb_versions_test.go @@ -35,7 +35,7 @@ func TestCmdDataDBVersions(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } @@ -45,7 +45,7 @@ func TestCmdDataDBVersions(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(EmptyWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/debit_max_test.go b/console/debit_max_test.go index 5dcf4a91f..104c9414f 100644 --- a/console/debit_max_test.go +++ b/console/debit_max_test.go @@ -35,15 +35,15 @@ func TestCmdDebitMax(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/debit_test.go b/console/debit_test.go index 396e6cd8f..fc8214efa 100644 --- a/console/debit_test.go +++ b/console/debit_test.go @@ -35,15 +35,15 @@ func TestCmdDebit(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/destination_set_test.go b/console/destination_set_test.go index 134bc8c0f..9197d1675 100644 --- a/console/destination_set_test.go +++ b/console/destination_set_test.go @@ -35,15 +35,15 @@ func TestCmdDestinationSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/destinations_test.go b/console/destinations_test.go index 00fe47104..bcbca8fd1 100644 --- a/console/destinations_test.go +++ b/console/destinations_test.go @@ -36,15 +36,15 @@ func TestCmdDestinations(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/dispatchers_for_event_test.go b/console/dispatchers_for_event_test.go index b4e7309df..5024e95fa 100644 --- a/console/dispatchers_for_event_test.go +++ b/console/dispatchers_for_event_test.go @@ -36,15 +36,15 @@ func TestCmdDispatchersForEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/dispatchers_host_ids_test.go b/console/dispatchers_host_ids_test.go index 23664569c..b64e1baf6 100644 --- a/console/dispatchers_host_ids_test.go +++ b/console/dispatchers_host_ids_test.go @@ -36,15 +36,15 @@ func TestCmdDispatchersHostIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/dispatchers_host_rem_test.go b/console/dispatchers_host_rem_test.go index 0b91a8ce5..fb94048e1 100644 --- a/console/dispatchers_host_rem_test.go +++ b/console/dispatchers_host_rem_test.go @@ -36,15 +36,15 @@ func TestCmdDispatchersHostRem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/dispatchers_host_set_test.go b/console/dispatchers_host_set_test.go index 907ac00c9..ab32b4c2a 100644 --- a/console/dispatchers_host_set_test.go +++ b/console/dispatchers_host_set_test.go @@ -36,15 +36,15 @@ func TestCmdDispatchersHostSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/dispatchers_host_test.go b/console/dispatchers_host_test.go index 039764729..d09724b4e 100644 --- a/console/dispatchers_host_test.go +++ b/console/dispatchers_host_test.go @@ -36,15 +36,15 @@ func TestCmdDispatchersHost(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/dispatchers_profile_ids_test.go b/console/dispatchers_profile_ids_test.go index 942d8a8bc..395541c7e 100644 --- a/console/dispatchers_profile_ids_test.go +++ b/console/dispatchers_profile_ids_test.go @@ -36,15 +36,15 @@ func TestCmdDispatchersProfileIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/dispatchers_profile_rem_test.go b/console/dispatchers_profile_rem_test.go index f798d7859..bbd226374 100644 --- a/console/dispatchers_profile_rem_test.go +++ b/console/dispatchers_profile_rem_test.go @@ -36,15 +36,15 @@ func TestCmdDispatchersProfileRem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/dispatchers_profile_set_test.go b/console/dispatchers_profile_set_test.go index 4a1596735..e08852b80 100644 --- a/console/dispatchers_profile_set_test.go +++ b/console/dispatchers_profile_set_test.go @@ -36,15 +36,15 @@ func TestCmdDispatchersProfileSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/dispatchers_profile_test.go b/console/dispatchers_profile_test.go index e4a3339a2..385a9e831 100644 --- a/console/dispatchers_profile_test.go +++ b/console/dispatchers_profile_test.go @@ -36,15 +36,15 @@ func TestCmdDispatchersProfile(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/filter_ids_test.go b/console/filter_ids_test.go index c57c6180a..f96a06c54 100644 --- a/console/filter_ids_test.go +++ b/console/filter_ids_test.go @@ -36,15 +36,15 @@ func TestCmdFilterIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/filter_indexes_remove_test.go b/console/filter_indexes_remove_test.go index 75e5aa9ae..18e84f71e 100644 --- a/console/filter_indexes_remove_test.go +++ b/console/filter_indexes_remove_test.go @@ -36,15 +36,15 @@ func TestCmdFilterIndexesRem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/filter_indexes_test.go b/console/filter_indexes_test.go index 124f0272f..f63c14f79 100644 --- a/console/filter_indexes_test.go +++ b/console/filter_indexes_test.go @@ -36,15 +36,15 @@ func TestCmdFilterIndexes(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/filter_remove_test.go b/console/filter_remove_test.go index bc35e3746..7709493ac 100644 --- a/console/filter_remove_test.go +++ b/console/filter_remove_test.go @@ -36,15 +36,15 @@ func TestCmdFilterRem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/filter_set_test.go b/console/filter_set_test.go index 318e7244a..49a9d44bb 100644 --- a/console/filter_set_test.go +++ b/console/filter_set_test.go @@ -36,15 +36,15 @@ func TestCmdFilterSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/filter_test.go b/console/filter_test.go index 76162514f..5ed2595ef 100644 --- a/console/filter_test.go +++ b/console/filter_test.go @@ -36,15 +36,15 @@ func TestCmdFilter(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/get_json_section_test.go b/console/get_json_section_test.go index 28a53f9d8..dc2fd82b0 100644 --- a/console/get_json_section_test.go +++ b/console/get_json_section_test.go @@ -36,15 +36,15 @@ func TestCmdGetJSONSection(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/import_tp_from_folder_test.go b/console/import_tp_from_folder_test.go index c8ca0f4af..ac6fa0dd3 100644 --- a/console/import_tp_from_folder_test.go +++ b/console/import_tp_from_folder_test.go @@ -36,15 +36,15 @@ func TestCmdTPFromFolder(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/load_history_test.go b/console/load_history_test.go index 6a0d7445a..904e8686e 100644 --- a/console/load_history_test.go +++ b/console/load_history_test.go @@ -36,15 +36,15 @@ func TestCmdLoadHistory(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/load_ids_test.go b/console/load_ids_test.go index a58775588..9c0b11282 100644 --- a/console/load_ids_test.go +++ b/console/load_ids_test.go @@ -35,7 +35,7 @@ func TestCmdLoadIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -44,7 +44,7 @@ func TestCmdLoadIDs(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/load_times_test.go b/console/load_times_test.go index 8126e398b..808a26343 100644 --- a/console/load_times_test.go +++ b/console/load_times_test.go @@ -36,15 +36,15 @@ func TestCmdLoadTimes(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/load_tp_from_folder_test.go b/console/load_tp_from_folder_test.go index 9936202b7..1f0f64dd9 100644 --- a/console/load_tp_from_folder_test.go +++ b/console/load_tp_from_folder_test.go @@ -36,15 +36,15 @@ func TestCmdLoadTPFromFolder(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/load_tp_from_stordb_test.go b/console/load_tp_from_stordb_test.go index 0319f831a..852d03e9d 100644 --- a/console/load_tp_from_stordb_test.go +++ b/console/load_tp_from_stordb_test.go @@ -36,15 +36,15 @@ func TestCmdLoadTPFromStorDB(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/loader_load_test.go b/console/loader_load_test.go index c8911a6f7..6722448e1 100644 --- a/console/loader_load_test.go +++ b/console/loader_load_test.go @@ -36,15 +36,15 @@ func TestCmdLoaderLoad(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/loader_remove_test.go b/console/loader_remove_test.go index c069417eb..9e9c01283 100644 --- a/console/loader_remove_test.go +++ b/console/loader_remove_test.go @@ -36,15 +36,15 @@ func TestCmdLoaderRemove(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/maxduration_test.go b/console/maxduration_test.go index 4fcfdaa1e..d18bb81a0 100644 --- a/console/maxduration_test.go +++ b/console/maxduration_test.go @@ -35,15 +35,15 @@ func TestCmdMaxDuration(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/maxusage_test.go b/console/maxusage_test.go index bf189e2ba..67460111d 100644 --- a/console/maxusage_test.go +++ b/console/maxusage_test.go @@ -36,15 +36,15 @@ func TestCmdMaxUsage(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/passive_sessions_test.go b/console/passive_sessions_test.go index 6de89eb22..886b32f34 100644 --- a/console/passive_sessions_test.go +++ b/console/passive_sessions_test.go @@ -36,15 +36,15 @@ func TestCmdPassiveSessions(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/ping_test.go b/console/ping_test.go index f3479d457..81dacf574 100644 --- a/console/ping_test.go +++ b/console/ping_test.go @@ -43,7 +43,7 @@ func TestCmdPingRoutesLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -52,7 +52,7 @@ func TestCmdPingRoutesLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -77,7 +77,7 @@ func TestCmdPingAttributesLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -86,7 +86,7 @@ func TestCmdPingAttributesLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -112,7 +112,7 @@ func TestCmdPingChargerSLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -121,7 +121,7 @@ func TestCmdPingChargerSLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -147,7 +147,7 @@ func TestCmdPingResourcesLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -156,7 +156,7 @@ func TestCmdPingResourcesLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -182,7 +182,7 @@ func TestCmdPingStatServiceLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -191,7 +191,7 @@ func TestCmdPingStatServiceLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -216,7 +216,7 @@ func TestCmdPingThresholdsLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -225,7 +225,7 @@ func TestCmdPingThresholdsLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -250,7 +250,7 @@ func TestCmdPingSessionsLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -259,7 +259,7 @@ func TestCmdPingSessionsLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -284,7 +284,7 @@ func TestCmdPingLoaderSLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -293,7 +293,7 @@ func TestCmdPingLoaderSLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -318,7 +318,7 @@ func TestCmdPingDispatcherSLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -327,7 +327,7 @@ func TestCmdPingDispatcherSLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -352,7 +352,7 @@ func TestCmdPingAnalyzerSLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -361,7 +361,7 @@ func TestCmdPingAnalyzerSLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -386,7 +386,7 @@ func TestCmdPingSchedulerSLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -395,7 +395,7 @@ func TestCmdPingSchedulerSLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -420,7 +420,7 @@ func TestCmdPingRALsLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -429,7 +429,7 @@ func TestCmdPingRALsLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -454,7 +454,7 @@ func TestCmdPingReplicatorLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -463,7 +463,7 @@ func TestCmdPingReplicatorLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -488,7 +488,7 @@ func TestCmdPingApierSLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -497,7 +497,7 @@ func TestCmdPingApierSLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose @@ -522,7 +522,7 @@ func TestCmdPingEEsLow(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -531,7 +531,7 @@ func TestCmdPingEEsLow(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/ratingplan_cost_test.go b/console/ratingplan_cost_test.go index 8ec9512ed..b976f415f 100644 --- a/console/ratingplan_cost_test.go +++ b/console/ratingplan_cost_test.go @@ -36,15 +36,15 @@ func TestCmdRatingPlanCost(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/ratingprofile_ids_test.go b/console/ratingprofile_ids_test.go index 52e449e09..83f14f676 100644 --- a/console/ratingprofile_ids_test.go +++ b/console/ratingprofile_ids_test.go @@ -36,15 +36,15 @@ func TestCmdRatingPlanIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/ratingprofile_remove_test.go b/console/ratingprofile_remove_test.go index c3da0a2a9..6eb8ce71c 100644 --- a/console/ratingprofile_remove_test.go +++ b/console/ratingprofile_remove_test.go @@ -35,15 +35,15 @@ func TestCmdRatingPlanRem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } diff --git a/console/ratingprofile_set_test.go b/console/ratingprofile_set_test.go index 8be1a9138..8dbb7b2ba 100644 --- a/console/ratingprofile_set_test.go +++ b/console/ratingprofile_set_test.go @@ -36,15 +36,15 @@ func TestCmdRatingPlanSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/ratingprofile_test.go b/console/ratingprofile_test.go index 083d09fba..9b930f115 100644 --- a/console/ratingprofile_test.go +++ b/console/ratingprofile_test.go @@ -36,15 +36,15 @@ func TestCmdRatingPlan(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/reload_config_test.go b/console/reload_config_test.go index d4433789c..748d21cdf 100644 --- a/console/reload_config_test.go +++ b/console/reload_config_test.go @@ -36,15 +36,15 @@ func TestCmdReloadConfig(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/resources_allocate_test.go b/console/resources_allocate_test.go index f084567f6..b2aa6a027 100644 --- a/console/resources_allocate_test.go +++ b/console/resources_allocate_test.go @@ -36,15 +36,15 @@ func TestCmdResourcesAllocate(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/resources_authorize_test.go b/console/resources_authorize_test.go index 1a46281a6..726f991e2 100644 --- a/console/resources_authorize_test.go +++ b/console/resources_authorize_test.go @@ -36,15 +36,15 @@ func TestCmdResourcesAuthorize(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/resources_for_event_test.go b/console/resources_for_event_test.go index 4600fb46a..6c5c219b4 100644 --- a/console/resources_for_event_test.go +++ b/console/resources_for_event_test.go @@ -36,15 +36,15 @@ func TestCmdResourcesForEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/resources_profile_ids_test.go b/console/resources_profile_ids_test.go index a8a6492ba..9a1202376 100644 --- a/console/resources_profile_ids_test.go +++ b/console/resources_profile_ids_test.go @@ -36,15 +36,15 @@ func TestCmdResourcesProfileIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/resources_profile_rem_test.go b/console/resources_profile_rem_test.go index 1aec01b00..dc0aadf8b 100644 --- a/console/resources_profile_rem_test.go +++ b/console/resources_profile_rem_test.go @@ -36,15 +36,15 @@ func TestCmdResourcesProfileRem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/resources_profile_set_test.go b/console/resources_profile_set_test.go index 08d8366ac..7911e6c8a 100644 --- a/console/resources_profile_set_test.go +++ b/console/resources_profile_set_test.go @@ -36,15 +36,15 @@ func TestCmdResourcesProfileSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/resources_profiles_test.go b/console/resources_profiles_test.go index 02132753b..6bd2839be 100644 --- a/console/resources_profiles_test.go +++ b/console/resources_profiles_test.go @@ -36,15 +36,15 @@ func TestCmdResourcesProfile(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/resources_release_test.go b/console/resources_release_test.go index 9a2e638b3..07ecfbf25 100644 --- a/console/resources_release_test.go +++ b/console/resources_release_test.go @@ -36,15 +36,15 @@ func TestCmdResourcesRelease(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/resources_test.go b/console/resources_test.go index 9bd743964..adfa01e94 100644 --- a/console/resources_test.go +++ b/console/resources_test.go @@ -36,15 +36,15 @@ func TestCmdResources(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/routes_profile_ids_test.go b/console/routes_profile_ids_test.go index 6607b81a9..6249d5883 100644 --- a/console/routes_profile_ids_test.go +++ b/console/routes_profile_ids_test.go @@ -36,15 +36,15 @@ func TestCmdRoutesProfileIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/routes_profile_remove_test.go b/console/routes_profile_remove_test.go index a40c444ed..9d1d85e3a 100644 --- a/console/routes_profile_remove_test.go +++ b/console/routes_profile_remove_test.go @@ -36,15 +36,15 @@ func TestCmdRoutesProfileRemove(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/routes_profile_set_test.go b/console/routes_profile_set_test.go index 5355da554..5fc557b78 100644 --- a/console/routes_profile_set_test.go +++ b/console/routes_profile_set_test.go @@ -36,15 +36,15 @@ func TestCmdRoutesProfileSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/routes_profile_test.go b/console/routes_profile_test.go index 037d01354..35f6587c3 100644 --- a/console/routes_profile_test.go +++ b/console/routes_profile_test.go @@ -36,15 +36,15 @@ func TestCmdRoutesProfile(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/routes_profiles_for_event_test.go b/console/routes_profiles_for_event_test.go index 3d6a45834..7a758885c 100644 --- a/console/routes_profiles_for_event_test.go +++ b/console/routes_profiles_for_event_test.go @@ -36,15 +36,15 @@ func TestCmdRoutesProfilesForEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/routes_test.go b/console/routes_test.go index 6e61cdfee..a3e0ddeb1 100644 --- a/console/routes_test.go +++ b/console/routes_test.go @@ -36,15 +36,15 @@ func TestCmdRoutes(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/scheduler_execute_test.go b/console/scheduler_execute_test.go index e69c4af5f..cda26cc78 100644 --- a/console/scheduler_execute_test.go +++ b/console/scheduler_execute_test.go @@ -36,15 +36,15 @@ func TestCmdSchedulerExecute(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/scheduler_queue_test.go b/console/scheduler_queue_test.go index 5a4c38de6..7b85c6abd 100644 --- a/console/scheduler_queue_test.go +++ b/console/scheduler_queue_test.go @@ -36,15 +36,15 @@ func TestCmdSchedulerQueue(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/scheduler_reload_test.go b/console/scheduler_reload_test.go index b551ca15c..5e9268e3c 100644 --- a/console/scheduler_reload_test.go +++ b/console/scheduler_reload_test.go @@ -36,15 +36,15 @@ func TestCmdSchedulerReload(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/session_authorize_event_test.go b/console/session_authorize_event_test.go index 6333d51e9..f74d3c513 100644 --- a/console/session_authorize_event_test.go +++ b/console/session_authorize_event_test.go @@ -36,15 +36,15 @@ func TestCmdSessionAuthorizeEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/session_force_disconnect_test.go b/console/session_force_disconnect_test.go index d79782d3c..989b6ce64 100644 --- a/console/session_force_disconnect_test.go +++ b/console/session_force_disconnect_test.go @@ -36,15 +36,15 @@ func TestCmdSessionForceDisconnect(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/session_initiate_test.go b/console/session_initiate_test.go index 263526a39..560e0d625 100644 --- a/console/session_initiate_test.go +++ b/console/session_initiate_test.go @@ -36,15 +36,15 @@ func TestCmdSessionInitiate(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/session_process_cdr_test.go b/console/session_process_cdr_test.go index 6fbb544d8..fe130e4e8 100644 --- a/console/session_process_cdr_test.go +++ b/console/session_process_cdr_test.go @@ -36,15 +36,15 @@ func TestCmdSessionProcessCDR(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/session_process_message_test.go b/console/session_process_message_test.go index a6b2ad150..48b5c9c20 100644 --- a/console/session_process_message_test.go +++ b/console/session_process_message_test.go @@ -36,15 +36,15 @@ func TestCmdSessionProcessMessage(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/session_terminate_test.go b/console/session_terminate_test.go index 2014da8be..8ec64be28 100644 --- a/console/session_terminate_test.go +++ b/console/session_terminate_test.go @@ -36,15 +36,15 @@ func TestCmdSessionTerminate(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/session_update_test.go b/console/session_update_test.go index 080b2840a..ef83d1cc7 100644 --- a/console/session_update_test.go +++ b/console/session_update_test.go @@ -36,15 +36,15 @@ func TestCmdSessionUpdate(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/set_datadb_versions_test.go b/console/set_datadb_versions_test.go index fd047f755..99e221118 100644 --- a/console/set_datadb_versions_test.go +++ b/console/set_datadb_versions_test.go @@ -35,15 +35,15 @@ func TestCmdSetDataDBVersions(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/set_stordb_versions_test.go b/console/set_stordb_versions_test.go index 0b71c22df..b3094a54f 100644 --- a/console/set_stordb_versions_test.go +++ b/console/set_stordb_versions_test.go @@ -35,15 +35,15 @@ func TestCmdSetStorDBVersions(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/sharedgroup_test.go b/console/sharedgroup_test.go index 0b56f28ce..55f966400 100644 --- a/console/sharedgroup_test.go +++ b/console/sharedgroup_test.go @@ -35,7 +35,7 @@ func TestCmdSharedGroup(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -44,7 +44,7 @@ func TestCmdSharedGroup(t *testing.T) { t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/sleep_test.go b/console/sleep_test.go index 561b2b196..e5468b8d4 100644 --- a/console/sleep_test.go +++ b/console/sleep_test.go @@ -35,15 +35,15 @@ func TestCmdSleep(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/stats_for_event_test.go b/console/stats_for_event_test.go index c1f7ed09f..0213ff523 100644 --- a/console/stats_for_event_test.go +++ b/console/stats_for_event_test.go @@ -35,15 +35,15 @@ func TestCmdStatsForEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/stats_metrics_test.go b/console/stats_metrics_test.go index cdfab6305..2f4c89441 100644 --- a/console/stats_metrics_test.go +++ b/console/stats_metrics_test.go @@ -35,15 +35,15 @@ func TestCmdStatsMetrics(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/stats_process_event_test.go b/console/stats_process_event_test.go index bcc7f7059..784db52bb 100644 --- a/console/stats_process_event_test.go +++ b/console/stats_process_event_test.go @@ -35,15 +35,15 @@ func TestCmdStatsProcessEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/stats_profile_ids_test.go b/console/stats_profile_ids_test.go index a961b58b9..44f0f6f02 100644 --- a/console/stats_profile_ids_test.go +++ b/console/stats_profile_ids_test.go @@ -35,15 +35,15 @@ func TestCmdStatsProfileIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/stats_profile_rem_test.go b/console/stats_profile_rem_test.go index 4f5423375..59e569039 100644 --- a/console/stats_profile_rem_test.go +++ b/console/stats_profile_rem_test.go @@ -35,15 +35,15 @@ func TestCmdStatsProfileRem(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/stats_profile_set_test.go b/console/stats_profile_set_test.go index e63867f4b..213d8686f 100644 --- a/console/stats_profile_set_test.go +++ b/console/stats_profile_set_test.go @@ -35,15 +35,15 @@ func TestCmdStatsProfileSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/stats_profile_test.go b/console/stats_profile_test.go index d5c0d38f4..fded96208 100644 --- a/console/stats_profile_test.go +++ b/console/stats_profile_test.go @@ -35,15 +35,15 @@ func TestCmdStatsProfile(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/status_test.go b/console/status_test.go index d9fa36b15..5e13a9478 100644 --- a/console/status_test.go +++ b/console/status_test.go @@ -35,15 +35,15 @@ func TestCmdStatus(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/stordb_versions_test.go b/console/stordb_versions_test.go index f92fa6b82..279e37e93 100644 --- a/console/stordb_versions_test.go +++ b/console/stordb_versions_test.go @@ -35,7 +35,7 @@ func TestCmdStorDBVersions(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // for coverage purpose @@ -45,7 +45,7 @@ func TestCmdStorDBVersions(t *testing.T) { } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/threshold_test.go b/console/threshold_test.go index e3ab8cdb8..b3f7ca461 100644 --- a/console/threshold_test.go +++ b/console/threshold_test.go @@ -35,15 +35,15 @@ func TestCmdThreshold(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/thresholds_for_event_test.go b/console/thresholds_for_event_test.go index 561b262f0..ec0fa4089 100644 --- a/console/thresholds_for_event_test.go +++ b/console/thresholds_for_event_test.go @@ -35,15 +35,15 @@ func TestCmdThresholdsForEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/thresholds_process_event_test.go b/console/thresholds_process_event_test.go index 11d3568a7..884a35b72 100644 --- a/console/thresholds_process_event_test.go +++ b/console/thresholds_process_event_test.go @@ -35,15 +35,15 @@ func TestCmdThresholdsProcessEvent(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/thresholds_profile_ids_test.go b/console/thresholds_profile_ids_test.go index 54f3bbba6..b7baf2a31 100644 --- a/console/thresholds_profile_ids_test.go +++ b/console/thresholds_profile_ids_test.go @@ -35,15 +35,15 @@ func TestCmdThresholdsProfileIDs(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/thresholds_profile_remove_test.go b/console/thresholds_profile_remove_test.go index 03d6e0ceb..177fcace7 100644 --- a/console/thresholds_profile_remove_test.go +++ b/console/thresholds_profile_remove_test.go @@ -35,15 +35,15 @@ func TestCmdThresholdsProfileRemove(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/thresholds_profile_set_test.go b/console/thresholds_profile_set_test.go index b8bd9d6ff..ab67c25e9 100644 --- a/console/thresholds_profile_set_test.go +++ b/console/thresholds_profile_set_test.go @@ -35,15 +35,15 @@ func TestCmdThresholdsProfileSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/thresholds_profile_test.go b/console/thresholds_profile_test.go index f01b3b941..8daf46014 100644 --- a/console/thresholds_profile_test.go +++ b/console/thresholds_profile_test.go @@ -35,15 +35,15 @@ func TestCmdThresholdsProfile(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/trigger_remove_test.go b/console/trigger_remove_test.go index c95ab69bc..30e37cc9f 100644 --- a/console/trigger_remove_test.go +++ b/console/trigger_remove_test.go @@ -19,11 +19,12 @@ along with this program. If not, see package console import ( - v1 "github.com/cgrates/cgrates/apier/v1" - "github.com/cgrates/cgrates/utils" "reflect" "strings" "testing" + + v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/utils" ) func TestCmdTriggerRemove(t *testing.T) { @@ -34,15 +35,15 @@ func TestCmdTriggerRemove(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/trigger_set_test.go b/console/trigger_set_test.go index b6594004f..58281d9b7 100644 --- a/console/trigger_set_test.go +++ b/console/trigger_set_test.go @@ -35,15 +35,15 @@ func TestCmdTriggerSet(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/console/triggers_test.go b/console/triggers_test.go index ccdb590ad..69b9c36b5 100644 --- a/console/triggers_test.go +++ b/console/triggers_test.go @@ -35,15 +35,15 @@ func TestCmdTriggers(t *testing.T) { if !ok { t.Fatal("method not found") } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs + if m.Type.NumIn() != 4 { // expecting 4 inputs t.Fatalf("invalid number of input parameters ") } // verify the type of input parameter - if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { + if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok { t.Fatalf("cannot assign input parameter") } // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { + if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { t.Fatalf("cannot assign output parameter") } // for coverage purpose diff --git a/cores/caps.go b/cores/caps.go index be38fd602..690848d52 100644 --- a/cores/caps.go +++ b/cores/caps.go @@ -20,11 +20,9 @@ package cores import ( "net" - "net/rpc" - "net/rpc/jsonrpc" - "github.com/cenkalti/rpc2" - jsonrpc2 "github.com/cenkalti/rpc2/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/analyzers" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -39,8 +37,8 @@ type conn interface { RemoteAddr() net.Addr } -func newCapsGOBCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) (r rpc.ServerCodec) { - r = newCapsServerCodec(newGobServerCodec(conn), caps) +func newCapsGOBCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) (r birpc.ServerCodec) { + r = newCapsServerCodec(birpc.NewServerCodec(conn), caps) if anz != nil { from := conn.RemoteAddr() var fromstr string @@ -57,7 +55,7 @@ func newCapsGOBCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerServic return } -func newCapsJSONCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) (r rpc.ServerCodec) { +func newCapsJSONCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) (r birpc.ServerCodec) { r = newCapsServerCodec(jsonrpc.NewServerCodec(conn), caps) if anz != nil { from := conn.RemoteAddr() @@ -75,7 +73,7 @@ func newCapsJSONCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerServi return } -func newCapsServerCodec(sc rpc.ServerCodec, caps *engine.Caps) rpc.ServerCodec { +func newCapsServerCodec(sc birpc.ServerCodec, caps *engine.Caps) birpc.ServerCodec { if !caps.IsLimited() { return sc } @@ -86,11 +84,11 @@ func newCapsServerCodec(sc rpc.ServerCodec, caps *engine.Caps) rpc.ServerCodec { } type capsServerCodec struct { - sc rpc.ServerCodec + sc birpc.ServerCodec caps *engine.Caps } -func (c *capsServerCodec) ReadRequestHeader(r *rpc.Request) error { +func (c *capsServerCodec) ReadRequestHeader(r *birpc.Request) error { return c.sc.ReadRequestHeader(r) } @@ -100,7 +98,7 @@ func (c *capsServerCodec) ReadRequestBody(x any) error { } return c.sc.ReadRequestBody(x) } -func (c *capsServerCodec) WriteResponse(r *rpc.Response, x any) error { +func (c *capsServerCodec) WriteResponse(r *birpc.Response, x any) error { if r.Error == utils.ErrMaxConcurrentRPCExceededNoCaps.Error() { r.Error = utils.ErrMaxConcurrentRPCExceeded.Error() } else { @@ -110,8 +108,8 @@ func (c *capsServerCodec) WriteResponse(r *rpc.Response, x any) error { } func (c *capsServerCodec) Close() error { return c.sc.Close() } -func newCapsBiRPCGOBCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) (r rpc2.Codec) { - r = newCapsBiRPCCodec(rpc2.NewGobCodec(conn), caps) +func newCapsBiRPCGOBCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) (r birpc.BirpcCodec) { + r = newCapsBiRPCCodec(birpc.NewGobBirpcCodec(conn), caps) if anz != nil { from := conn.RemoteAddr() var fromstr string @@ -128,8 +126,8 @@ func newCapsBiRPCGOBCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerS return } -func newCapsBiRPCJSONCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) (r rpc2.Codec) { - r = newCapsBiRPCCodec(jsonrpc2.NewJSONCodec(conn), caps) +func newCapsBiRPCJSONCodec(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) (r birpc.BirpcCodec) { + r = newCapsBiRPCCodec(jsonrpc.NewJSONBirpcCodec(conn), caps) if anz != nil { from := conn.RemoteAddr() var fromstr string @@ -146,7 +144,7 @@ func newCapsBiRPCJSONCodec(conn conn, caps *engine.Caps, anz *analyzers.Analyzer return } -func newCapsBiRPCCodec(sc rpc2.Codec, caps *engine.Caps) rpc2.Codec { +func newCapsBiRPCCodec(sc birpc.BirpcCodec, caps *engine.Caps) birpc.BirpcCodec { if !caps.IsLimited() { return sc } @@ -157,19 +155,19 @@ func newCapsBiRPCCodec(sc rpc2.Codec, caps *engine.Caps) rpc2.Codec { } type capsBiRPCCodec struct { - sc rpc2.Codec + sc birpc.BirpcCodec caps *engine.Caps } // ReadHeader must read a message and populate either the request // or the response by inspecting the incoming message. -func (c *capsBiRPCCodec) ReadHeader(req *rpc2.Request, resp *rpc2.Response) (err error) { +func (c *capsBiRPCCodec) ReadHeader(req *birpc.Request, resp *birpc.Response) (err error) { if err = c.sc.ReadHeader(req, resp); err != nil || - req.Method == utils.EmptyString { // caps will not process replies + req.ServiceMethod == utils.EmptyString { // caps will not process replies return } if err = c.caps.Allocate(); err != nil { - req.Method = utils.SessionSv1CapsError + req.ServiceMethod = utils.SessionSv1CapsError err = nil } return @@ -186,12 +184,12 @@ func (c *capsBiRPCCodec) ReadResponseBody(x any) error { } // WriteRequest must be safe for concurrent use by multiple goroutines. -func (c *capsBiRPCCodec) WriteRequest(req *rpc2.Request, x any) error { +func (c *capsBiRPCCodec) WriteRequest(req *birpc.Request, x any) error { return c.sc.WriteRequest(req, x) } // WriteResponse must be safe for concurrent use by multiple goroutines. -func (c *capsBiRPCCodec) WriteResponse(r *rpc2.Response, x any) error { +func (c *capsBiRPCCodec) WriteResponse(r *birpc.Response, x any) error { if r.Error == utils.ErrMaxConcurrentRPCExceededNoCaps.Error() { r.Error = utils.ErrMaxConcurrentRPCExceeded.Error() } else { diff --git a/cores/caps_test.go b/cores/caps_test.go index 377a20300..0988b16e5 100644 --- a/cores/caps_test.go +++ b/cores/caps_test.go @@ -19,14 +19,12 @@ package cores import ( "net" - "net/rpc" - "net/rpc/jsonrpc" "reflect" "syscall" "testing" - "github.com/cenkalti/rpc2" - jsonrpc2 "github.com/cenkalti/rpc2/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/analyzers" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -35,7 +33,7 @@ import ( type mockServerCodec struct{} -func (c *mockServerCodec) ReadRequestHeader(r *rpc.Request) (err error) { +func (c *mockServerCodec) ReadRequestHeader(r *birpc.Request) (err error) { r.Seq = 0 r.ServiceMethod = utils.CoreSv1Ping return @@ -44,7 +42,7 @@ func (c *mockServerCodec) ReadRequestHeader(r *rpc.Request) (err error) { func (c *mockServerCodec) ReadRequestBody(x any) (err error) { return utils.ErrNotImplemented } -func (c *mockServerCodec) WriteResponse(r *rpc.Response, x any) error { +func (c *mockServerCodec) WriteResponse(r *birpc.Response, x any) error { return nil } func (c *mockServerCodec) Close() error { return nil } @@ -65,8 +63,8 @@ func TestNewCapsServerCodec(t *testing.T) { t.Errorf("Expected: %v ,received:%v", exp, codec) } var err error - r := new(rpc.Request) - expR := &rpc.Request{ + r := new(birpc.Request) + expR := &birpc.Request{ Seq: 0, ServiceMethod: utils.CoreSv1Ping, } @@ -84,18 +82,16 @@ func TestNewCapsServerCodec(t *testing.T) { t.Errorf("Expected error: %v ,received: %v ", utils.ErrMaxConcurrentRPCExceededNoCaps, err) } - if err = codec.WriteResponse(&rpc.Response{ - Error: "error", - Seq: 0, - ServiceMethod: utils.CoreSv1Ping, + if err = codec.WriteResponse(&birpc.Response{ + Error: "error", + Seq: 0, }, "reply"); err != nil { t.Fatal(err) } - if err = codec.WriteResponse(&rpc.Response{ - Error: utils.ErrMaxConcurrentRPCExceededNoCaps.Error(), - Seq: 0, - ServiceMethod: utils.CoreSv1Ping, + if err = codec.WriteResponse(&birpc.Response{ + Error: utils.ErrMaxConcurrentRPCExceededNoCaps.Error(), + Seq: 0, }, "reply"); err != nil { t.Fatal(err) } @@ -112,20 +108,6 @@ func (*mockConn) Close() error { return nil } func (*mockConn) LocalAddr() net.Addr { return utils.LocalAddr() } func (*mockConn) RemoteAddr() net.Addr { return utils.LocalAddr() } -func TestNewCapsGOBCodec(t *testing.T) { - conn := new(mockConn) - cr := engine.NewCaps(0, utils.MetaBusy) - anz := &analyzers.AnalyzerService{} - exp := newGobServerCodec(conn) - if r := newCapsGOBCodec(conn, cr, nil); !reflect.DeepEqual(r, exp) { - t.Errorf("Expected: %v ,received:%v", exp, r) - } - exp = analyzers.NewAnalyzerServerCodec(newGobServerCodec(conn), anz, utils.MetaGOB, utils.Local, utils.Local) - if r := newCapsGOBCodec(conn, cr, anz); !reflect.DeepEqual(r, exp) { - t.Errorf("Expected: %v ,received:%v", exp, r) - } -} - func TestNewCapsJSONCodec(t *testing.T) { conn := new(mockConn) cr := engine.NewCaps(0, utils.MetaBusy) @@ -142,16 +124,16 @@ func TestNewCapsJSONCodec(t *testing.T) { type mockBiRPCCodec struct{} -func (mockBiRPCCodec) ReadHeader(r *rpc2.Request, _ *rpc2.Response) error { +func (mockBiRPCCodec) ReadHeader(r *birpc.Request, _ *birpc.Response) error { r.Seq = 0 - r.Method = utils.CoreSv1Ping + r.ServiceMethod = utils.CoreSv1Ping return nil } -func (mockBiRPCCodec) ReadRequestBody(any) error { return utils.ErrNotImplemented } -func (mockBiRPCCodec) ReadResponseBody(any) error { return nil } -func (mockBiRPCCodec) WriteRequest(*rpc2.Request, any) error { return nil } -func (mockBiRPCCodec) WriteResponse(*rpc2.Response, any) error { return nil } -func (mockBiRPCCodec) Close() error { return nil } +func (mockBiRPCCodec) ReadRequestBody(any) error { return utils.ErrNotImplemented } +func (mockBiRPCCodec) ReadResponseBody(any) error { return nil } +func (mockBiRPCCodec) WriteRequest(*birpc.Request, any) error { return nil } +func (mockBiRPCCodec) WriteResponse(*birpc.Response, any) error { return nil } +func (mockBiRPCCodec) Close() error { return nil } func TestNewCapsBiRPCCodec(t *testing.T) { mk := new(mockBiRPCCodec) @@ -169,10 +151,10 @@ func TestNewCapsBiRPCCodec(t *testing.T) { t.Errorf("Expected: %v ,received:%v", exp, codec) } var err error - r := new(rpc2.Request) - expR := &rpc2.Request{ - Seq: 0, - Method: utils.CoreSv1Ping, + r := new(birpc.Request) + expR := &birpc.Request{ + Seq: 0, + ServiceMethod: utils.CoreSv1Ping, } if err = codec.ReadHeader(r, nil); err != nil { t.Fatal(err) @@ -180,7 +162,7 @@ func TestNewCapsBiRPCCodec(t *testing.T) { t.Errorf("Expected: %v ,received:%v", expR, r) } - expR.Method = utils.SessionSv1CapsError + expR.ServiceMethod = utils.SessionSv1CapsError if err = codec.ReadHeader(r, nil); err != nil { t.Fatal(err) @@ -192,7 +174,7 @@ func TestNewCapsBiRPCCodec(t *testing.T) { t.Fatal(err) } - if err = codec.WriteResponse(&rpc2.Response{ + if err = codec.WriteResponse(&birpc.Response{ Error: "error", Seq: 0, }, "reply"); err != nil { @@ -203,14 +185,14 @@ func TestNewCapsBiRPCCodec(t *testing.T) { t.Fatal(err) } - if err = codec.WriteRequest(&rpc2.Request{ - Seq: 0, - Method: utils.CoreSv1Ping, + if err = codec.WriteRequest(&birpc.Request{ + Seq: 0, + ServiceMethod: utils.CoreSv1Ping, }, "reply"); err != nil { t.Fatal(err) } - if err = codec.WriteResponse(&rpc2.Response{ + if err = codec.WriteResponse(&birpc.Response{ Error: utils.ErrMaxConcurrentRPCExceededNoCaps.Error(), Seq: 0, }, "reply"); err != nil { @@ -225,11 +207,11 @@ func TestNewCapsGOBBiRPCCodec(t *testing.T) { conn := new(mockConn) cr := engine.NewCaps(0, utils.MetaBusy) anz := &analyzers.AnalyzerService{} - exp := rpc2.NewGobCodec(conn) + exp := birpc.NewGobBirpcCodec(conn) if r := newCapsBiRPCGOBCodec(conn, cr, nil); !reflect.DeepEqual(r, exp) { t.Errorf("Expected: %v ,received:%v", exp, r) } - exp = analyzers.NewAnalyzerBiRPCCodec(rpc2.NewGobCodec(conn), anz, rpcclient.BiRPCGOB, utils.Local, utils.Local) + exp = analyzers.NewAnalyzerBiRPCCodec(birpc.NewGobBirpcCodec(conn), anz, rpcclient.BiRPCGOB, utils.Local, utils.Local) if r := newCapsBiRPCGOBCodec(conn, cr, anz); !reflect.DeepEqual(r, exp) { t.Errorf("Expected: %v ,received:%v", exp, r) } @@ -239,11 +221,11 @@ func TestNewCapsJSONBiRPCCodec(t *testing.T) { conn := new(mockConn) cr := engine.NewCaps(0, utils.MetaBusy) anz := &analyzers.AnalyzerService{} - exp := jsonrpc2.NewJSONCodec(conn) + exp := jsonrpc.NewJSONBirpcCodec(conn) if r := newCapsBiRPCJSONCodec(conn, cr, nil); !reflect.DeepEqual(r, exp) { t.Errorf("Expected: %v ,received:%v", exp, r) } - exp = analyzers.NewAnalyzerBiRPCCodec(jsonrpc2.NewJSONCodec(conn), anz, rpcclient.BiRPCJSON, utils.Local, utils.Local) + exp = analyzers.NewAnalyzerBiRPCCodec(jsonrpc.NewJSONBirpcCodec(conn), anz, rpcclient.BiRPCJSON, utils.Local, utils.Local) if r := newCapsBiRPCJSONCodec(conn, cr, anz); !reflect.DeepEqual(r, exp) { t.Errorf("Expected: %v ,received:%v", exp, r) } diff --git a/cores/core.go b/cores/core.go index f6f73270d..6913fda3d 100644 --- a/cores/core.go +++ b/cores/core.go @@ -29,6 +29,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -127,8 +128,8 @@ func MemProfiling(memProfDir string, interval time.Duration, nrFiles int, shdWg } } -// Status returns the status of the engine -func (cS *CoreService) Status(arg *utils.TenantWithAPIOpts, reply *map[string]any) (err error) { +// V1Status returns the status of the engine +func (cS *CoreService) V1Status(_ *context.Context, _ *utils.TenantWithAPIOpts, reply *map[string]any) (err error) { memstats := new(runtime.MemStats) runtime.ReadMemStats(memstats) response := make(map[string]any) @@ -203,7 +204,52 @@ func (cS *CoreService) StopMemoryProfiling() (err error) { return } -// Panic is used print the Message sent as a panic -func (cS *CoreService) Panic(args *utils.PanicMessageArgs, _ *string) error { +// Sleep is used to test the concurrent requests mechanism +func (cS *CoreService) V1Sleep(_ *context.Context, arg *utils.DurationArgs, reply *string) error { + time.Sleep(arg.Duration) + *reply = utils.OK + return nil +} + +// StartCPUProfiling is used to start CPUProfiling in the given path +func (cS *CoreService) V1StartCPUProfiling(_ *context.Context, args *utils.DirectoryArgs, reply *string) error { + if err := cS.StartCPUProfiling(path.Join(args.DirPath, utils.CpuPathCgr)); err != nil { + return err + } + *reply = utils.OK + return nil +} + +// StopCPUProfiling is used to stop CPUProfiling. The file should be written on the path +// where the CPUProfiling already started +func (cS *CoreService) V1StopCPUProfiling(_ *context.Context, _ *utils.TenantWithAPIOpts, reply *string) error { + if err := cS.StopCPUProfiling(); err != nil { + return err + } + *reply = utils.OK + return nil +} + +// StartMemoryProfiling is used to start MemoryProfiling in the given path +func (cS *CoreService) V1StartMemoryProfiling(_ *context.Context, args *utils.MemoryPrf, reply *string) error { + if err := cS.StartMemoryProfiling(args); err != nil { + return err + } + *reply = utils.OK + return nil +} + +// V1StopMemoryProfiling is used to stop MemoryProfiling. The file should be written on the path +// where the MemoryProfiling already started +func (cS *CoreService) V1StopMemoryProfiling(_ *context.Context, _ *utils.TenantWithAPIOpts, reply *string) error { + if err := cS.StopMemoryProfiling(); err != nil { + return err + } + *reply = utils.OK + return nil +} + +// V1Panic is used print the Message sent as a panic +func (cS *CoreService) V1Panic(_ *context.Context, args *utils.PanicMessageArgs, _ *string) error { panic(args.Message) } diff --git a/cores/core_test.go b/cores/core_test.go index 06f85a072..99bcbbb4b 100644 --- a/cores/core_test.go +++ b/cores/core_test.go @@ -25,6 +25,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -83,7 +84,7 @@ func TestCoreServiceStatus(t *testing.T) { utils.MemoryUsage: "CHANGED_MEMORY_USAGE", utils.NodeID: cfgDflt.GeneralCfg().NodeID, } - if err := cores.Status(args, &reply); err != nil { + if err := cores.V1Status(context.Background(), args, &reply); err != nil { t.Error(err) } else { reply[utils.RunningSince] = "TIME_CHANGED" @@ -106,7 +107,7 @@ func TestCoreServiceStatus(t *testing.T) { } utils.GitLastLog = `Date: wrong format ` - if err := cores.Status(args, &reply); err != nil { + if err := cores.V1Status(context.Background(), args, &reply); err != nil { t.Error(err) } diff --git a/cores/gob_codec.go b/cores/gob_codec.go deleted file mode 100644 index 2a2e32b26..000000000 --- a/cores/gob_codec.go +++ /dev/null @@ -1,87 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package cores - -import ( - "bufio" - "encoding/gob" - "io" - "log" - "net/rpc" -) - -// All of the logic follows standard library implementation in this file -// Only here to use as object - -func newGobServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec { - buf := bufio.NewWriter(conn) - return &gobServerCodec{ - rwc: conn, - dec: gob.NewDecoder(conn), - enc: gob.NewEncoder(buf), - encBuf: buf, - } -} - -type gobServerCodec struct { - rwc io.ReadWriteCloser - dec *gob.Decoder - enc *gob.Encoder - encBuf *bufio.Writer - closed bool -} - -func (c *gobServerCodec) ReadRequestHeader(r *rpc.Request) error { - return c.dec.Decode(r) -} - -func (c *gobServerCodec) ReadRequestBody(body any) error { - return c.dec.Decode(body) -} - -func (c *gobServerCodec) WriteResponse(r *rpc.Response, body any) (err error) { - if err = c.enc.Encode(r); err != nil { - if c.encBuf.Flush() == nil { - // Gob couldn't encode the header. Should not happen, so if it does, - // shut down the connection to signal that the connection is broken. - log.Println("rpc: gob error encoding response:", err) - c.Close() - } - return - } - if err = c.enc.Encode(body); err != nil { - if c.encBuf.Flush() == nil { - // Was a gob problem encoding the body but the header has been written. - // Shut down the connection to signal that the connection is broken. - log.Println("rpc: gob error encoding body:", err) - c.Close() - } - return - } - return c.encBuf.Flush() -} - -func (c *gobServerCodec) Close() error { - if c.closed { - // Only call c.rwc.Close once; otherwise the semantics are undefined. - return nil - } - c.closed = true - return c.rwc.Close() -} diff --git a/cores/gob_codec_test.go b/cores/gob_codec_test.go deleted file mode 100644 index 7c2458344..000000000 --- a/cores/gob_codec_test.go +++ /dev/null @@ -1,146 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package cores - -import ( - "bufio" - "encoding/gob" - "io" - "log" - "net/rpc" - "testing" - - "github.com/cgrates/cgrates/utils" -) - -type mockRWC struct{} - -func (*mockRWC) Read(p []byte) (n int, err error) { - return 0, nil -} - -func (mk *mockRWC) Write(p []byte) (n int, err error) { - return 0, nil -} - -func (mk *mockRWC) Close() error { - return nil -} - -// Mocking For getting a nil error when the interface argument is nil in encoding -type mockReadWriteCloserErrorNilInterface struct { - mockRWC -} - -func (mk *mockReadWriteCloserErrorNilInterface) Write(p []byte) (n int, err error) { - return len(p), nil -} - -func TestWriteResponseInterface(t *testing.T) { - log.SetOutput(io.Discard) - resp := &rpc.Response{ - ServiceMethod: utils.APIerSv1Ping, - Seq: 123, - } - conn := new(mockReadWriteCloserErrorNilInterface) - exp := newGobServerCodec(conn) - expected := "gob: cannot encode nil value" - if err := exp.WriteResponse(resp, nil); err == nil || err.Error() != expected { - t.Errorf("Expected %+v, received %+v", expected, err) - } -} - -type mockReadWriteCloserErrorNilResponse struct { - mockRWC -} - -func (mk *mockReadWriteCloserErrorNilResponse) Write(p []byte) (n int, err error) { - return 4, utils.ErrNotImplemented -} - -func TestWriteResponseResponse(t *testing.T) { - log.SetOutput(io.Discard) - resp := &rpc.Response{ - ServiceMethod: utils.APIerSv1Ping, - Seq: 123, - Error: "err", - } - conn := new(mockReadWriteCloserErrorNilResponse) - buf := bufio.NewWriter(conn) - gsrv := gobServerCodec{ - enc: gob.NewEncoder(buf), - encBuf: buf, - rwc: conn, - dec: gob.NewDecoder(conn), - } - if err := gsrv.WriteResponse(resp, "string"); err == nil || err != utils.ErrNotImplemented { - t.Errorf("Expected %+v, received %+v", utils.ErrNotImplemented, err) - } - - buf = bufio.NewWriter(conn) - gsrv.encBuf = buf - - if err := gsrv.WriteResponse(resp, "string"); err == nil || err != utils.ErrNotImplemented { - t.Errorf("Expected %+v, received %+v", utils.ErrNotImplemented, err) - } -} - -func TestReadRequestHeader(t *testing.T) { - conn := new(mockReadWriteCloserErrorNilResponse) - buf := bufio.NewWriter(conn) - gsrv := gobServerCodec{ - enc: gob.NewEncoder(buf), - encBuf: buf, - rwc: conn, - dec: gob.NewDecoder(conn), - } - expected := "gob: DecodeValue of unassignable value" - if err := gsrv.ReadRequestHeader(nil); err == nil || err.Error() != expected { - t.Errorf("Expected %+v, received %+v", expected, err) - } -} - -func TestReadRequestBody(t *testing.T) { - conn := new(mockReadWriteCloserErrorNilResponse) - buf := bufio.NewWriter(conn) - gsrv := gobServerCodec{ - enc: gob.NewEncoder(buf), - encBuf: buf, - rwc: conn, - dec: gob.NewDecoder(conn), - } - expected := "gob: attempt to decode into a non-pointer" - if err := gsrv.ReadRequestBody(2); err == nil || err.Error() != expected { - t.Errorf("Expected %+v, received %+v", expected, err) - } -} - -func TestClose(t *testing.T) { - conn := new(mockRWC) - exp := newGobServerCodec(conn) - //now after calling, it will be closed - if err := exp.Close(); err != nil { - t.Error(err) - } - - //calling again the function won t close - if err := exp.Close(); err != nil { - t.Error(err) - } -} diff --git a/cores/server.go b/cores/server.go index 0a98a683e..e4154a9fa 100644 --- a/cores/server.go +++ b/cores/server.go @@ -29,13 +29,12 @@ import ( "net" "net/http" "net/http/pprof" - "net/rpc" "os" "strings" "sync" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/analyzers" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -46,8 +45,10 @@ func NewServer(caps *engine.Caps) (s *Server) { return &Server{ httpMux: http.NewServeMux(), httpsMux: http.NewServeMux(), - stopbiRPCServer: make(chan struct{}, 1), + stopBiRPCServer: make(chan struct{}, 1), caps: caps, + rpcSrv: birpc.NewServer(), + birpcSrv: birpc.NewBirpcServer(), } } @@ -55,8 +56,9 @@ type Server struct { sync.RWMutex rpcEnabled bool httpEnabled bool - birpcSrv *rpc2.Server - stopbiRPCServer chan struct{} // used in order to fully stop the biRPC + rpcSrv *birpc.Server + birpcSrv *birpc.BirpcServer + stopBiRPCServer chan struct{} // used in order to fully stop the biRPC httpsMux *http.ServeMux httpMux *http.ServeMux caps *engine.Caps @@ -69,7 +71,7 @@ func (s *Server) SetAnalyzer(anz *analyzers.AnalyzerService) { func (s *Server) RpcRegister(rcvr any) { utils.RegisterRpcParams(utils.EmptyString, rcvr) - rpc.Register(rcvr) + s.rpcSrv.Register(rcvr) s.Lock() s.rpcEnabled = true s.Unlock() @@ -77,12 +79,16 @@ func (s *Server) RpcRegister(rcvr any) { func (s *Server) RpcRegisterName(name string, rcvr any) { utils.RegisterRpcParams(name, rcvr) - rpc.RegisterName(name, rcvr) + s.rpcSrv.RegisterName(name, rcvr) s.Lock() s.rpcEnabled = true s.Unlock() } +func (s *Server) RpcUnregisterName(name string) { + s.rpcSrv.UnregisterName(name) +} + func (s *Server) RegisterHttpFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) { if s.httpMux != nil { s.httpMux.HandleFunc(pattern, handler) @@ -108,19 +114,15 @@ func (s *Server) RegisterHttpHandler(pattern string, handler http.Handler) { } // Registers a new BiJsonRpc name -func (s *Server) BiRPCRegisterName(method string, handlerFunc any) { - s.RLock() - isNil := s.birpcSrv == nil - s.RUnlock() - if isNil { - s.Lock() - s.birpcSrv = rpc2.NewServer() - s.Unlock() - } - s.birpcSrv.Handle(method, handlerFunc) +func (s *Server) BiRPCRegisterName(name string, rcvr any) { + s.birpcSrv.RegisterName(name, rcvr) } -func (s *Server) serveCodec(addr, codecName string, newCodec func(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) rpc.ServerCodec, +func (s *Server) BiRPCUnregisterName(name string) { + s.birpcSrv.UnregisterName(name) +} + +func (s *Server) serveCodec(addr, codecName string, newCodec func(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) birpc.ServerCodec, shdChan *utils.SyncedChan) { s.RLock() enabled := s.rpcEnabled @@ -139,9 +141,9 @@ func (s *Server) serveCodec(addr, codecName string, newCodec func(conn conn, cap s.accept(l, codecName, newCodec, shdChan) } -func (s *Server) accept(l net.Listener, codecName string, newCodec func(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) rpc.ServerCodec, +func (s *Server) accept(l net.Listener, codecName string, newCodec func(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) birpc.ServerCodec, shdChan *utils.SyncedChan) { - errCnt := 0 + var errCnt int var lastErrorTime time.Time for { conn, err := l.Accept() @@ -159,7 +161,7 @@ func (s *Server) accept(l net.Listener, codecName string, newCodec func(conn con } continue } - go rpc.ServeCodec(newCodec(conn, s.caps, s.anz)) + go s.rpcSrv.ServeCodec(newCodec(conn, s.caps, s.anz)) } } @@ -176,7 +178,7 @@ func (s *Server) handleRequest(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") rmtIP, _ := utils.GetRemoteIP(r) rmtAddr, _ := net.ResolveIPAddr(utils.EmptyString, rmtIP) - res := newRPCRequest(r.Body, rmtAddr, s.caps, s.anz).Call() + res := newRPCRequest(s.rpcSrv, r.Body, rmtAddr, s.caps, s.anz).Call() io.Copy(w, res) } @@ -248,62 +250,59 @@ func (s *Server) ServeHTTP(addr string, jsonRPCURL string, wsRPCURL string, } // ServeBiRPC create a goroutine to listen and serve as BiRPC server -func (s *Server) ServeBiRPC(addrJSON, addrGOB string, onConn func(*rpc2.Client), onDis func(*rpc2.Client)) (err error) { - s.RLock() - isNil := s.birpcSrv == nil - s.RUnlock() - if isNil { - return fmt.Errorf("BiRPCServer should not be nil") - } - +func (s *Server) ServeBiRPC(addrJSON, addrGOB string, onConn, onDis func(birpc.ClientConnector)) (err error) { s.birpcSrv.OnConnect(onConn) s.birpcSrv.OnDisconnect(onDis) if addrJSON != utils.EmptyString { var ljson net.Listener - if ljson, err = s.listenBiRPC(s.birpcSrv, addrJSON, utils.JSONCaps, newCapsBiRPCJSONCodec); err != nil { + if ljson, err = listenBiRPC(s.birpcSrv, addrJSON, utils.JSONCaps, func(conn conn) birpc.BirpcCodec { + return newCapsBiRPCJSONCodec(conn, s.caps, s.anz) + }, s.stopBiRPCServer); err != nil { return } defer ljson.Close() } if addrGOB != utils.EmptyString { var lgob net.Listener - if lgob, err = s.listenBiRPC(s.birpcSrv, addrGOB, utils.GOBCaps, newCapsBiRPCGOBCodec); err != nil { + if lgob, err = listenBiRPC(s.birpcSrv, addrGOB, utils.GOBCaps, func(conn conn) birpc.BirpcCodec { + return newCapsBiRPCGOBCodec(conn, s.caps, s.anz) + }, s.stopBiRPCServer); err != nil { return } defer lgob.Close() } - <-s.stopbiRPCServer // wait until server is stopped to close the listener + <-s.stopBiRPCServer // wait until server is stopped to close the listener return } -func (s *Server) listenBiRPC(srv *rpc2.Server, addr, codecName string, newCodec func(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) rpc2.Codec) (lBiRPC net.Listener, err error) { +func listenBiRPC(srv *birpc.BirpcServer, addr, codecName string, newCodec func(conn conn) birpc.BirpcCodec, stopBiRPCServer chan struct{}) (lBiRPC net.Listener, err error) { if lBiRPC, err = net.Listen(utils.TCP, addr); err != nil { log.Printf("ServeBi%s listen error: %s \n", codecName, err) return } utils.Logger.Info(fmt.Sprintf("Starting CGRateS Bi%s server at <%s>", codecName, addr)) - go s.acceptBiRPC(srv, lBiRPC, codecName, newCodec) + go acceptBiRPC(srv, lBiRPC, codecName, newCodec, stopBiRPCServer) return } -func (s *Server) acceptBiRPC(srv *rpc2.Server, l net.Listener, codecName string, newCodec func(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) rpc2.Codec) { +func acceptBiRPC(srv *birpc.BirpcServer, l net.Listener, codecName string, newCodec func(conn conn) birpc.BirpcCodec, stopBiRPCServer chan struct{}) { for { conn, err := l.Accept() if err != nil { if strings.Contains(err.Error(), "use of closed network connection") { // if closed by us do not log return } - s.stopbiRPCServer <- struct{}{} + stopBiRPCServer <- struct{}{} utils.Logger.Crit(fmt.Sprintf("Stopped Bi%s server beacause %s", codecName, err)) return // stop if we get Accept error } - go srv.ServeCodec(newCodec(conn, s.caps, s.anz)) + go srv.ServeCodec(newCodec(conn)) } } // StopBiRPC stops the go routine create with ServeBiJSON func (s *Server) StopBiRPC() { - s.stopbiRPCServer <- struct{}{} + s.stopBiRPCServer <- struct{}{} s.Lock() s.birpcSrv = nil s.Unlock() @@ -317,16 +316,18 @@ type rpcRequest struct { remoteAddr net.Addr caps *engine.Caps anzWarpper *analyzers.AnalyzerService + srv *birpc.Server } // newRPCRequest returns a new rpcRequest. -func newRPCRequest(r io.ReadCloser, remoteAddr net.Addr, caps *engine.Caps, anz *analyzers.AnalyzerService) *rpcRequest { +func newRPCRequest(srv *birpc.Server, r io.ReadCloser, remoteAddr net.Addr, caps *engine.Caps, anz *analyzers.AnalyzerService) *rpcRequest { return &rpcRequest{ r: r, rw: new(bytes.Buffer), remoteAddr: remoteAddr, caps: caps, anzWarpper: anz, + srv: srv, } } @@ -351,7 +352,7 @@ func (r *rpcRequest) Close() error { // Call invokes the RPC request, waits for it to complete, and returns the results. func (r *rpcRequest) Call() io.Reader { - rpc.ServeCodec(newCapsJSONCodec(r, r.caps, r.anzWarpper)) + r.srv.ServeCodec(newCapsJSONCodec(r, r.caps, r.anzWarpper)) return r.rw } @@ -395,7 +396,7 @@ func loadTLSConfig(serverCrt, serverKey, caCert string, serverPolicy int, } func (s *Server) serveCodecTLS(addr, codecName, serverCrt, serverKey, caCert string, - serverPolicy int, serverName string, newCodec func(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) rpc.ServerCodec, + serverPolicy int, serverName string, newCodec func(conn conn, caps *engine.Caps, anz *analyzers.AnalyzerService) birpc.ServerCodec, shdChan *utils.SyncedChan) { s.RLock() enabled := s.rpcEnabled @@ -429,7 +430,7 @@ func (s *Server) ServeJSONTLS(addr, serverCrt, serverKey, caCert string, } func (s *Server) handleWebSocket(ws *websocket.Conn) { - rpc.ServeCodec(newCapsJSONCodec(ws, s.caps, s.anz)) + s.rpcSrv.ServeCodec(newCapsJSONCodec(ws, s.caps, s.anz)) } func (s *Server) ServeHTTPTLS(addr, serverCrt, serverKey, caCert string, serverPolicy int, diff --git a/cores/server_it_test.go b/cores/server_it_test.go index 63c92c650..14ed45c2f 100644 --- a/cores/server_it_test.go +++ b/cores/server_it_test.go @@ -30,7 +30,6 @@ import ( "net" "net/http" "net/http/httptest" - "net/rpc/jsonrpc" "os" "path" "reflect" @@ -39,7 +38,9 @@ import ( "testing" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -65,7 +66,6 @@ var ( testServeBiJSONEmptyBiRPCServer, testServeBiJSONInvalidPort, testServeBiGoB, - testServeBiGoBEmptyBiRPCServer, testServeBiGoBInvalidPort, testServeGOBTLS, testServeJSONTls, @@ -76,7 +76,6 @@ var ( testServeHTTPTLSError, testServeHTTPTLSHttpNotEnabled, testHandleRequest, - testBiRPCRegisterName, testAcceptBiRPC, testAcceptBiRPCError, testRpcRegisterActions, @@ -94,11 +93,7 @@ func TestServerIT(t *testing.T) { type mockRegister string -func (x *mockRegister) ForTest(method *rpc2.Client, args *any, reply *any) error { - return nil -} - -func (robj *mockRegister) Ping(in string, out *string) error { +func (robj *mockRegister) Ping(ctx *context.Context, in string, out *string) error { *out = utils.Pong return nil } @@ -324,7 +319,7 @@ func testServeBiJSON(t *testing.T) { caps := engine.NewCaps(100, utils.MetaBusy) server = NewServer(caps) server.RpcRegister(new(mockRegister)) - server.birpcSrv = rpc2.NewServer() + server.birpcSrv = birpc.NewBirpcServer() data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) @@ -365,7 +360,7 @@ func testServeBiJSONInvalidPort(t *testing.T) { caps := engine.NewCaps(100, utils.MetaBusy) server = NewServer(caps) server.RpcRegister(new(mockRegister)) - server.birpcSrv = rpc2.NewServer() + server.birpcSrv = birpc.NewBirpcServer() data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) @@ -386,7 +381,7 @@ func testServeBiGoB(t *testing.T) { caps := engine.NewCaps(100, utils.MetaBusy) server = NewServer(caps) server.RpcRegister(new(mockRegister)) - server.birpcSrv = rpc2.NewServer() + server.birpcSrv = birpc.NewBirpcServer() data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) @@ -401,33 +396,12 @@ func testServeBiGoB(t *testing.T) { runtime.Gosched() } -func testServeBiGoBEmptyBiRPCServer(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - caps := engine.NewCaps(100, utils.MetaBusy) - server = NewServer(caps) - server.RpcRegister(new(mockRegister)) - - data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - - ss := sessions.NewSessionS(cfg, dm, nil) - - expectedErr := "BiRPCServer should not be nil" - go func() { - if err := server.ServeBiRPC("", ":93430", ss.OnBiJSONConnect, ss.OnBiJSONDisconnect); err == nil || err.Error() != "BiRPCServer should not be nil" { - t.Errorf("Expected %+v, received %+v", expectedErr, err) - } - }() - - runtime.Gosched() -} - func testServeBiGoBInvalidPort(t *testing.T) { cfg := config.NewDefaultCGRConfig() caps := engine.NewCaps(100, utils.MetaBusy) server = NewServer(caps) server.RpcRegister(new(mockRegister)) - server.birpcSrv = rpc2.NewServer() + server.birpcSrv = birpc.NewBirpcServer() data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) @@ -731,34 +705,23 @@ func testServeHTTPTLSHttpNotEnabled(t *testing.T) { shdChan.CloseOnce() } -func testBiRPCRegisterName(t *testing.T) { - caps := engine.NewCaps(0, utils.MetaBusy) - server := NewServer(caps) - - handler := func(method *rpc2.Client, args *any, reply *any) error { - return nil - } - go server.BiRPCRegisterName(utils.APIerSv1Ping, handler) - runtime.Gosched() - - server.StopBiRPC() -} - func testAcceptBiRPC(t *testing.T) { caps := engine.NewCaps(0, utils.MetaBusy) server := NewServer(caps) server.RpcRegister(new(mockRegister)) - server.birpcSrv = rpc2.NewServer() + server.birpcSrv = birpc.NewBirpcServer() p1, p2 := net.Pipe() l := &mockListener{ p1: p1, } - go server.acceptBiRPC(server.birpcSrv, l, utils.JSONCaps, newCapsBiRPCJSONCodec) + go acceptBiRPC(server.birpcSrv, l, utils.JSONCaps, func(conn conn) birpc.BirpcCodec { + return newCapsBiRPCJSONCodec(conn, server.caps, server.anz) + }, server.stopBiRPCServer) rpc := jsonrpc.NewClient(p2) var reply string - expected := "rpc2: can't find method AttributeSv1.Ping" - if err := rpc.Call(utils.AttributeSv1Ping, utils.CGREvent{}, &reply); err == nil || err.Error() != expected { + expected := "birpc: can't find method AttributeSv1.Ping" + if err := rpc.Call(context.Background(), utils.AttributeSv1Ping, utils.CGREvent{}, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -778,11 +741,13 @@ func testAcceptBiRPCError(t *testing.T) { caps := engine.NewCaps(10, utils.MetaBusy) server := NewServer(caps) server.RpcRegister(new(mockRegister)) - server.birpcSrv = rpc2.NewServer() + server.birpcSrv = birpc.NewBirpcServer() //it will contain "use of closed network connection" l := new(mockListenError) - go server.acceptBiRPC(server.birpcSrv, l, utils.JSONCaps, newCapsBiRPCJSONCodec) + go acceptBiRPC(server.birpcSrv, l, utils.JSONCaps, func(conn conn) birpc.BirpcCodec { + return newCapsBiRPCJSONCodec(conn, server.caps, server.anz) + }, server.stopBiRPCServer) runtime.Gosched() } @@ -798,7 +763,7 @@ func testRpcRegisterActions(t *testing.T) { rmtIP, _ := utils.GetRemoteIP(r) rmtAddr, _ := net.ResolveIPAddr(utils.EmptyString, rmtIP) - rpcReq := newRPCRequest(r.Body, rmtAddr, server.caps, nil) + rpcReq := newRPCRequest(server.rpcSrv, r.Body, rmtAddr, server.caps, nil) rpcReq.remoteAddr = utils.NewNetAddr("network", "127.0.0.1:2012") if n, err := rpcReq.Write([]byte(`TEST`)); err != nil { @@ -840,7 +805,7 @@ func testWebSocket(t *testing.T) { rpc := jsonrpc.NewClient(conn1) var reply string - err = rpc.Call("mockRegister.Ping", "", &reply) + err = rpc.Call(context.Background(), "mockRegister.Ping", "", &reply) if err != nil { t.Fatal(err) } diff --git a/cores/server_test.go b/cores/server_test.go index 72afd1539..49be949c7 100644 --- a/cores/server_test.go +++ b/cores/server_test.go @@ -44,9 +44,11 @@ func TestNewServer(t *testing.T) { caps: caps, } rcv := NewServer(caps) - rcv.stopbiRPCServer = nil + rcv.stopBiRPCServer = nil + rcv.rpcSrv = nil + rcv.birpcSrv = nil if !reflect.DeepEqual(expected, rcv) { - t.Errorf("Expected %+v, received %+v", expected, rcv) + t.Errorf("\nExpected %+v,\nreceived %+v", expected, rcv) } cfgDflt.AnalyzerSCfg().DBPath = "/tmp/analyzers" diff --git a/data/ansible/drone/main.yaml b/data/ansible/drone/main.yaml index 27988d2e2..f167a6291 100644 --- a/data/ansible/drone/main.yaml +++ b/data/ansible/drone/main.yaml @@ -11,7 +11,7 @@ docker_runner_capacity: 20 drone_user_create: cgrates - drone_user_filter: + drone_user_filter: - cgrates - danbogos - TeoV @@ -26,34 +26,34 @@ - apt-transport-https - ca-certificates - openssl - - gnupg-agent + - gnupg-agent - software-properties-common - python3 - python3-pip - virtualenv - python3-setuptools - rootUser : root - - remote_user: '{{ user }}' + rootUser: root + + remote_user: "{{ user }}" tasks: -########################################################################################################################### -########################################################################################################################### -# install dependencies + ########################################################################################################################### + ########################################################################################################################### + # install dependencies - name: Install dependencies become: yes apt: name={{ dependencies }} state=present - - - name: Configure docker + + - name: Configure docker include: docker.yaml -########################################################################################################################### -########################################################################################################################### -# Install Go + ########################################################################################################################### + ########################################################################################################################### + # Install Go - name: Install Go import_role: name: ../roles/go -########################################################################################################################### -########################################################################################################################### + ########################################################################################################################### + ########################################################################################################################### - name: clean go cache become: yes shell: "go clean --cache" @@ -70,16 +70,16 @@ become: yes file: state: directory - mode: 'u=rwx,go=rx' + mode: "u=rwx,go=rx" owner: "{{ user }}" group: "{{ user }}" - dest: '/home/{{ user }}/go/src/github.com/Trial97/drone-email' + dest: "/home/{{ user }}/go/src/github.com/Trial97/drone-email" become_user: "{{ user }}" - name: git clone mailer git: repo: https://github.com/Trial97/drone-email.git - dest: '/home/{{ user }}/go/src/github.com/Trial97/drone-email' + dest: "/home/{{ user }}/go/src/github.com/Trial97/drone-email" update: yes force: yes version: "master" @@ -90,23 +90,22 @@ become: yes shell: docker build -t trial97/drone-email /home/{{ user }}/go/src/github.com/Trial97/drone-email args: - chdir: '/home/{{ user }}/go/src/github.com/Trial97/drone-email' - + chdir: "/home/{{ user }}/go/src/github.com/Trial97/drone-email" - name: create drone-cli directory become: yes file: state: directory - mode: 'u=rwx,go=rx' + mode: "u=rwx,go=rx" owner: "{{ user }}" group: "{{ user }}" - dest: '/home/{{ user }}/go/src/github.com/drone/drone-cli' + dest: "/home/{{ user }}/go/src/github.com/drone/drone-cli" become_user: "{{ user }}" - name: git clone mailer git: repo: https://github.com/drone/drone-cli.git - dest: '/home/{{ user }}/go/src/github.com/drone/drone-cli' + dest: "/home/{{ user }}/go/src/github.com/drone/drone-cli" update: yes force: yes version: "master" @@ -116,7 +115,7 @@ - name: build drone-cli shell: go build -o /home/{{ user }}/go/bin/drone-cli ./main.go args: - chdir: '/home/{{ user }}/go/src/github.com/drone/drone-cli/drone' + chdir: "/home/{{ user }}/go/src/github.com/drone/drone-cli/drone" environment: PATH: "{{ lookup('env','PATH') }}:/home/{{ user }}/go/bin:/usr/local/go/bin:{{ ansible_env.PATH }}" @@ -124,16 +123,16 @@ become: yes file: state: directory - mode: 'u=rwx,go=rx' + mode: "u=rwx,go=rx" owner: "{{ user }}" group: "{{ user }}" - dest: '{{ cgrates_dir }}' + dest: "{{ cgrates_dir }}" become_user: "{{ user }}" - name: git clone cgrates git: repo: https://github.com/cgrates/cgrates.git - dest: '{{ cgrates_dir }}' + dest: "{{ cgrates_dir }}" update: yes force: yes version: "master" @@ -141,8 +140,7 @@ become_user: "{{ user }}" - name: copy storage scripts - shell: - mkdir -p postgres; + shell: mkdir -p postgres; cp {{ cgrates_dir }}/data/storage/postgres/create_cdrs_tables.sql ./postgres/create_cdrs_tables.sql; cp {{ cgrates_dir }}/data/storage/postgres/create_tariffplan_tables.sql ./postgres/create_tariffplan_tables.sql; cp {{ cgrates_dir }}/data/storage/mysql/create_cdrs_tables.sql ./mysql/create_cdrs_tables.sql; @@ -151,28 +149,28 @@ cp {{ cgrates_dir }}/data/storage/mongo/create_user.js ./create_user.js; args: warn: false - chdir: '{{ cgrates_dir }}/data/docker/integration/scripts' + chdir: "{{ cgrates_dir }}/data/docker/integration/scripts" - name: build Docker image for integration become: yes shell: docker build -t cgrates-integration {{ cgrates_dir }}/data/docker/integration/ args: - chdir: '{{ cgrates_dir }}/data/docker/integration' + chdir: "{{ cgrates_dir }}/data/docker/integration" - name: create drone directory become: yes file: state: directory - mode: 'u=rwx,go=rx' + mode: "u=rwx,go=rx" owner: "{{ user }}" group: "{{ user }}" - dest: '{{ drone_dir }}' + dest: "{{ drone_dir }}" become_user: "{{ user }}" - name: git clone drone git: repo: https://github.com/drone/drone.git - dest: '{{ drone_dir }}' + dest: "{{ drone_dir }}" update: yes force: yes become: yes @@ -183,7 +181,7 @@ environment: PATH: "{{ lookup('env','PATH') }}:/home/{{ user }}/go/bin:/usr/local/go/bin:{{ ansible_env.PATH }}" args: - chdir: '{{ drone_dir }}' + chdir: "{{ drone_dir }}" - name: install validate plugin shell: "go get github.com/Trial97/droneAuth" @@ -195,12 +193,11 @@ src: users.json.j2 dest: /home/{{ user }}/users.json - - name: generate RPCSecret + - name: generate RPCSecret shell: "openssl rand -hex 16" register: drone_secret - - - name: generate token + - name: generate token shell: "openssl rand -hex 16" register: drone_token @@ -208,14 +205,14 @@ template: src: .env.j2 dest: /home/{{ user }}/.env - + - name: start validate plugin shell: "droneAuth -secret={{ drone_secret.stdout }} -cfg=/home/{{ user }}/users.json -endpoint={{ drone_validate_plugin_endpoint }}>/dev/null 2>&1 &" async: 10 poll: 0 environment: PATH: "{{ lookup('env','PATH') }}:/home/{{ user }}/go/bin:/usr/local/go/bin:{{ ansible_env.PATH }}" - + - name: start drone become: yes shell: "drone-server --env-file=/home/{{ user }}/.env >/home/{{ user }}/drone.log 2>&1 &" @@ -223,13 +220,13 @@ poll: 0 environment: PATH: "{{ lookup('env','PATH') }}:/home/{{ user }}/go/bin:/usr/local/go/bin:{{ ansible_env.PATH }}" - + - name: Check if drone-runner is running become: yes shell: docker container ls -q -f="name=drone-runner" register: continerList2 - - name: Start drone-runner + - name: Start drone-runner become: yes shell: docker run -d -v /var/run/docker.sock:/var/run/docker.sock -e DRONE_RPC_PROTO="https" -e DRONE_RPC_HOST="{{ drone_server_host }}" -e DRONE_RPC_SECRET="{{ drone_secret.stdout }}" -e DRONE_RUNNER_CAPACITY={{ docker_runner_capacity }} -e DRONE_RUNNER_NAME=cgrates -p 3000:3000 --restart always --name runner drone/drone-runner-docker:1 when: continerList2.stdout_lines|length == 0 @@ -238,13 +235,13 @@ copy: dest: "/home/{{ user }}/credentials.json" content: "{{ gapi_credentials }}" - - - name: Creating token file + + - name: Creating token file copy: dest: "/home/{{ user }}/token.json" content: "{{ gapi_token }}" - - name: add secrets + - name: add secrets become: yes shell: | drone-cli orgsecret add {{ item }} credentials @/home/{{ user }}/credentials.json --allow-pull-request; @@ -253,14 +250,14 @@ PATH: "{{ lookup('env','PATH') }}:/home/{{ user }}/go/bin:/usr/local/go/bin:{{ ansible_env.PATH }}" DRONE_SERVER: "https://{{ drone_server_host }}" DRONE_TOKEN: "{{ drone_token.stdout }}" - with_items: '{{ drone_user_filter }}' + with_items: "{{ drone_user_filter }}" - name: Removeing credentials file file: path: "/home/{{ user }}/credentials.json" state: absent - - - name: Removeing token file + + - name: Removeing token file file: path: "/home/{{ user }}/token.json" - state: absent \ No newline at end of file + state: absent diff --git a/dispatchers/attributes.go b/dispatchers/attributes.go index 0f5c7445b..1fb0b5e38 100644 --- a/dispatchers/attributes.go +++ b/dispatchers/attributes.go @@ -19,12 +19,13 @@ along with this program. If not, see package dispatchers import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // AttributeSv1Ping interrogates AttributeS server responsible to process the event -func (dS *DispatcherService) AttributeSv1Ping(args *utils.CGREvent, +func (dS *DispatcherService) AttributeSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) @@ -43,7 +44,7 @@ func (dS *DispatcherService) AttributeSv1Ping(args *utils.CGREvent, } // AttributeSv1GetAttributeForEvent is the dispatcher method for AttributeSv1.GetAttributeForEvent -func (dS *DispatcherService) AttributeSv1GetAttributeForEvent(args *utils.CGREvent, +func (dS *DispatcherService) AttributeSv1GetAttributeForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.AttributeProfile) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && args.Tenant != utils.EmptyString { @@ -59,7 +60,7 @@ func (dS *DispatcherService) AttributeSv1GetAttributeForEvent(args *utils.CGREve } // AttributeSv1ProcessEvent . -func (dS *DispatcherService) AttributeSv1ProcessEvent(args *utils.CGREvent, +func (dS *DispatcherService) AttributeSv1ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.AttrSProcessEventReply) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && args.Tenant != utils.EmptyString { diff --git a/dispatchers/attributes_it_test.go b/dispatchers/attributes_it_test.go index ad0e0dc47..29499d95e 100644 --- a/dispatchers/attributes_it_test.go +++ b/dispatchers/attributes_it_test.go @@ -25,6 +25,7 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -88,13 +89,13 @@ func TestDspAttributeSNoConn(t *testing.T) { func testDspAttrPingFailover(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } reply = "" - if err := allEngine2.RPC.Call(utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine2.RPC.Call(context.Background(), utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -106,27 +107,27 @@ func testDspAttrPingFailover(t *testing.T) { utils.OptsAPIKey: "attr12345", }, } - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine.stopEngine(t) reply = "" - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine2.stopEngine(t) reply = "" - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine.startEngine(t) allEngine2.startEngine(t) reply = "" - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -135,7 +136,7 @@ func testDspAttrPingFailover(t *testing.T) { func testDspAttrPingFailoverNotFoundHost(t *testing.T) { var reply string - if err := allEngine2.RPC.Call(utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine2.RPC.Call(context.Background(), utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -151,18 +152,18 @@ func testDspAttrPingFailoverNotFoundHost(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine2.stopEngine(t) // stop the engine and we expect to get error - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine2.startEngine(t) reply = "" - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -171,13 +172,13 @@ func testDspAttrPingFailoverNotFoundHost(t *testing.T) { func testDspAttrPingFailover2(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } reply = "" - if err := allEngine2.RPC.Call(utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine2.RPC.Call(context.Background(), utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -190,20 +191,20 @@ func testDspAttrPingFailover2(t *testing.T) { }, } allEngine.stopEngine(t) // stop the engine and the call should go to the second engine - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine2.stopEngine(t) reply = "" - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine.startEngine(t) allEngine2.startEngine(t) reply = "" - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -263,12 +264,12 @@ func testDspAttrGetAttrFailover(t *testing.T) { var attrReply *engine.AttributeProfile var rplyEv engine.AttrSProcessEventReply - if err := dispEngine.RPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, args, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := dispEngine.RPC.Call(utils.AttributeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, args, &rplyEv); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } else if reflect.DeepEqual(eRply, &rplyEv) { @@ -278,7 +279,7 @@ func testDspAttrGetAttrFailover(t *testing.T) { allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, args, &attrReply); err != nil { t.Error(err) } @@ -291,7 +292,7 @@ func testDspAttrGetAttrFailover(t *testing.T) { eRply.APIOpts[utils.MetaNodeID] = "DispatcherS1" eRply.APIOpts[utils.MetaSubsys] = "*dispatchers" - if err := dispEngine.RPC.Call(utils.AttributeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, args, &rplyEv); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRply, &rplyEv) { @@ -304,7 +305,7 @@ func testDspAttrGetAttrFailover(t *testing.T) { func testDspAttrPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -312,7 +313,7 @@ func testDspAttrPing(t *testing.T) { if dispEngine.RPC == nil { t.Fatal(dispEngine.RPC) } - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ utils.OptsAPIKey: "attr12345", @@ -336,7 +337,7 @@ func testDspAttrTestMissingArgDispatcher(t *testing.T) { }, } var attrReply *engine.AttributeProfile - if err := dispEngine.RPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, args, &attrReply); err == nil || err.Error() != utils.NewErrMandatoryIeMissing(utils.APIKey).Error() { t.Errorf("Error:%v rply=%s", err, utils.ToJSON(attrReply)) } @@ -354,7 +355,7 @@ func testDspAttrTestMissingApiKey(t *testing.T) { }, } var attrReply *engine.AttributeProfile - if err := dispEngine.RPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, args, &attrReply); err == nil || err.Error() != utils.NewErrMandatoryIeMissing(utils.APIKey).Error() { t.Errorf("Error:%v rply=%s", err, utils.ToJSON(attrReply)) } @@ -372,7 +373,7 @@ func testDspAttrTestUnknownApiKey(t *testing.T) { }, } var attrReply *engine.AttributeProfile - if err := dispEngine.RPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, args, &attrReply); err == nil || err.Error() != utils.ErrUnknownApiKey.Error() { t.Error(err) } @@ -391,7 +392,7 @@ func testDspAttrTestAuthKey(t *testing.T) { }, } var attrReply *engine.AttributeProfile - if err := dispEngine.RPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, args, &attrReply); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() { t.Error(err) } @@ -429,7 +430,7 @@ func testDspAttrTestAuthKey2(t *testing.T) { eAttrPrf.Attributes[0].FilterIDs = nil // empty slice are nil in gob } var attrReply *engine.AttributeProfile - if err := dispEngine.RPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, args, &attrReply); err != nil { t.Error(err) } @@ -461,7 +462,7 @@ func testDspAttrTestAuthKey2(t *testing.T) { } var rplyEv engine.AttrSProcessEventReply - if err := dispEngine.RPC.Call(utils.AttributeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, args, &rplyEv); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRply, &rplyEv) { @@ -484,7 +485,7 @@ func testDspAttrTestAuthKey3(t *testing.T) { }, } var attrReply *engine.AttributeProfile - if err := dispEngine.RPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, args, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -542,13 +543,13 @@ func testDspAttrGetAttrRoundRobin(t *testing.T) { var attrReply *engine.AttributeProfile var rplyEv engine.AttrSProcessEventReply // To ALL2 - if err := dispEngine.RPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, args, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } // To ALL - if err := dispEngine.RPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, args, &attrReply); err != nil { t.Error(err) } @@ -560,7 +561,7 @@ func testDspAttrGetAttrRoundRobin(t *testing.T) { } // To ALL2 - if err := dispEngine.RPC.Call(utils.AttributeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, args, &rplyEv); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } else if reflect.DeepEqual(eRply, &rplyEv) { @@ -572,7 +573,7 @@ func testDspAttrGetAttrRoundRobin(t *testing.T) { eRply.APIOpts[utils.MetaNodeID] = "DispatcherS1" eRply.APIOpts[utils.MetaSubsys] = "*dispatchers" // To ALL - if err := dispEngine.RPC.Call(utils.AttributeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, args, &rplyEv); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRply, &rplyEv) { @@ -616,7 +617,7 @@ func testDspAttrGetAttrInternal(t *testing.T) { } var rplyEv engine.AttrSProcessEventReply - if err := dispEngine.RPC.Call(utils.AttributeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, args, &rplyEv); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRply, &rplyEv) { @@ -627,7 +628,7 @@ func testDspAttrGetAttrInternal(t *testing.T) { func testDspAttrPingNoArgDispatcher(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -635,7 +636,7 @@ func testDspAttrPingNoArgDispatcher(t *testing.T) { if dispEngine.RPC == nil { t.Fatal(dispEngine.RPC) } - if err := dispEngine.RPC.Call(utils.AttributeSv1Ping, &utils.CGREvent{Tenant: "cgrates.org"}, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.AttributeSv1Ping, &utils.CGREvent{Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) diff --git a/dispatchers/attributes_test.go b/dispatchers/attributes_test.go index 149780aa1..fa621b74e 100644 --- a/dispatchers/attributes_test.go +++ b/dispatchers/attributes_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -32,7 +33,7 @@ func TestDspAttributeSv1PingError(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrEvent := &utils.CGREvent{} var reply *string - err := dspSrv.AttributeSv1Ping(cgrEvent, reply) + err := dspSrv.AttributeSv1Ping(context.Background(), cgrEvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -50,7 +51,7 @@ func TestDspAttributeSv1PingErrorTenant(t *testing.T) { APIOpts: nil, } var reply *string - err := dspSrv.AttributeSv1Ping(cgrEvent, reply) + err := dspSrv.AttributeSv1Ping(context.Background(), cgrEvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -61,7 +62,7 @@ func TestDspAttributeSv1PingErrorNil(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - err := dspSrv.AttributeSv1Ping(nil, reply) + err := dspSrv.AttributeSv1Ping(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -80,7 +81,7 @@ func TestDspAttributeSv1PingErrorAttributeSConns(t *testing.T) { APIOpts: nil, } var reply *string - err := dspSrv.AttributeSv1Ping(cgrEvent, reply) + err := dspSrv.AttributeSv1Ping(context.Background(), cgrEvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -95,7 +96,7 @@ func TestDspAttributeSv1GetAttributeForEventError(t *testing.T) { Time: &time.Time{}, } var reply *engine.AttributeProfile - err := dspSrv.AttributeSv1GetAttributeForEvent(processEvent, reply) + err := dspSrv.AttributeSv1GetAttributeForEvent(context.Background(), processEvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -111,7 +112,7 @@ func TestDspAttributeSv1GetAttributeForEventErrorTenant(t *testing.T) { Time: &time.Time{}, } var reply *engine.AttributeProfile - err := dspSrv.AttributeSv1GetAttributeForEvent(processEvent, reply) + err := dspSrv.AttributeSv1GetAttributeForEvent(context.Background(), processEvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -127,7 +128,7 @@ func TestDspAttributeSv1GetAttributeForEventErrorAttributeS(t *testing.T) { } var reply *engine.AttributeProfile - err := dspSrv.AttributeSv1GetAttributeForEvent(processEvent, reply) + err := dspSrv.AttributeSv1GetAttributeForEvent(context.Background(), processEvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -143,7 +144,7 @@ func TestDspAttributeSv1ProcessEventError(t *testing.T) { } var reply *engine.AttrSProcessEventReply - err := dspSrv.AttributeSv1ProcessEvent(processEvent, reply) + err := dspSrv.AttributeSv1ProcessEvent(context.Background(), processEvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -160,7 +161,7 @@ func TestDspAttributeSv1ProcessEventErrorAttributeSConns(t *testing.T) { } var reply *engine.AttrSProcessEventReply - err := dspSrv.AttributeSv1ProcessEvent(processEvent, reply) + err := dspSrv.AttributeSv1ProcessEvent(context.Background(), processEvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) diff --git a/dispatchers/caches.go b/dispatchers/caches.go index b160d6d5d..5eed6fbad 100644 --- a/dispatchers/caches.go +++ b/dispatchers/caches.go @@ -21,12 +21,13 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" ) // CacheSv1Ping interogates CacheSv1 server responsible to process the event -func (dS *DispatcherService) CacheSv1Ping(args *utils.CGREvent, +func (dS *DispatcherService) CacheSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) @@ -45,7 +46,7 @@ func (dS *DispatcherService) CacheSv1Ping(args *utils.CGREvent, } // CacheSv1GetItemIDs returns the IDs for cacheID with given prefix -func (dS *DispatcherService) CacheSv1GetItemIDs(args *utils.ArgsGetCacheItemIDsWithAPIOpts, +func (dS *DispatcherService) CacheSv1GetItemIDs(ctx *context.Context, args *utils.ArgsGetCacheItemIDsWithAPIOpts, reply *[]string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -64,7 +65,7 @@ func (dS *DispatcherService) CacheSv1GetItemIDs(args *utils.ArgsGetCacheItemIDsW } // CacheSv1HasItem verifies the existence of an Item in cache -func (dS *DispatcherService) CacheSv1HasItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (dS *DispatcherService) CacheSv1HasItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *bool) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -84,7 +85,7 @@ func (dS *DispatcherService) CacheSv1HasItem(args *utils.ArgsGetCacheItemWithAPI utils.MetaCaches, utils.CacheSv1HasItem, args, reply) } -func (dS *DispatcherService) CacheSv1GetItem(args *utils.ArgsGetCacheItemWithAPIOpts, reply *any) (err error) { +func (dS *DispatcherService) CacheSv1GetItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *any) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant @@ -104,7 +105,7 @@ func (dS *DispatcherService) CacheSv1GetItem(args *utils.ArgsGetCacheItemWithAPI } // CacheSv1GetItemExpiryTime returns the expiryTime for an item -func (dS *DispatcherService) CacheSv1GetItemExpiryTime(args *utils.ArgsGetCacheItemWithAPIOpts, +func (dS *DispatcherService) CacheSv1GetItemExpiryTime(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *time.Time) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -124,7 +125,7 @@ func (dS *DispatcherService) CacheSv1GetItemExpiryTime(args *utils.ArgsGetCacheI } // CacheSv1RemoveItem removes the Item with ID from cache -func (dS *DispatcherService) CacheSv1RemoveItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (dS *DispatcherService) CacheSv1RemoveItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -143,7 +144,7 @@ func (dS *DispatcherService) CacheSv1RemoveItem(args *utils.ArgsGetCacheItemWith } // CacheSv1RemoveItems removes the Item with ID from cache -func (dS *DispatcherService) CacheSv1RemoveItems(args *utils.AttrReloadCacheWithAPIOpts, +func (dS *DispatcherService) CacheSv1RemoveItems(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -162,7 +163,7 @@ func (dS *DispatcherService) CacheSv1RemoveItems(args *utils.AttrReloadCacheWith } // CacheSv1Clear will clear partitions in the cache (nil fol all, empty slice for none) -func (dS *DispatcherService) CacheSv1Clear(args *utils.AttrCacheIDsWithAPIOpts, +func (dS *DispatcherService) CacheSv1Clear(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -181,7 +182,7 @@ func (dS *DispatcherService) CacheSv1Clear(args *utils.AttrCacheIDsWithAPIOpts, } // CacheSv1GetCacheStats returns CacheStats filtered by cacheIDs -func (dS *DispatcherService) CacheSv1GetCacheStats(args *utils.AttrCacheIDsWithAPIOpts, +func (dS *DispatcherService) CacheSv1GetCacheStats(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, reply *map[string]*ltcache.CacheStats) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -200,7 +201,7 @@ func (dS *DispatcherService) CacheSv1GetCacheStats(args *utils.AttrCacheIDsWithA } // CacheSv1PrecacheStatus checks status of active precache processes -func (dS *DispatcherService) CacheSv1PrecacheStatus(args *utils.AttrCacheIDsWithAPIOpts, reply *map[string]string) (err error) { +func (dS *DispatcherService) CacheSv1PrecacheStatus(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, reply *map[string]string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -217,7 +218,7 @@ func (dS *DispatcherService) CacheSv1PrecacheStatus(args *utils.AttrCacheIDsWith }, utils.MetaCaches, utils.CacheSv1PrecacheStatus, args, reply) } -func (dS *DispatcherService) CacheSv1GetItemWithRemote(args *utils.ArgsGetCacheItemWithAPIOpts, reply *any) (err error) { +func (dS *DispatcherService) CacheSv1GetItemWithRemote(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *any) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant @@ -237,7 +238,7 @@ func (dS *DispatcherService) CacheSv1GetItemWithRemote(args *utils.ArgsGetCacheI } // CacheSv1HasGroup checks existence of a group in cache -func (dS *DispatcherService) CacheSv1HasGroup(args *utils.ArgsGetGroupWithAPIOpts, +func (dS *DispatcherService) CacheSv1HasGroup(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, reply *bool) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -256,7 +257,7 @@ func (dS *DispatcherService) CacheSv1HasGroup(args *utils.ArgsGetGroupWithAPIOpt } // CacheSv1GetGroupItemIDs returns a list of itemIDs in a cache group -func (dS *DispatcherService) CacheSv1GetGroupItemIDs(args *utils.ArgsGetGroupWithAPIOpts, +func (dS *DispatcherService) CacheSv1GetGroupItemIDs(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, reply *[]string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -275,7 +276,7 @@ func (dS *DispatcherService) CacheSv1GetGroupItemIDs(args *utils.ArgsGetGroupWit } // CacheSv1RemoveGroup will remove a group and all items belonging to it from cache -func (dS *DispatcherService) CacheSv1RemoveGroup(args *utils.ArgsGetGroupWithAPIOpts, reply *string) (err error) { +func (dS *DispatcherService) CacheSv1RemoveGroup(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -293,7 +294,7 @@ func (dS *DispatcherService) CacheSv1RemoveGroup(args *utils.ArgsGetGroupWithAPI } // CacheSv1ReloadCache reloads cache from DB for a prefix or completely -func (dS *DispatcherService) CacheSv1ReloadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { +func (dS *DispatcherService) CacheSv1ReloadCache(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -311,7 +312,7 @@ func (dS *DispatcherService) CacheSv1ReloadCache(args *utils.AttrReloadCacheWith } // CacheSv1LoadCache loads cache from DB for a prefix or completely -func (dS *DispatcherService) CacheSv1LoadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { +func (dS *DispatcherService) CacheSv1LoadCache(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -329,7 +330,7 @@ func (dS *DispatcherService) CacheSv1LoadCache(args *utils.AttrReloadCacheWithAP } // CacheSv1ReplicateRemove remove an item -func (dS *DispatcherService) CacheSv1ReplicateRemove(args *utils.ArgCacheReplicateRemove, reply *string) (err error) { +func (dS *DispatcherService) CacheSv1ReplicateRemove(ctx *context.Context, args *utils.ArgCacheReplicateRemove, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -347,7 +348,7 @@ func (dS *DispatcherService) CacheSv1ReplicateRemove(args *utils.ArgCacheReplica } // CacheSv1ReplicateSet replicate an item -func (dS *DispatcherService) CacheSv1ReplicateSet(args *utils.ArgCacheReplicateSet, reply *string) (err error) { +func (dS *DispatcherService) CacheSv1ReplicateSet(ctx *context.Context, args *utils.ArgCacheReplicateSet, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant diff --git a/dispatchers/caches_it_test.go b/dispatchers/caches_it_test.go index 6eaf6047c..576c6d589 100644 --- a/dispatchers/caches_it_test.go +++ b/dispatchers/caches_it_test.go @@ -27,6 +27,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" @@ -73,7 +74,7 @@ func TestDspCacheSv1(t *testing.T) { func testDspChcPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.CacheSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.CacheSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -81,7 +82,7 @@ func testDspChcPing(t *testing.T) { if dispEngine.RPC == nil { t.Fatal(dispEngine.RPC) } - if err := dispEngine.RPC.Call(utils.CacheSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", @@ -108,7 +109,7 @@ func testDspChcLoadAfterFolder(t *testing.T) { }, Tenant: "cgrates.org", } - if err := dispEngine.RPC.Call(utils.CacheSv1GetCacheStats, args, &rcvStats); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1GetCacheStats, args, &rcvStats); err != nil { t.Error(err) } else if !reflect.DeepEqual(expStats, rcvStats) { t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats)) @@ -120,7 +121,7 @@ func testDspChcLoadAfterFolder(t *testing.T) { utils.OptsAPIKey: "chc12345", } argsR.Tenant = "cgrates.org" - if err := dispEngine.RPC.Call(utils.CacheSv1LoadCache, argsR, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1LoadCache, argsR, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(reply) @@ -156,7 +157,7 @@ func testDspChcLoadAfterFolder(t *testing.T) { expStats[utils.CacheAttributeFilterIndexes].Groups = 4 expStats[utils.CacheReverseFilterIndexes].Items = 8 expStats[utils.CacheReverseFilterIndexes].Groups = 6 - if err := dispEngine.RPC.Call(utils.CacheSv1GetCacheStats, &args, &rcvStats); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1GetCacheStats, &args, &rcvStats); err != nil { t.Error(err) } else if !reflect.DeepEqual(expStats, rcvStats) { t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats)) @@ -217,7 +218,7 @@ func testDspChcPrecacheStatus(t *testing.T) { utils.CacheReplicationHosts: utils.MetaReady, } - if err := dispEngine.RPC.Call(utils.CacheSv1PrecacheStatus, utils.AttrCacheIDsWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1PrecacheStatus, utils.AttrCacheIDsWithAPIOpts{ APIOpts: map[string]any{ utils.OptsAPIKey: "chc12345", }, @@ -241,7 +242,7 @@ func testDspChcGetItemIDs(t *testing.T) { }, Tenant: "cgrates.org", } - if err := dispEngine.RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Fatalf("Got error on APIerSv1.GetCacheStats: %s ", err.Error()) } sort.Strings(rcvKeys) @@ -263,7 +264,7 @@ func testDspChcHasItem(t *testing.T) { }, Tenant: "cgrates.org", } - if err := dispEngine.RPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: %v , received:%v", expected, reply) @@ -283,7 +284,7 @@ func testDspChcGetItemExpiryTime(t *testing.T) { }, Tenant: "cgrates.org", } - if err := dispEngine.RPC.Call(utils.CacheSv1GetItemExpiryTime, argsAPI, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1GetItemExpiryTime, argsAPI, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expected, reply) { t.Errorf("Expected: %v , received:%v", expected, reply) @@ -292,7 +293,7 @@ func testDspChcGetItemExpiryTime(t *testing.T) { func testDspChcReloadCache(t *testing.T) { reply := "" - if err := dispEngine.RPC.Call(utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ APIOpts: map[string]any{ utils.OptsAPIKey: "chc12345", }, @@ -316,18 +317,18 @@ func testDspChcRemoveItem(t *testing.T) { }, Tenant: "cgrates.org", } - if err := dispEngine.RPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: %v , received:%v", true, reply) } var remReply string - if err := dispEngine.RPC.Call(utils.CacheSv1RemoveItem, argsAPI, &remReply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1RemoveItem, argsAPI, &remReply); err != nil { t.Error(err) } else if remReply != utils.OK { t.Errorf("Expected: %v , received:%v", utils.OK, remReply) } - if err := dispEngine.RPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1HasItem, argsAPI, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: %v , received:%v", false, reply) @@ -336,7 +337,7 @@ func testDspChcRemoveItem(t *testing.T) { func testDspChcClear(t *testing.T) { reply := "" - if err := dispEngine.RPC.Call(utils.CacheSv1Clear, utils.AttrCacheIDsWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1Clear, utils.AttrCacheIDsWithAPIOpts{ APIOpts: map[string]any{ utils.OptsAPIKey: "chc12345", }, @@ -348,7 +349,7 @@ func testDspChcClear(t *testing.T) { } var rcvStats map[string]*ltcache.CacheStats expStats := engine.GetDefaultEmptyCacheStats() - if err := dispEngine.RPC.Call(utils.CacheSv1GetCacheStats, utils.AttrCacheIDsWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.CacheSv1GetCacheStats, utils.AttrCacheIDsWithAPIOpts{ APIOpts: map[string]any{ utils.OptsAPIKey: "chc12345", }, diff --git a/dispatchers/caches_test.go b/dispatchers/caches_test.go index f228bb2bc..a236ebd65 100644 --- a/dispatchers/caches_test.go +++ b/dispatchers/caches_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -39,7 +40,7 @@ func TestDspCacheSv1PingError(t *testing.T) { APIOpts: nil, } var reply *string - result := dspSrv.CacheSv1Ping(CGREvent, reply) + result := dspSrv.CacheSv1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -50,7 +51,7 @@ func TestDspCacheSv1PingErrorArgs(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.CacheSv1Ping(nil, reply) + result := dspSrv.CacheSv1Ping(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -69,7 +70,7 @@ func TestDspCacheSv1PingErrorAttributeSConns(t *testing.T) { APIOpts: nil, } var reply *string - result := dspSrv.CacheSv1Ping(CGREvent, reply) + result := dspSrv.CacheSv1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -82,7 +83,7 @@ func TestDspCacheSv1GetItemIDsError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.ArgsGetCacheItemIDsWithAPIOpts{} var reply *[]string - result := dspSrv.CacheSv1GetItemIDs(CGREvent, reply) + result := dspSrv.CacheSv1GetItemIDs(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -96,7 +97,7 @@ func TestDspCacheSv1GetItemIDsErrorArgsNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.CacheSv1GetItemIDs(CGREvent, reply) + result := dspSrv.CacheSv1GetItemIDs(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -109,7 +110,7 @@ func TestDspCacheSv1HasItemError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.ArgsGetCacheItemWithAPIOpts{} var reply *bool - result := dspSrv.CacheSv1HasItem(CGREvent, reply) + result := dspSrv.CacheSv1HasItem(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -123,7 +124,7 @@ func TestDspCacheSv1HasItemErrorArgsNil(t *testing.T) { Tenant: "tenant", } var reply *bool - result := dspSrv.CacheSv1HasItem(CGREvent, reply) + result := dspSrv.CacheSv1HasItem(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -136,7 +137,7 @@ func TestDspCacheSv1GetItemExpiryTimeCacheSv1GetItemExpiryTimeError(t *testing.T cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.ArgsGetCacheItemWithAPIOpts{} var reply *time.Time - result := dspSrv.CacheSv1GetItemExpiryTime(CGREvent, reply) + result := dspSrv.CacheSv1GetItemExpiryTime(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -150,7 +151,7 @@ func TestDspCacheSv1GetItemExpiryTimeCacheSv1GetItemExpiryTimeErrorArgsNil(t *te Tenant: "tenant", } var reply *time.Time - result := dspSrv.CacheSv1GetItemExpiryTime(CGREvent, reply) + result := dspSrv.CacheSv1GetItemExpiryTime(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -163,7 +164,7 @@ func TestDspCacheSv1RemoveItemError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.ArgsGetCacheItemWithAPIOpts{} var reply *string - result := dspSrv.CacheSv1RemoveItem(CGREvent, reply) + result := dspSrv.CacheSv1RemoveItem(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -177,7 +178,7 @@ func TestDspCacheSv1RemoveItemArgsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CacheSv1RemoveItem(CGREvent, reply) + result := dspSrv.CacheSv1RemoveItem(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -190,7 +191,7 @@ func TestDspCacheSv1RemoveItemsError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.AttrReloadCacheWithAPIOpts{} var reply *string - result := dspSrv.CacheSv1RemoveItems(CGREvent, reply) + result := dspSrv.CacheSv1RemoveItems(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -204,7 +205,7 @@ func TestDspCacheSv1RemoveItemsArgsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CacheSv1RemoveItems(CGREvent, reply) + result := dspSrv.CacheSv1RemoveItems(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -217,7 +218,7 @@ func TestDspCacheSv1ClearError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.AttrCacheIDsWithAPIOpts{} var reply *string - result := dspSrv.CacheSv1Clear(CGREvent, reply) + result := dspSrv.CacheSv1Clear(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -231,7 +232,7 @@ func TestDspCacheSv1ClearArgsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CacheSv1Clear(CGREvent, reply) + result := dspSrv.CacheSv1Clear(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -244,7 +245,7 @@ func TestDspCacheSv1GetCacheStatsError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.AttrCacheIDsWithAPIOpts{} var reply *map[string]*ltcache.CacheStats - result := dspSrv.CacheSv1GetCacheStats(CGREvent, reply) + result := dspSrv.CacheSv1GetCacheStats(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -258,7 +259,7 @@ func TestDspCacheSv1GetCacheStatsArgsNil(t *testing.T) { Tenant: "tenant", } var reply *map[string]*ltcache.CacheStats - result := dspSrv.CacheSv1GetCacheStats(CGREvent, reply) + result := dspSrv.CacheSv1GetCacheStats(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -271,7 +272,7 @@ func TestDspCacheSv1PrecacheStatusError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.AttrCacheIDsWithAPIOpts{} var reply *map[string]string - result := dspSrv.CacheSv1PrecacheStatus(CGREvent, reply) + result := dspSrv.CacheSv1PrecacheStatus(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -285,7 +286,7 @@ func TestDspCacheSv1PrecacheStatusArgsNil(t *testing.T) { Tenant: "tenant", } var reply *map[string]string - result := dspSrv.CacheSv1PrecacheStatus(CGREvent, reply) + result := dspSrv.CacheSv1PrecacheStatus(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -298,7 +299,7 @@ func TestDspCacheSv1HasGroupError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.ArgsGetGroupWithAPIOpts{} var reply *bool - result := dspSrv.CacheSv1HasGroup(CGREvent, reply) + result := dspSrv.CacheSv1HasGroup(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -312,7 +313,7 @@ func TestDspCacheSv1HasGroupArgsNil(t *testing.T) { Tenant: "tenant", } var reply *bool - result := dspSrv.CacheSv1HasGroup(CGREvent, reply) + result := dspSrv.CacheSv1HasGroup(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -325,7 +326,7 @@ func TestDspCacheSv1GetGroupItemIDsError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.ArgsGetGroupWithAPIOpts{} var reply *[]string - result := dspSrv.CacheSv1GetGroupItemIDs(CGREvent, reply) + result := dspSrv.CacheSv1GetGroupItemIDs(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -339,7 +340,7 @@ func TestDspCacheSv1GetGroupItemIDsArgsNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.CacheSv1GetGroupItemIDs(CGREvent, reply) + result := dspSrv.CacheSv1GetGroupItemIDs(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -352,7 +353,7 @@ func TestDspCacheSv1RemoveGroupError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.ArgsGetGroupWithAPIOpts{} var reply *string - result := dspSrv.CacheSv1RemoveGroup(CGREvent, reply) + result := dspSrv.CacheSv1RemoveGroup(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -366,7 +367,7 @@ func TestDspCacheSv1RemoveGroupArgsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CacheSv1RemoveGroup(CGREvent, reply) + result := dspSrv.CacheSv1RemoveGroup(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -379,7 +380,7 @@ func TestDspCacheSv1ReloadCacheError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.AttrReloadCacheWithAPIOpts{} var reply *string - result := dspSrv.CacheSv1ReloadCache(CGREvent, reply) + result := dspSrv.CacheSv1ReloadCache(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -393,7 +394,7 @@ func TestDspCacheSv1ReloadCacheNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CacheSv1ReloadCache(CGREvent, reply) + result := dspSrv.CacheSv1ReloadCache(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -406,7 +407,7 @@ func TestDspCacheSv1LoadCacheError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.AttrReloadCacheWithAPIOpts{} var reply *string - result := dspSrv.CacheSv1LoadCache(CGREvent, reply) + result := dspSrv.CacheSv1LoadCache(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -420,7 +421,7 @@ func TestDspCacheSv1LoadCacheNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CacheSv1LoadCache(CGREvent, reply) + result := dspSrv.CacheSv1LoadCache(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -433,7 +434,7 @@ func TestDspCacheSv1ReplicateRemoveError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.ArgCacheReplicateRemove{} var reply *string - result := dspSrv.CacheSv1ReplicateRemove(CGREvent, reply) + result := dspSrv.CacheSv1ReplicateRemove(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -447,7 +448,7 @@ func TestDspCacheSv1ReplicateRemoveNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CacheSv1ReplicateRemove(CGREvent, reply) + result := dspSrv.CacheSv1ReplicateRemove(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -460,7 +461,7 @@ func TestDspCacheSv1ReplicateSetError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.ArgCacheReplicateSet{} var reply *string - result := dspSrv.CacheSv1ReplicateSet(CGREvent, reply) + result := dspSrv.CacheSv1ReplicateSet(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -474,7 +475,7 @@ func TestDspCacheSv1ReplicateSetNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CacheSv1ReplicateSet(CGREvent, reply) + result := dspSrv.CacheSv1ReplicateSet(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -516,7 +517,7 @@ func TestDspCacheSv1GetItemWithRemote(t *testing.T) { t.Error(err) } var reply any - if err := dsp.CacheSv1GetItemWithRemote(args, &reply); err == nil { + if err := dsp.CacheSv1GetItemWithRemote(context.Background(), args, &reply); err == nil { t.Error(err) } } @@ -554,7 +555,7 @@ func TestDspCacheSv1GetItem(t *testing.T) { t.Error(err) } var reply any - if err := dsp.CacheSv1GetItem(args, &reply); err == nil { + if err := dsp.CacheSv1GetItem(context.Background(), args, &reply); err == nil { t.Error(err) } diff --git a/dispatchers/cdrs.go b/dispatchers/cdrs.go index 861986bc9..e3826dfd9 100644 --- a/dispatchers/cdrs.go +++ b/dispatchers/cdrs.go @@ -21,12 +21,13 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // CDRsV1Ping interogates CDRsV1 server responsible to process the event -func (dS *DispatcherService) CDRsV1Ping(args *utils.CGREvent, +func (dS *DispatcherService) CDRsV1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) @@ -46,7 +47,7 @@ func (dS *DispatcherService) CDRsV1Ping(args *utils.CGREvent, } // CDRsV1GetCDRs returns the CDRs that match the filter -func (dS *DispatcherService) CDRsV1GetCDRs(args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) (err error) { +func (dS *DispatcherService) CDRsV1GetCDRs(ctx *context.Context, args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -64,7 +65,7 @@ func (dS *DispatcherService) CDRsV1GetCDRs(args *utils.RPCCDRsFilterWithAPIOpts, } // CDRsV1GetCDRsCount counts the cdrs that match the filter -func (dS *DispatcherService) CDRsV1GetCDRsCount(args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) (err error) { +func (dS *DispatcherService) CDRsV1GetCDRsCount(ctx *context.Context, args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -81,7 +82,7 @@ func (dS *DispatcherService) CDRsV1GetCDRsCount(args *utils.RPCCDRsFilterWithAPI }, utils.MetaCDRs, utils.CDRsV1GetCDRsCount, args, reply) } -func (dS *DispatcherService) CDRsV1StoreSessionCost(args *engine.AttrCDRSStoreSMCost, reply *string) (err error) { +func (dS *DispatcherService) CDRsV1StoreSessionCost(ctx *context.Context, args *engine.AttrCDRSStoreSMCost, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -98,7 +99,7 @@ func (dS *DispatcherService) CDRsV1StoreSessionCost(args *engine.AttrCDRSStoreSM }, utils.MetaCDRs, utils.CDRsV1StoreSessionCost, args, reply) } -func (dS *DispatcherService) CDRsV1RateCDRs(args *engine.ArgRateCDRs, reply *string) (err error) { +func (dS *DispatcherService) CDRsV1RateCDRs(ctx *context.Context, args *engine.ArgRateCDRs, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -115,7 +116,7 @@ func (dS *DispatcherService) CDRsV1RateCDRs(args *engine.ArgRateCDRs, reply *str }, utils.MetaCDRs, utils.CDRsV1RateCDRs, args, reply) } -func (dS *DispatcherService) CDRsV1ProcessExternalCDR(args *engine.ExternalCDRWithAPIOpts, reply *string) (err error) { +func (dS *DispatcherService) CDRsV1ProcessExternalCDR(ctx *context.Context, args *engine.ExternalCDRWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -132,7 +133,7 @@ func (dS *DispatcherService) CDRsV1ProcessExternalCDR(args *engine.ExternalCDRWi }, utils.MetaCDRs, utils.CDRsV1ProcessExternalCDR, args, reply) } -func (dS *DispatcherService) CDRsV1ProcessEvent(args *engine.ArgV1ProcessEvent, reply *string) (err error) { +func (dS *DispatcherService) CDRsV1ProcessEvent(ctx *context.Context, args *engine.ArgV1ProcessEvent, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.CGREvent.Tenant != utils.EmptyString { tnt = args.CGREvent.Tenant @@ -147,7 +148,7 @@ func (dS *DispatcherService) CDRsV1ProcessEvent(args *engine.ArgV1ProcessEvent, utils.CDRsV1ProcessEvent, args, reply) } -func (dS *DispatcherService) CDRsV1ProcessCDR(args *engine.CDRWithAPIOpts, reply *string) (err error) { +func (dS *DispatcherService) CDRsV1ProcessCDR(ctx *context.Context, args *engine.CDRWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -164,7 +165,7 @@ func (dS *DispatcherService) CDRsV1ProcessCDR(args *engine.CDRWithAPIOpts, reply }, utils.MetaCDRs, utils.CDRsV1ProcessCDR, args, reply) } -func (dS *DispatcherService) CDRsV2ProcessEvent(args *engine.ArgV1ProcessEvent, reply *[]*utils.EventWithFlags) (err error) { +func (dS *DispatcherService) CDRsV2ProcessEvent(ctx *context.Context, args *engine.ArgV1ProcessEvent, reply *[]*utils.EventWithFlags) (err error) { tnt := args.Tenant if tnt == utils.EmptyString { tnt = dS.cfg.GeneralCfg().DefaultTenant @@ -179,7 +180,7 @@ func (dS *DispatcherService) CDRsV2ProcessEvent(args *engine.ArgV1ProcessEvent, utils.CDRsV2ProcessEvent, args, reply) } -func (dS *DispatcherService) CDRsV2StoreSessionCost(args *engine.ArgsV2CDRSStoreSMCost, reply *string) (err error) { +func (dS *DispatcherService) CDRsV2StoreSessionCost(ctx *context.Context, args *engine.ArgsV2CDRSStoreSMCost, reply *string) (err error) { tnt := args.Tenant if tnt == utils.EmptyString { tnt = dS.cfg.GeneralCfg().DefaultTenant diff --git a/dispatchers/cdrs_it_test.go b/dispatchers/cdrs_it_test.go index 86902d571..f6ec363b2 100644 --- a/dispatchers/cdrs_it_test.go +++ b/dispatchers/cdrs_it_test.go @@ -25,6 +25,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -99,12 +100,12 @@ func TestDspCDRsITMySQLWithoutAuth(t *testing.T) { func testDspCDRsPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.CDRsV1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.CDRsV1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.CDRsV1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ utils.OptsAPIKey: "cdrs12345", @@ -141,7 +142,7 @@ func testDspCDRsProcessEvent(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -161,7 +162,7 @@ func testDspCDRsCountCDR(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV1GetCDRsCount, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1GetCDRsCount, args, &reply); err != nil { t.Error(err) } else if reply != 1 { t.Errorf("Received: %+v", reply) @@ -181,7 +182,7 @@ func testDspCDRsGetCDR(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV1GetCDRs, &args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &reply); err != nil { t.Error(err) } else if len(reply) != 1 { t.Errorf("Received: %+v", reply) @@ -202,7 +203,7 @@ func testDspCDRsGetCDRWithoutTenant(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV1GetCDRs, &args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &reply); err != nil { t.Error(err) } else if len(reply) != 1 { t.Errorf("Received: %+v", reply) @@ -230,7 +231,7 @@ func testDspCDRsProcessCDR(t *testing.T) { utils.OptsAPIKey: "cdrs12345", }, } - if err := dispEngine.RPC.Call(utils.CDRsV1ProcessCDR, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1ProcessCDR, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -251,7 +252,7 @@ func testDspCDRsGetCDR2(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV1GetCDRs, &args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &reply); err != nil { t.Error(err) } else if len(reply) != 1 { t.Errorf("Received: %+v", reply) @@ -283,7 +284,7 @@ func testDspCDRsProcessExternalCDR(t *testing.T) { utils.OptsAPIKey: "cdrs12345", }, } - if err := dispEngine.RPC.Call(utils.CDRsV1ProcessExternalCDR, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1ProcessExternalCDR, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -304,7 +305,7 @@ func testDspCDRsGetCDR3(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV1GetCDRs, &args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &reply); err != nil { t.Error(err) } else if len(reply) != 1 { t.Errorf("Received: %+v", reply) @@ -336,7 +337,7 @@ func testDspCDRsV2ProcessEvent(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV2ProcessEvent, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV2ProcessEvent, args, &reply); err != nil { t.Error(err) } else if len(reply) != 2 { for _, procEv := range reply { @@ -374,13 +375,13 @@ func testDspCDRsV2StoreSessionCost(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV2StoreSessionCost, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV2StoreSessionCost, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } time.Sleep(150 * time.Millisecond) - if err := dispEngine.RPC.Call(utils.CDRsV2StoreSessionCost, args, + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV2StoreSessionCost, args, &reply); err == nil || err.Error() != "SERVER_ERROR: EXISTS" { t.Error("Unexpected error: ", err) } @@ -388,12 +389,12 @@ func testDspCDRsV2StoreSessionCost(t *testing.T) { func testDspCDRsPingNoAuth(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.CDRsV1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.CDRsV1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.CDRsV1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1Ping, &utils.CGREvent{ Tenant: "cgrates.org", }, &reply); err != nil { t.Error(err) @@ -423,7 +424,7 @@ func testDspCDRsProcessEventNoAuth(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -440,7 +441,7 @@ func testDspCDRsCountCDRNoAuth(t *testing.T) { Tenant: "cgrates.org", } - if err := dispEngine.RPC.Call(utils.CDRsV1GetCDRsCount, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1GetCDRsCount, args, &reply); err != nil { t.Error(err) } else if reply != 1 { t.Errorf("Received: %+v", reply) @@ -457,7 +458,7 @@ func testDspCDRsGetCDRNoAuth(t *testing.T) { Tenant: "cgrates.org", } - if err := dispEngine.RPC.Call(utils.CDRsV1GetCDRs, &args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &reply); err != nil { t.Error(err) } else if len(reply) != 1 { t.Errorf("Received: %+v", reply) @@ -475,7 +476,7 @@ func testDspCDRsGetCDRNoAuthWithoutTenant(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV1GetCDRs, &args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &reply); err != nil { t.Error(err) } else if len(reply) != 1 { t.Errorf("Received: %+v", reply) @@ -500,7 +501,7 @@ func testDspCDRsProcessCDRNoAuth(t *testing.T) { Usage: 2 * time.Minute, }, } - if err := dispEngine.RPC.Call(utils.CDRsV1ProcessCDR, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1ProcessCDR, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -518,7 +519,7 @@ func testDspCDRsGetCDR2NoAuth(t *testing.T) { Tenant: "cgrates.org", } - if err := dispEngine.RPC.Call(utils.CDRsV1GetCDRs, &args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &reply); err != nil { t.Error(err) } else if len(reply) != 1 { t.Errorf("Received: %+v", reply) @@ -547,7 +548,7 @@ func testDspCDRsProcessExternalCDRNoAuth(t *testing.T) { ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, }, } - if err := dispEngine.RPC.Call(utils.CDRsV1ProcessExternalCDR, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1ProcessExternalCDR, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -565,7 +566,7 @@ func testDspCDRsGetCDR3NoAuth(t *testing.T) { Tenant: "cgrates.org", } - if err := dispEngine.RPC.Call(utils.CDRsV1GetCDRs, &args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &reply); err != nil { t.Error(err) } else if len(reply) != 1 { t.Errorf("Received: %+v", reply) @@ -593,7 +594,7 @@ func testDspCDRsV2ProcessEventNoAuth(t *testing.T) { }, }, } - if err := dispEngine.RPC.Call(utils.CDRsV2ProcessEvent, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV2ProcessEvent, args, &reply); err != nil { t.Error(err) } else if len(reply) != 2 { for _, procEv := range reply { @@ -628,13 +629,13 @@ func testDspCDRsV2StoreSessionCostNoAuth(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.CDRsV2StoreSessionCost, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV2StoreSessionCost, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } time.Sleep(150 * time.Millisecond) - if err := dispEngine.RPC.Call(utils.CDRsV2StoreSessionCost, args, + if err := dispEngine.RPC.Call(context.Background(), utils.CDRsV2StoreSessionCost, args, &reply); err == nil || err.Error() != "SERVER_ERROR: EXISTS" { t.Error("Unexpected error: ", err) } diff --git a/dispatchers/cdrs_test.go b/dispatchers/cdrs_test.go index bf9e4bd6f..04a0f9184 100644 --- a/dispatchers/cdrs_test.go +++ b/dispatchers/cdrs_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -32,7 +33,7 @@ func TestDspCDRsV1PingError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.CGREvent{} var reply *string - result := dspSrv.CDRsV1Ping(CGREvent, reply) + result := dspSrv.CDRsV1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -46,7 +47,7 @@ func TestDspCDRsV1PingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CDRsV1Ping(CGREvent, reply) + result := dspSrv.CDRsV1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -58,7 +59,7 @@ func TestDspCDRsV1PingNilError(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *string - result := dspSrv.CDRsV1Ping(nil, reply) + result := dspSrv.CDRsV1Ping(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -71,7 +72,7 @@ func TestDspCDRsV1GetCDRsError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.RPCCDRsFilterWithAPIOpts{} var reply *[]*engine.CDR - result := dspSrv.CDRsV1GetCDRs(CGREvent, reply) + result := dspSrv.CDRsV1GetCDRs(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -85,7 +86,7 @@ func TestDspCDRsV1GetCDRsNil(t *testing.T) { Tenant: "tenant", } var reply *[]*engine.CDR - result := dspSrv.CDRsV1GetCDRs(CGREvent, reply) + result := dspSrv.CDRsV1GetCDRs(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -98,7 +99,7 @@ func TestDspCDRsV1GetCDRsCountError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.RPCCDRsFilterWithAPIOpts{} var reply *int64 - result := dspSrv.CDRsV1GetCDRsCount(CGREvent, reply) + result := dspSrv.CDRsV1GetCDRsCount(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -112,7 +113,7 @@ func TestDspCDRsV1GetCDRsCountNil(t *testing.T) { Tenant: "tenant", } var reply *int64 - result := dspSrv.CDRsV1GetCDRsCount(CGREvent, reply) + result := dspSrv.CDRsV1GetCDRsCount(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -125,7 +126,7 @@ func TestDspCDRsV1RateCDRsError(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &engine.ArgRateCDRs{} var reply *string - result := dspSrv.CDRsV1RateCDRs(CGREvent, reply) + result := dspSrv.CDRsV1RateCDRs(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -139,7 +140,7 @@ func TestDspCDRsV1RateCDRsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CDRsV1RateCDRs(CGREvent, reply) + result := dspSrv.CDRsV1RateCDRs(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -156,7 +157,7 @@ func TestDspCDRsV1ProcessExternalCDRError(t *testing.T) { }, } var reply *string - result := dspSrv.CDRsV1ProcessExternalCDR(CGREvent, reply) + result := dspSrv.CDRsV1ProcessExternalCDR(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -172,7 +173,7 @@ func TestDspCDRsV1ProcessExternalCDRNil(t *testing.T) { }, } var reply *string - result := dspSrv.CDRsV1ProcessExternalCDR(CGREvent, reply) + result := dspSrv.CDRsV1ProcessExternalCDR(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -189,7 +190,7 @@ func TestDspCDRsV1ProcessEventError(t *testing.T) { }, } var reply *string - result := dspSrv.CDRsV1ProcessEvent(CGREvent, reply) + result := dspSrv.CDRsV1ProcessEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -205,7 +206,7 @@ func TestDspCDRsV1ProcessEventNil(t *testing.T) { }, } var reply *string - result := dspSrv.CDRsV1ProcessEvent(CGREvent, reply) + result := dspSrv.CDRsV1ProcessEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -222,7 +223,7 @@ func TestDspCDRsV1ProcessCDRError(t *testing.T) { }, } var reply *string - result := dspSrv.CDRsV1ProcessCDR(CGREvent, reply) + result := dspSrv.CDRsV1ProcessCDR(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -238,7 +239,7 @@ func TestDspCDRsV1ProcessCDRNil(t *testing.T) { }, } var reply *string - result := dspSrv.CDRsV1ProcessCDR(CGREvent, reply) + result := dspSrv.CDRsV1ProcessCDR(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -256,7 +257,7 @@ func TestDspCDRsV2ProcessEventError(t *testing.T) { }, } var reply *[]*utils.EventWithFlags - result := dspSrv.CDRsV2ProcessEvent(CGREvent, reply) + result := dspSrv.CDRsV2ProcessEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -273,7 +274,7 @@ func TestDspCDRsV2ProcessEventNil(t *testing.T) { }, } var reply *[]*utils.EventWithFlags - result := dspSrv.CDRsV2ProcessEvent(CGREvent, reply) + result := dspSrv.CDRsV2ProcessEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -289,7 +290,7 @@ func TestDspCDRsV2ProcessEventErrorNil(t *testing.T) { CGREvent: utils.CGREvent{}, } var reply *[]*utils.EventWithFlags - result := dspSrv.CDRsV2ProcessEvent(CGREvent, reply) + result := dspSrv.CDRsV2ProcessEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -303,7 +304,7 @@ func TestDspCDRsV1StoreSessionCostNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CDRsV1StoreSessionCost(CGREvent, reply) + result := dspSrv.CDRsV1StoreSessionCost(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -316,7 +317,7 @@ func TestDspCDRsV1StoreSessionCostErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &engine.AttrCDRSStoreSMCost{} var reply *string - result := dspSrv.CDRsV1StoreSessionCost(CGREvent, reply) + result := dspSrv.CDRsV1StoreSessionCost(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -330,7 +331,7 @@ func TestDspCDRsV2StoreSessionCostNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.CDRsV2StoreSessionCost(CGREvent, reply) + result := dspSrv.CDRsV2StoreSessionCost(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -343,7 +344,7 @@ func TestDspCDRsV2StoreSessionCostErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &engine.ArgsV2CDRSStoreSMCost{} var reply *string - result := dspSrv.CDRsV2StoreSessionCost(CGREvent, reply) + result := dspSrv.CDRsV2StoreSessionCost(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/chargers.go b/dispatchers/chargers.go index 65832ecc8..188161798 100644 --- a/dispatchers/chargers.go +++ b/dispatchers/chargers.go @@ -19,11 +19,12 @@ along with this program. If not, see package dispatchers import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) ChargerSv1Ping(args *utils.CGREvent, reply *string) (err error) { +func (dS *DispatcherService) ChargerSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) } @@ -40,7 +41,7 @@ func (dS *DispatcherService) ChargerSv1Ping(args *utils.CGREvent, reply *string) return dS.Dispatch(args, utils.MetaChargers, utils.ChargerSv1Ping, args, reply) } -func (dS *DispatcherService) ChargerSv1GetChargersForEvent(args *utils.CGREvent, +func (dS *DispatcherService) ChargerSv1GetChargersForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.ChargerProfiles) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && args.Tenant != utils.EmptyString { @@ -55,7 +56,7 @@ func (dS *DispatcherService) ChargerSv1GetChargersForEvent(args *utils.CGREvent, return dS.Dispatch(args, utils.MetaChargers, utils.ChargerSv1GetChargersForEvent, args, reply) } -func (dS *DispatcherService) ChargerSv1ProcessEvent(args *utils.CGREvent, +func (dS *DispatcherService) ChargerSv1ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*engine.ChrgSProcessEventReply) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && args.Tenant != utils.EmptyString { diff --git a/dispatchers/chargers_it_test.go b/dispatchers/chargers_it_test.go index 61c2f4f8d..f104347d4 100644 --- a/dispatchers/chargers_it_test.go +++ b/dispatchers/chargers_it_test.go @@ -27,6 +27,7 @@ import ( "strings" "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -70,7 +71,7 @@ func TestDspChargerST(t *testing.T) { func testDspCppPingFailover(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.ChargerSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.ChargerSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -82,19 +83,19 @@ func testDspCppPingFailover(t *testing.T) { utils.OptsAPIKey: "chrg12345", }, } - if err := dispEngine.RPC.Call(utils.ChargerSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ChargerSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine.stopEngine(t) - if err := dispEngine.RPC.Call(utils.ChargerSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ChargerSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.ChargerSv1Ping, &ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ChargerSv1Ping, &ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine.startEngine(t) @@ -128,7 +129,7 @@ func testDspCppGetChtgFailover(t *testing.T) { (*eChargers)[0].FilterIDs = nil // empty slice are nil in gob } var reply *engine.ChargerProfiles - if err := dispEngine.RPC.Call(utils.ChargerSv1GetChargersForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.ChargerSv1GetChargersForEvent, args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eChargers, reply) { @@ -149,7 +150,7 @@ func testDspCppGetChtgFailover(t *testing.T) { if *encoding == utils.MetaGOB { (*eChargers)[1].FilterIDs = nil // empty slice are nil in gob } - if err := dispEngine.RPC.Call(utils.ChargerSv1GetChargersForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.ChargerSv1GetChargersForEvent, args, &reply); err != nil { t.Fatal(err) } @@ -165,12 +166,12 @@ func testDspCppGetChtgFailover(t *testing.T) { func testDspCppPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.ChargerSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.ChargerSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.ChargerSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.ChargerSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ utils.OptsAPIKey: "chrg12345", @@ -194,7 +195,7 @@ func testDspCppTestAuthKey(t *testing.T) { }, } var reply *engine.ChargerProfiles - if err := dispEngine.RPC.Call(utils.ChargerSv1GetChargersForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.ChargerSv1GetChargersForEvent, args, &reply); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() { t.Error(err) } @@ -235,7 +236,7 @@ func testDspCppTestAuthKey2(t *testing.T) { (*eChargers)[1].FilterIDs = nil // empty slice are nil in gob } var reply *engine.ChargerProfiles - if err := dispEngine.RPC.Call(utils.ChargerSv1GetChargersForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.ChargerSv1GetChargersForEvent, args, &reply); err != nil { t.Fatal(err) } @@ -274,7 +275,7 @@ func testDspCppGetChtgRoundRobin(t *testing.T) { } var reply *engine.ChargerProfiles // To ALL2 - if err := dispEngine.RPC.Call(utils.ChargerSv1GetChargersForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.ChargerSv1GetChargersForEvent, args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(eChargers, reply) { @@ -294,7 +295,7 @@ func testDspCppGetChtgRoundRobin(t *testing.T) { if *encoding == utils.MetaGOB { (*eChargers)[1].FilterIDs = nil // empty slice are nil in gob } - if err := dispEngine.RPC.Call(utils.ChargerSv1GetChargersForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.ChargerSv1GetChargersForEvent, args, &reply); err != nil { t.Fatal(err) } diff --git a/dispatchers/chargers_test.go b/dispatchers/chargers_test.go index df43e60e4..a554adadc 100644 --- a/dispatchers/chargers_test.go +++ b/dispatchers/chargers_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -30,7 +31,7 @@ func TestDspChargerSv1PingNilStruct(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ChargerSv1Ping(nil, reply) + result := dspSrv.ChargerSv1Ping(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -44,7 +45,7 @@ func TestDspChargerSv1PingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ChargerSv1Ping(CGREvent, reply) + result := dspSrv.ChargerSv1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -57,7 +58,7 @@ func TestDspChargerSv1PingErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.CGREvent{} var reply *string - result := dspSrv.ChargerSv1Ping(CGREvent, reply) + result := dspSrv.ChargerSv1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -71,7 +72,7 @@ func TestDspChargerSv1GetChargersForEventNil(t *testing.T) { Tenant: "tenant", } var reply *engine.ChargerProfiles - result := dspSrv.ChargerSv1GetChargersForEvent(CGREvent, reply) + result := dspSrv.ChargerSv1GetChargersForEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -84,7 +85,7 @@ func TestDspChargerSv1GetChargersForEventErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.CGREvent{} var reply *engine.ChargerProfiles - result := dspSrv.ChargerSv1GetChargersForEvent(CGREvent, reply) + result := dspSrv.ChargerSv1GetChargersForEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -98,7 +99,7 @@ func TestDspChargerSv1ProcessEventNil(t *testing.T) { Tenant: "tenant", } var reply *[]*engine.ChrgSProcessEventReply - result := dspSrv.ChargerSv1ProcessEvent(CGREvent, reply) + result := dspSrv.ChargerSv1ProcessEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -111,7 +112,7 @@ func TestDspChargerSv1ProcessEventErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.CGREvent{} var reply *[]*engine.ChrgSProcessEventReply - result := dspSrv.ChargerSv1ProcessEvent(CGREvent, reply) + result := dspSrv.ChargerSv1ProcessEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/config.go b/dispatchers/config.go index 5c43198fa..0c8f0346f 100644 --- a/dispatchers/config.go +++ b/dispatchers/config.go @@ -21,11 +21,12 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) ConfigSv1GetConfig(args *config.SectionWithAPIOpts, reply *map[string]any) (err error) { +func (dS *DispatcherService) ConfigSv1GetConfig(ctx *context.Context, args *config.SectionWithAPIOpts, reply *map[string]any) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -42,7 +43,7 @@ func (dS *DispatcherService) ConfigSv1GetConfig(args *config.SectionWithAPIOpts, }, utils.MetaConfig, utils.ConfigSv1GetConfig, args, reply) } -func (dS *DispatcherService) ConfigSv1ReloadConfig(args *config.ReloadArgs, reply *string) (err error) { +func (dS *DispatcherService) ConfigSv1ReloadConfig(ctx *context.Context, args *config.ReloadArgs, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -59,7 +60,7 @@ func (dS *DispatcherService) ConfigSv1ReloadConfig(args *config.ReloadArgs, repl }, utils.MetaConfig, utils.ConfigSv1ReloadConfig, args, reply) } -func (dS *DispatcherService) ConfigSv1SetConfig(args *config.SetConfigArgs, reply *string) (err error) { +func (dS *DispatcherService) ConfigSv1SetConfig(ctx *context.Context, args *config.SetConfigArgs, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -76,7 +77,7 @@ func (dS *DispatcherService) ConfigSv1SetConfig(args *config.SetConfigArgs, repl }, utils.MetaConfig, utils.ConfigSv1SetConfig, args, reply) } -func (dS *DispatcherService) ConfigSv1SetConfigFromJSON(args *config.SetConfigFromJSONArgs, reply *string) (err error) { +func (dS *DispatcherService) ConfigSv1SetConfigFromJSON(ctx *context.Context, args *config.SetConfigFromJSONArgs, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -93,7 +94,7 @@ func (dS *DispatcherService) ConfigSv1SetConfigFromJSON(args *config.SetConfigFr }, utils.MetaConfig, utils.ConfigSv1SetConfigFromJSON, args, reply) } -func (dS *DispatcherService) ConfigSv1GetConfigAsJSON(args *config.SectionWithAPIOpts, reply *string) (err error) { +func (dS *DispatcherService) ConfigSv1GetConfigAsJSON(ctx *context.Context, args *config.SectionWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant diff --git a/dispatchers/config_it_test.go b/dispatchers/config_it_test.go index 30c50a463..39e67661d 100644 --- a/dispatchers/config_it_test.go +++ b/dispatchers/config_it_test.go @@ -25,6 +25,7 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -73,7 +74,7 @@ func testDspConfigSv1GetJSONSection(t *testing.T) { "listen": expected, } var reply map[string]any - if err := dispEngine.RPC.Call(utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", APIOpts: map[string]any{ utils.OptsAPIKey: "cfg12345", diff --git a/dispatchers/config_test.go b/dispatchers/config_test.go index 45e23d505..ccb8b424e 100644 --- a/dispatchers/config_test.go +++ b/dispatchers/config_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" ) @@ -31,7 +32,7 @@ func TestDspConfigSv1GetConfigNil(t *testing.T) { Tenant: "tenant", } var reply *map[string]any - result := dspSrv.ConfigSv1GetConfig(CGREvent, reply) + result := dspSrv.ConfigSv1GetConfig(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -44,7 +45,7 @@ func TestDspConfigSv1GetConfigErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &config.SectionWithAPIOpts{} var reply *map[string]any - result := dspSrv.ConfigSv1GetConfig(CGREvent, reply) + result := dspSrv.ConfigSv1GetConfig(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -58,7 +59,7 @@ func TestDspConfigSv1ReloadConfigNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ConfigSv1ReloadConfig(CGREvent, reply) + result := dspSrv.ConfigSv1ReloadConfig(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -71,7 +72,7 @@ func TestDspConfigSv1ReloadConfigErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &config.ReloadArgs{} var reply *string - result := dspSrv.ConfigSv1ReloadConfig(CGREvent, reply) + result := dspSrv.ConfigSv1ReloadConfig(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -85,7 +86,7 @@ func TestDspConfigSv1SetConfigNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ConfigSv1SetConfig(CGREvent, reply) + result := dspSrv.ConfigSv1SetConfig(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -98,7 +99,7 @@ func TestDspConfigSv1SetConfigErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &config.SetConfigArgs{} var reply *string - result := dspSrv.ConfigSv1SetConfig(CGREvent, reply) + result := dspSrv.ConfigSv1SetConfig(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -112,7 +113,7 @@ func TestDspConfigSv1SetConfigFromJSONNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ConfigSv1SetConfigFromJSON(CGREvent, reply) + result := dspSrv.ConfigSv1SetConfigFromJSON(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -125,7 +126,7 @@ func TestDspConfigSv1SetConfigFromJSONErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &config.SetConfigFromJSONArgs{} var reply *string - result := dspSrv.ConfigSv1SetConfigFromJSON(CGREvent, reply) + result := dspSrv.ConfigSv1SetConfigFromJSON(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -139,7 +140,7 @@ func TestDspConfigSv1GetConfigAsJSONNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ConfigSv1GetConfigAsJSON(CGREvent, reply) + result := dspSrv.ConfigSv1GetConfigAsJSON(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -152,7 +153,7 @@ func TestDspConfigSv1GetConfigAsJSONErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &config.SectionWithAPIOpts{} var reply *string - result := dspSrv.ConfigSv1GetConfigAsJSON(CGREvent, reply) + result := dspSrv.ConfigSv1GetConfigAsJSON(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/cores.go b/dispatchers/cores.go index feaea8ff4..e38cf0c9b 100644 --- a/dispatchers/cores.go +++ b/dispatchers/cores.go @@ -21,10 +21,11 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) CoreSv1Panic(args *utils.PanicMessageArgs, reply *string) (err error) { +func (dS *DispatcherService) CoreSv1Panic(ctx *context.Context, args *utils.PanicMessageArgs, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant @@ -42,7 +43,7 @@ func (dS *DispatcherService) CoreSv1Panic(args *utils.PanicMessageArgs, reply *s } return dS.Dispatch(&utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.MetaCore, utils.CoreSv1Panic, args, reply) } -func (dS *DispatcherService) CoreSv1Ping(args *utils.CGREvent, reply *string) (err error) { +func (dS *DispatcherService) CoreSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant @@ -64,7 +65,7 @@ func (dS *DispatcherService) CoreSv1Ping(args *utils.CGREvent, reply *string) (e return dS.Dispatch(&utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.MetaCore, utils.CoreSv1Ping, args, reply) } -func (dS *DispatcherService) CoreSv1Sleep(args *utils.DurationArgs, reply *string) (err error) { +func (dS *DispatcherService) CoreSv1Sleep(ctx *context.Context, args *utils.DurationArgs, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant @@ -83,7 +84,7 @@ func (dS *DispatcherService) CoreSv1Sleep(args *utils.DurationArgs, reply *strin return dS.Dispatch(&utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.MetaCore, utils.CoreSv1Sleep, args, reply) } -func (dS *DispatcherService) CoreSv1StartCPUProfiling(args *utils.DirectoryArgs, reply *string) (err error) { +func (dS *DispatcherService) CoreSv1StartCPUProfiling(ctx *context.Context, args *utils.DirectoryArgs, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant @@ -101,7 +102,7 @@ func (dS *DispatcherService) CoreSv1StartCPUProfiling(args *utils.DirectoryArgs, } return dS.Dispatch(&utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.MetaCore, utils.CoreSv1StartCPUProfiling, args, reply) } -func (dS *DispatcherService) CoreSv1StartMemoryProfiling(args *utils.MemoryPrf, reply *string) (err error) { +func (dS *DispatcherService) CoreSv1StartMemoryProfiling(ctx *context.Context, args *utils.MemoryPrf, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant @@ -119,7 +120,7 @@ func (dS *DispatcherService) CoreSv1StartMemoryProfiling(args *utils.MemoryPrf, } return dS.Dispatch(&utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.MetaCore, utils.CoreSv1StartMemoryProfiling, args, reply) } -func (dS *DispatcherService) CoreSv1Status(args *utils.TenantWithAPIOpts, reply *map[string]any) (err error) { +func (dS *DispatcherService) CoreSv1Status(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *map[string]any) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant @@ -137,7 +138,7 @@ func (dS *DispatcherService) CoreSv1Status(args *utils.TenantWithAPIOpts, reply } return dS.Dispatch(&utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.MetaCore, utils.CoreSv1Status, args, reply) } -func (dS *DispatcherService) CoreSv1StopCPUProfiling(args *utils.TenantWithAPIOpts, reply *string) (err error) { +func (dS *DispatcherService) CoreSv1StopCPUProfiling(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant @@ -155,7 +156,7 @@ func (dS *DispatcherService) CoreSv1StopCPUProfiling(args *utils.TenantWithAPIOp } return dS.Dispatch(&utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.MetaCore, utils.CoreSv1StopCPUProfiling, args, reply) } -func (dS *DispatcherService) CoreSv1StopMemoryProfiling(args *utils.TenantWithAPIOpts, reply *string) (err error) { +func (dS *DispatcherService) CoreSv1StopMemoryProfiling(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant diff --git a/dispatchers/dispatchers.go b/dispatchers/dispatchers.go index e699599a4..d41390c83 100644 --- a/dispatchers/dispatchers.go +++ b/dispatchers/dispatchers.go @@ -24,6 +24,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/guardian" @@ -61,7 +62,7 @@ func (dS *DispatcherService) Shutdown() { func (dS *DispatcherService) authorizeEvent(ev *utils.CGREvent, reply *engine.AttrSProcessEventReply) (err error) { ev.APIOpts[utils.OptsContext] = utils.MetaAuth - if err = dS.connMgr.Call(dS.cfg.DispatcherSCfg().AttributeSConns, nil, + if err = dS.connMgr.Call(context.TODO(), dS.cfg.DispatcherSCfg().AttributeSConns, utils.AttributeSv1ProcessEvent, ev, reply); err != nil { if err.Error() == utils.ErrNotFound.Error() { err = utils.ErrUnknownApiKey @@ -311,7 +312,7 @@ func (dS *DispatcherService) Dispatch(ev *utils.CGREvent, subsys string, return // return the last error } -func (dS *DispatcherService) V1GetProfilesForEvent(ev *utils.CGREvent, +func (dS *DispatcherService) DispatcherSv1GetProfilesForEvent(ctx *context.Context, ev *utils.CGREvent, dPfl *engine.DispatcherProfiles) (err error) { tnt := ev.Tenant if tnt == utils.EmptyString { @@ -333,7 +334,7 @@ func (dS *DispatcherService) V1GetProfilesForEvent(ev *utils.CGREvent, /* // V1Apier is a generic way to cover all APIer methods -func (dS *DispatcherService) V1Apier(apier any, args *utils.MethodParameters, reply *any) (err error) { +func (dS *DispatcherService) V1Apier(ctx *context.Context,apier any, args *utils.MethodParameters, reply *any) (err error) { parameters, canCast := args.Parameters.(map[string]any) if !canCast { @@ -426,8 +427,8 @@ func (dS *DispatcherService) V1Apier(apier any, args *utils.MethodParameters, re } */ -// Call implements rpcclient.ClientConnector interface for internal RPC -func (dS *DispatcherService) Call(serviceMethod string, // all API fuction must be of type: SubsystemMethod +// Call implements birpc.ClientConnector interface for internal RPC +func (dS *DispatcherService) Call(ctx *context.Context, serviceMethod string, // all API fuction must be of type: SubsystemMethod args any, reply any) error { methodSplit := strings.Split(serviceMethod, ".") if len(methodSplit) != 2 { @@ -452,7 +453,7 @@ func (dS *DispatcherService) Call(serviceMethod string, // all API fuction must return err } -func (dS *DispatcherService) DispatcherSv1RemoteStatus(args *utils.TenantWithAPIOpts, +func (dS *DispatcherService) DispatcherSv1RemoteStatus(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *map[string]any) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -470,7 +471,7 @@ func (dS *DispatcherService) DispatcherSv1RemoteStatus(args *utils.TenantWithAPI }, utils.MetaCore, utils.CoreSv1Status, args, reply) } -func (dS *DispatcherService) DispatcherSv1RemoteSleep(args *utils.DurationArgs, reply *string) (err error) { +func (dS *DispatcherService) DispatcherSv1RemoteSleep(ctx *context.Context, args *utils.DurationArgs, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -487,7 +488,7 @@ func (dS *DispatcherService) DispatcherSv1RemoteSleep(args *utils.DurationArgs, }, utils.MetaCore, utils.CoreSv1Sleep, args, reply) } -func (dS *DispatcherService) DispatcherSv1RemotePing(args *utils.CGREvent, reply *string) (err error) { +func (dS *DispatcherService) DispatcherSv1RemotePing(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && args.Tenant != utils.EmptyString { tnt = args.Tenant diff --git a/dispatchers/dispatchers_it_test.go b/dispatchers/dispatchers_it_test.go index 585c7eece..c96a5a15e 100644 --- a/dispatchers/dispatchers_it_test.go +++ b/dispatchers/dispatchers_it_test.go @@ -25,10 +25,10 @@ import ( "testing" "time" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // for the moment we dispable Apier through dispatcher @@ -79,7 +79,7 @@ func testDspApierSetAttributes(t *testing.T) { } var result string - if err := dispEngine.RPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf, &result); err != nil { + if err := dispEngine.RPC.Call(context.Background(),utils.APIerSv1SetAttributeProfile, attrPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -110,7 +110,7 @@ func testDspApierGetAttributes(t *testing.T) { Weight: 10, } alsPrf.Compile() - if err := dispEngine.RPC.Call(utils.APIerSv1GetAttributeProfile, + if err := dispEngine.RPC.Call(context.Background(),utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_Dispatcher"}, APIOpts: map[string]any{ @@ -128,7 +128,7 @@ func testDspApierGetAttributes(t *testing.T) { func testDspApierUnkownAPiKey(t *testing.T) { var reply *engine.AttributeProfile - if err := dispEngine.RPC.Call(utils.APIerSv1GetAttributeProfile, + if err := dispEngine.RPC.Call(context.Background(),utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_Dispatcher"}, APIOpts: map[string]any{ @@ -144,7 +144,7 @@ func testDspApierUnkownAPiKey(t *testing.T) { func TestDispatcherServiceDispatcherProfileForEventGetDispatchertWithoutAuthentification(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dm := engine.NewDataManager(&engine.DataDBMock{ GetKeysForPrefixF: func(string) ([]string, error) { diff --git a/dispatchers/dispatchers_test.go b/dispatchers/dispatchers_test.go index 9dbd37bd9..715dae2ae 100644 --- a/dispatchers/dispatchers_test.go +++ b/dispatchers/dispatchers_test.go @@ -23,6 +23,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -33,7 +35,7 @@ import ( func TestDispatcherServiceDispatcherProfileForEventGetDispatcherProfileNF(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dm := engine.NewDataManager(&engine.DataDBMock{ GetKeysForPrefixF: func(string) ([]string, error) { @@ -97,7 +99,7 @@ func TestDispatcherServiceDispatcherProfileForEventGetDispatcherProfileNF(t *tes func TestDispatcherServiceDispatcherProfileForEventMIIDENotFound(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -122,7 +124,7 @@ func (dS *DispatcherService) DispatcherServicePing(ev *utils.CGREvent, reply *st func TestDispatcherCall1(t *testing.T) { dS := &DispatcherService{} var reply string - if err := dS.Call(utils.DispatcherServicePing, &utils.CGREvent{}, &reply); err != nil { + if err := dS.Call(context.Background(), utils.DispatcherServicePing, &utils.CGREvent{}, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Expected: %s , received: %s", utils.Pong, reply) @@ -132,10 +134,10 @@ func TestDispatcherCall1(t *testing.T) { func TestDispatcherCall2(t *testing.T) { dS := &DispatcherService{} var reply string - if err := dS.Call("DispatcherServicePing", &utils.CGREvent{}, &reply); err == nil || err.Error() != rpcclient.ErrUnsupporteServiceMethod.Error() { + if err := dS.Call(context.Background(), "DispatcherServicePing", &utils.CGREvent{}, &reply); err == nil || err.Error() != rpcclient.ErrUnsupporteServiceMethod.Error() { t.Error(err) } - if err := dS.Call("DispatcherService.Pong", &utils.CGREvent{}, &reply); err == nil || err.Error() != rpcclient.ErrUnsupporteServiceMethod.Error() { + if err := dS.Call(context.Background(), "DispatcherService.Pong", &utils.CGREvent{}, &reply); err == nil || err.Error() != rpcclient.ErrUnsupporteServiceMethod.Error() { t.Error(err) } dS.Shutdown() @@ -181,7 +183,7 @@ func TestDispatcherV1GetProfileForEventErr(t *testing.T) { dsp := NewDispatcherService(nil, cfg, nil, nil) ev := &utils.CGREvent{} dPfl := &engine.DispatcherProfiles{} - err := dsp.V1GetProfilesForEvent(ev, dPfl) + err := dsp.DispatcherSv1GetProfilesForEvent(context.Background(), ev, dPfl) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -194,7 +196,7 @@ func TestDispatcherV1GetProfileForEvent(t *testing.T) { dsp := NewDispatcherService(nil, cfg, nil, nil) ev := &utils.CGREvent{} dPfl := &engine.DispatcherProfiles{} - err := dsp.V1GetProfilesForEvent(ev, dPfl) + err := dsp.DispatcherSv1GetProfilesForEvent(context.Background(), ev, dPfl) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -320,7 +322,7 @@ func TestDispatcherServiceAuthorizeEventError2(t *testing.T) { type mockTypeCon2 struct{} -func (*mockTypeCon2) Call(serviceMethod string, args, reply any) error { +func (*mockTypeCon2) Call(ctx *context.Context, serviceMethod string, args, reply any) error { return nil } @@ -329,9 +331,9 @@ func TestDispatcherServiceAuthorizeEventError3(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().AttributeSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} dm := engine.NewDataManager(nil, nil, nil) - chanRPC := make(chan rpcclient.ClientConnector, 1) + chanRPC := make(chan birpc.ClientConnector, 1) chanRPC <- new(mockTypeCon2) - rpcInt := map[string]chan rpcclient.ClientConnector{ + rpcInt := map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanRPC, } connMgr := engine.NewConnManager(cfg, rpcInt) @@ -367,7 +369,7 @@ func TestDispatcherServiceAuthorizeEventError3(t *testing.T) { type mockTypeCon3 struct{} -func (*mockTypeCon3) Call(serviceMethod string, args, reply any) error { +func (*mockTypeCon3) Call(_ *context.Context, serviceMethod string, args, reply any) error { eVreply := &engine.AttrSProcessEventReply{ CGREvent: &utils.CGREvent{ Tenant: "testTenant", @@ -388,9 +390,9 @@ func TestDispatcherServiceAuthorizeError(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().AttributeSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} dm := engine.NewDataManager(nil, nil, nil) - chanRPC := make(chan rpcclient.ClientConnector, 1) + chanRPC := make(chan birpc.ClientConnector, 1) chanRPC <- new(mockTypeCon3) - rpcInt := map[string]chan rpcclient.ClientConnector{ + rpcInt := map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanRPC, } connMgr := engine.NewConnManager(cfg, rpcInt) @@ -419,7 +421,7 @@ func TestDispatcherServiceAuthorizeError(t *testing.T) { type mockTypeCon4 struct{} -func (*mockTypeCon4) Call(serviceMethod string, args, reply any) error { +func (*mockTypeCon4) Call(ctx *context.Context, serviceMethod string, args, reply any) error { eVreply := &engine.AttrSProcessEventReply{ CGREvent: &utils.CGREvent{ Tenant: "testTenant", @@ -438,9 +440,9 @@ func TestDispatcherServiceAuthorizeError2(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().AttributeSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} dm := engine.NewDataManager(nil, nil, nil) - chanRPC := make(chan rpcclient.ClientConnector, 1) + chanRPC := make(chan birpc.ClientConnector, 1) chanRPC <- new(mockTypeCon4) - rpcInt := map[string]chan rpcclient.ClientConnector{ + rpcInt := map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanRPC, } connMgr := engine.NewConnManager(cfg, rpcInt) @@ -469,7 +471,7 @@ func TestDispatcherServiceAuthorizeError2(t *testing.T) { type mockTypeCon5 struct{} -func (*mockTypeCon5) Call(serviceMethod string, args, reply any) error { +func (*mockTypeCon5) Call(ctx *context.Context, serviceMethod string, args, reply any) error { eVreply := &engine.AttrSProcessEventReply{ CGREvent: &utils.CGREvent{ Tenant: "testTenant", @@ -490,9 +492,9 @@ func TestDispatcherServiceAuthorizeError3(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().AttributeSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} dm := engine.NewDataManager(nil, nil, nil) - chanRPC := make(chan rpcclient.ClientConnector, 1) + chanRPC := make(chan birpc.ClientConnector, 1) chanRPC <- new(mockTypeCon5) - rpcInt := map[string]chan rpcclient.ClientConnector{ + rpcInt := map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanRPC, } connMgr := engine.NewConnManager(cfg, rpcInt) @@ -520,7 +522,7 @@ func TestDispatcherServiceAuthorizeError3(t *testing.T) { func TestDispatcherServiceCall1(t *testing.T) { cfg := config.NewDefaultCGRConfig() - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dm := engine.NewDataManager(nil, nil, nil) dsp := NewDispatcherService(dm, cfg, nil, connMng) @@ -534,7 +536,7 @@ func TestDispatcherServiceCall1(t *testing.T) { }, APIOpts: nil, } - err := dsp.Call(utils.DispatcherServicePing, args, &reply) + err := dsp.Call(context.Background(), utils.DispatcherServicePing, args, &reply) if err != nil { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err) } @@ -543,7 +545,7 @@ func TestDispatcherServiceCall1(t *testing.T) { func TestDispatcherServiceDispatcherProfileForEventErrNil(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -590,7 +592,7 @@ func TestDispatcherServiceDispatcherProfileForEventErrNil(t *testing.T) { func TestDispatcherV1GetProfileForEventReturn(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -633,7 +635,7 @@ func TestDispatcherV1GetProfileForEventReturn(t *testing.T) { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err) } dPfl := &engine.DispatcherProfiles{} - err = dss.V1GetProfilesForEvent(ev, dPfl) + err = dss.DispatcherSv1GetProfilesForEvent(context.Background(), ev, dPfl) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if err != nil { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -643,7 +645,7 @@ func TestDispatcherV1GetProfileForEventReturn(t *testing.T) { func TestDispatcherServiceDispatcherProfileForEventErrNotFound(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -690,7 +692,7 @@ func TestDispatcherServiceDispatcherProfileForEventErrNotFound(t *testing.T) { func TestDispatcherServiceDispatcherProfileForEventErrNotFound2(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -737,7 +739,7 @@ func TestDispatcherServiceDispatcherProfileForEventErrNotFound2(t *testing.T) { func TestDispatcherServiceDispatcherProfileForEventErrNotFoundTime(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -789,7 +791,7 @@ func TestDispatcherServiceDispatcherProfileForEventErrNotFoundTime(t *testing.T) func TestDispatcherServiceDispatcherProfileForEventErrNotFoundFilter(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -837,7 +839,7 @@ func TestDispatcherServiceDispatcherProfileForEventErrNotFoundFilter(t *testing. func TestDispatcherServiceDispatchDspErr(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) engine.Cache.Clear(nil) @@ -883,7 +885,7 @@ func TestDispatcherServiceDispatchDspErrHostNotFound(t *testing.T) { cacheInit := engine.Cache cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -936,7 +938,7 @@ func TestDispatcherServiceDispatchDspErrHostNotFound(t *testing.T) { func TestDispatcherServiceDispatcherProfileForEventFoundFilter(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -997,7 +999,7 @@ func TestDispatcherServiceDispatcherProfileForEventFoundFilter(t *testing.T) { func TestDispatcherServiceDispatcherProfileForEventNotNotFound(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = true - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) var cnt int @@ -1041,7 +1043,7 @@ func TestDispatcherServiceDispatcherProfileForEventNotNotFound(t *testing.T) { func TestDispatcherServiceDispatcherProfileForEventGetDispatcherError(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -1103,7 +1105,7 @@ func TestDispatcherServiceDispatchDspErrHostNotFound2(t *testing.T) { cacheInit := engine.Cache cfg := config.NewDefaultCGRConfig() cfg.DispatcherSCfg().IndexedSelects = false - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dataDB := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(dataDB, nil, connMng) @@ -1155,7 +1157,7 @@ func TestDispatcherServiceDispatchDspErrHostNotFound2(t *testing.T) { type mockTypeConSetCache struct{} -func (*mockTypeConSetCache) Call(serviceMethod string, args, reply any) error { +func (*mockTypeConSetCache) Call(ctx *context.Context, serviceMethod string, args, reply any) error { return utils.ErrNotImplemented } @@ -1167,9 +1169,9 @@ func TestDispatcherServiceDispatchDspErrHostNotFound3(t *testing.T) { Replicate: true, } cfg.DispatcherSCfg().IndexedSelects = false - chanRPC := make(chan rpcclient.ClientConnector, 1) + chanRPC := make(chan birpc.ClientConnector, 1) chanRPC <- new(mockTypeConSetCache) - rpcInt := map[string]chan rpcclient.ClientConnector{ + rpcInt := map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): chanRPC, } connMgr := engine.NewConnManager(cfg, rpcInt) @@ -1223,7 +1225,7 @@ func (dS *DispatcherService) DispatcherServiceTest(ev *utils.CGREvent, reply *st func TestDispatcherServiceCall2(t *testing.T) { cfg := config.NewDefaultCGRConfig() - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dm := engine.NewDataManager(nil, nil, nil) dsp := NewDispatcherService(dm, cfg, nil, connMng) @@ -1241,7 +1243,7 @@ func TestDispatcherServiceCall2(t *testing.T) { utils.MetaSubsys: utils.MetaDispatchers, }, } - err := dsp.Call("DispatcherService.Test", args, &reply) + err := dsp.Call(context.Background(), "DispatcherService.Test", args, &reply) expected := "SERVER_ERROR" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -1255,7 +1257,7 @@ func (dS *DispatcherService) DispatcherServiceTest2(ev *utils.CGREvent, reply *s func TestDispatcherServiceCall3(t *testing.T) { cfg := config.NewDefaultCGRConfig() - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dm := engine.NewDataManager(nil, nil, nil) dsp := NewDispatcherService(dm, cfg, nil, connMng) @@ -1273,7 +1275,7 @@ func TestDispatcherServiceCall3(t *testing.T) { utils.MetaSubsys: utils.MetaDispatchers, }, } - err := dsp.Call("DispatcherService.Test2", args, &reply) + err := dsp.Call(context.Background(), "DispatcherService.Test2", args, &reply) expected := utils.ErrNotImplemented if err == nil || err != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) @@ -1287,7 +1289,7 @@ func (dS *DispatcherService) DispatcherServiceTest3(ev *utils.CGREvent, reply *s func TestDispatcherServiceCall4(t *testing.T) { cfg := config.NewDefaultCGRConfig() - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dm := engine.NewDataManager(nil, nil, nil) dsp := NewDispatcherService(dm, cfg, nil, connMng) @@ -1305,7 +1307,7 @@ func TestDispatcherServiceCall4(t *testing.T) { utils.MetaSubsys: utils.MetaDispatchers, }, } - err := dsp.Call("DispatcherService.Test3", args, &reply) + err := dsp.Call(context.Background(), "DispatcherService.Test3", args, &reply) expected := "SERVER_ERROR" if err == nil || err.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, err) diff --git a/dispatchers/ees.go b/dispatchers/ees.go index 875fd942b..fd81ecf33 100644 --- a/dispatchers/ees.go +++ b/dispatchers/ees.go @@ -21,11 +21,12 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) EeSv1Ping(args *utils.CGREvent, reply *string) (err error) { +func (dS *DispatcherService) EeSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant @@ -47,7 +48,7 @@ func (dS *DispatcherService) EeSv1Ping(args *utils.CGREvent, reply *string) (err return dS.Dispatch(&utils.CGREvent{Tenant: tnt, Event: ev, APIOpts: opts}, utils.MetaCore, utils.EeSv1Ping, args, reply) } -func (dS *DispatcherService) EeSv1ProcessEvent(args *engine.CGREventWithEeIDs, reply *map[string]map[string]any) (err error) { +func (dS *DispatcherService) EeSv1ProcessEvent(ctx *context.Context, args *engine.CGREventWithEeIDs, reply *map[string]map[string]any) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && len(args.Tenant) != 0 { tnt = args.Tenant diff --git a/dispatchers/ees_it_test.go b/dispatchers/ees_it_test.go index 3a27196fd..527f257d5 100644 --- a/dispatchers/ees_it_test.go +++ b/dispatchers/ees_it_test.go @@ -24,6 +24,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -66,7 +67,7 @@ func TestDspEEsIT(t *testing.T) { func testDspEEsPingFailover(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.EeSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.EeSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Unexpected reply: %s", reply) @@ -77,19 +78,19 @@ func testDspEEsPingFailover(t *testing.T) { utils.OptsAPIKey: "ees12345", }, } - if err := dispEngine.RPC.Call(utils.EeSv1Ping, ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.EeSv1Ping, ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Unexpected reply: %s", reply) } allEngine.stopEngine(t) - if err := dispEngine.RPC.Call(utils.EeSv1Ping, ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.EeSv1Ping, ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Unexpected reply: %s", reply) } allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.EeSv1Ping, ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.EeSv1Ping, ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine.startEngine(t) @@ -112,13 +113,13 @@ func testDspEEsProcessEventFailover(t *testing.T) { }, } var reply map[string]map[string]any - if err := dispEngine.RPC.Call(utils.EeSv1ProcessEvent, args, &reply); err == nil || + if err := dispEngine.RPC.Call(context.Background(), utils.EeSv1ProcessEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.EeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.EeSv1ProcessEvent, args, &reply); err != nil { t.Fatal(err) } @@ -127,12 +128,12 @@ func testDspEEsProcessEventFailover(t *testing.T) { func testDspEEsPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.EeSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.EeSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.EeSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.EeSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ utils.OptsAPIKey: "ees12345", @@ -158,7 +159,7 @@ func testDspEEsTestAuthKey(t *testing.T) { }, } var reply map[string]map[string]any - if err := dispEngine.RPC.Call(utils.EeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.EeSv1ProcessEvent, args, &reply); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() { t.Errorf("expected: <%+v>,\nreceived: <%+v>", utils.ErrUnauthorizedApi.Error(), err) } @@ -178,7 +179,7 @@ func testDspEEsTestAuthKey2(t *testing.T) { }, } var reply map[string]map[string]any - if err := dispEngine.RPC.Call(utils.EeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.EeSv1ProcessEvent, args, &reply); err != nil { t.Error(err) } else if _, ok := reply[utils.MetaDefault]; !ok { @@ -202,12 +203,12 @@ func testDspEEsProcessEventRoundRobin(t *testing.T) { } var reply map[string]map[string]any // To ALL2 - if err := dispEngine.RPC.Call(utils.EeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.EeSv1ProcessEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } // To ALL - if err := dispEngine.RPC.Call(utils.EeSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.EeSv1ProcessEvent, args, &reply); err != nil { t.Error(err) } else if _, ok := reply[utils.MetaDefault]; !ok { diff --git a/dispatchers/guardian.go b/dispatchers/guardian.go index ae23cc002..e18f577c2 100644 --- a/dispatchers/guardian.go +++ b/dispatchers/guardian.go @@ -21,11 +21,12 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // GuardianSv1Ping interogates GuardianSv1 server responsible to process the event -func (dS *DispatcherService) GuardianSv1Ping(args *utils.CGREvent, +func (dS *DispatcherService) GuardianSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) @@ -41,7 +42,7 @@ func (dS *DispatcherService) GuardianSv1Ping(args *utils.CGREvent, } // GuardianSv1RemoteLock will lock a key from remote -func (dS *DispatcherService) GuardianSv1RemoteLock(args AttrRemoteLockWithAPIOpts, +func (dS *DispatcherService) GuardianSv1RemoteLock(ctx *context.Context, args AttrRemoteLockWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -60,7 +61,7 @@ func (dS *DispatcherService) GuardianSv1RemoteLock(args AttrRemoteLockWithAPIOpt } // GuardianSv1RemoteUnlock will unlock a key from remote based on reference ID -func (dS *DispatcherService) GuardianSv1RemoteUnlock(args AttrRemoteUnlockWithAPIOpts, +func (dS *DispatcherService) GuardianSv1RemoteUnlock(ctx *context.Context, args AttrRemoteUnlockWithAPIOpts, reply *[]string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { diff --git a/dispatchers/guardian_it_test.go b/dispatchers/guardian_it_test.go index c3d222ae5..6d616699b 100644 --- a/dispatchers/guardian_it_test.go +++ b/dispatchers/guardian_it_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) @@ -63,12 +64,12 @@ func TestDspGuardianST(t *testing.T) { func testDspGrdPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.GuardianSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.GuardianSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.GuardianSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.GuardianSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ @@ -89,7 +90,7 @@ func testDspGrdLock(t *testing.T) { Timeout: 500 * time.Millisecond, } var reply string - if err := dispEngine.RPC.Call(utils.GuardianSv1RemoteLock, &AttrRemoteLockWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.GuardianSv1RemoteLock, &AttrRemoteLockWithAPIOpts{ AttrRemoteLock: args, Tenant: "cgrates.org", APIOpts: map[string]any{ @@ -100,7 +101,7 @@ func testDspGrdLock(t *testing.T) { } var unlockReply []string - if err := dispEngine.RPC.Call(utils.GuardianSv1RemoteUnlock, &AttrRemoteUnlockWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.GuardianSv1RemoteUnlock, &AttrRemoteUnlockWithAPIOpts{ RefID: reply, Tenant: "cgrates.org", APIOpts: map[string]any{ diff --git a/dispatchers/guardian_test.go b/dispatchers/guardian_test.go index 0025a7767..0686d0943 100644 --- a/dispatchers/guardian_test.go +++ b/dispatchers/guardian_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -35,7 +36,7 @@ func TestGuardianGuardianSv1PingErr1(t *testing.T) { var reply *string expected := "MANDATORY_IE_MISSING: [ApiKey]" - result := dspSrv.GuardianSv1Ping(CGREvent, reply) + result := dspSrv.GuardianSv1Ping(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -51,7 +52,7 @@ func TestGuardianGuardianSv1PingErr2(t *testing.T) { var reply *string expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" - result := dspSrv.GuardianSv1Ping(CGREvent, reply) + result := dspSrv.GuardianSv1Ping(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -65,7 +66,7 @@ func TestGuardianGuardianSv1PingErrNil(t *testing.T) { var reply *string expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" - result := dspSrv.GuardianSv1Ping(CGREvent, reply) + result := dspSrv.GuardianSv1Ping(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -82,7 +83,7 @@ func TestGuardianGuardianSv1RemoteLockErr1(t *testing.T) { var reply *string expected := "MANDATORY_IE_MISSING: [ApiKey]" - result := dspSrv.GuardianSv1RemoteLock(CGREvent, reply) + result := dspSrv.GuardianSv1RemoteLock(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -98,7 +99,7 @@ func TestGuardianGuardianSv1RemoteLockErr2(t *testing.T) { var reply *string expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" - result := dspSrv.GuardianSv1RemoteLock(CGREvent, reply) + result := dspSrv.GuardianSv1RemoteLock(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -115,7 +116,7 @@ func TestGuardianGuardianSv1RemoteUnlockErr1(t *testing.T) { var reply *[]string expected := "MANDATORY_IE_MISSING: [ApiKey]" - result := dspSrv.GuardianSv1RemoteUnlock(CGREvent, reply) + result := dspSrv.GuardianSv1RemoteUnlock(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -131,7 +132,7 @@ func TestGuardianGuardianSv1RemoteUnlockErr2(t *testing.T) { var reply *[]string expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" - result := dspSrv.GuardianSv1RemoteUnlock(CGREvent, reply) + result := dspSrv.GuardianSv1RemoteUnlock(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/lib_test.go b/dispatchers/lib_test.go index 71636316f..7b71189d4 100644 --- a/dispatchers/lib_test.go +++ b/dispatchers/lib_test.go @@ -21,14 +21,15 @@ package dispatchers import ( "errors" "flag" - "net/rpc" - "net/rpc/jsonrpc" "os/exec" "path" "strconv" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -46,12 +47,12 @@ var ( dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } @@ -60,7 +61,7 @@ func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { type testDispatcher struct { CfgPath string Cfg *config.CGRConfig - RPC *rpc.Client + RPC *birpc.Client cmd *exec.Cmd } @@ -121,7 +122,7 @@ func (d *testDispatcher) resetStorDb(t *testing.T) { func (d *testDispatcher) loadData(t *testing.T, path string) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path} - if err := d.RPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := d.RPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Errorf("<%s>Error at loading data from folder :%v", d.CfgPath, err) } } diff --git a/dispatchers/libdispatcher.go b/dispatchers/libdispatcher.go index 6aabb14b2..d30fcdb85 100644 --- a/dispatchers/libdispatcher.go +++ b/dispatchers/libdispatcher.go @@ -26,6 +26,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -287,7 +288,7 @@ func (b *broadcastDispatcher) Dispatch(dm *engine.DataManager, flts *engine.Filt if !hasHosts { // in case we do not match any host return utils.ErrDSPHostNotFound } - return pool.Call(serviceMethod, args, reply) + return pool.Call(context.TODO(), serviceMethod, args, reply) } type loadDispatcher struct { @@ -437,7 +438,7 @@ type lazyDH struct { dR *DispatcherRoute } -func (l *lazyDH) Call(method string, args, reply any) (err error) { +func (l *lazyDH) Call(ctx *context.Context, method string, args, reply any) (err error) { return callDH(l.dh, l.routeID, l.dR, method, args, reply) } @@ -464,7 +465,7 @@ func callDH(dh *engine.DispatcherHost, routeID string, dR *DispatcherRoute, utils.DispatcherS, err.Error(), dR)) } } - if err = dh.Call(method, args, reply); err != nil { + if err = dh.Call(context.TODO(), method, args, reply); err != nil { return } return diff --git a/dispatchers/libdispatcher_test.go b/dispatchers/libdispatcher_test.go index 3ae681c97..f16e9f2c1 100644 --- a/dispatchers/libdispatcher_test.go +++ b/dispatchers/libdispatcher_test.go @@ -23,6 +23,8 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -692,7 +694,7 @@ func TestLibDispatcherLoadDispatcherCacheError7(t *testing.T) { }, }, } - //rpcCl := map[string]chan rpcclient.ClientConnector{} + //rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, nil) dm := engine.NewDataManager(nil, nil, connMng) @@ -745,7 +747,7 @@ func TestLibDispatcherLoadDispatcherCacheError7(t *testing.T) { type mockTypeConDispatch struct{} -func (*mockTypeConDispatch) Call(serviceMethod string, args, reply any) error { +func (*mockTypeConDispatch) Call(ctx *context.Context, serviceMethod string, args, reply any) error { return rpc.ErrShutdown } @@ -768,7 +770,7 @@ func TestLibDispatcherLoadDispatcherCacheError5(t *testing.T) { tmp := engine.IntRPC engine.IntRPC = map[string]*rpcclient.RPCClient{} - chanRPC := make(chan rpcclient.ClientConnector, 1) + chanRPC := make(chan birpc.ClientConnector, 1) chanRPC <- new(mockTypeConDispatch) engine.IntRPC.AddInternalRPCClient(utils.AttributeSv1, chanRPC) engine.Cache.SetWithoutReplicate(utils.CacheDispatcherHosts, "testTenant:testID", @@ -812,7 +814,7 @@ func TestLibDispatcherSingleResultDispatcherCase1(t *testing.T) { } tmp := engine.IntRPC engine.IntRPC = map[string]*rpcclient.RPCClient{} - chanRPC := make(chan rpcclient.ClientConnector, 1) + chanRPC := make(chan birpc.ClientConnector, 1) chanRPC <- new(mockTypeConDispatch) engine.IntRPC.AddInternalRPCClient(utils.AttributeSv1, chanRPC) engine.Cache.SetWithoutReplicate(utils.CacheDispatcherHosts, "testTenant:testID", @@ -828,7 +830,7 @@ func TestLibDispatcherSingleResultDispatcherCase1(t *testing.T) { type mockTypeConDispatch2 struct{} -func (*mockTypeConDispatch2) Call(serviceMethod string, args, reply any) error { +func (*mockTypeConDispatch2) Call(ctx *context.Context, serviceMethod string, args, reply any) error { return nil } @@ -849,7 +851,7 @@ func TestLibDispatcherSingleResultDispatcherCase2(t *testing.T) { } tmp := engine.IntRPC engine.IntRPC = map[string]*rpcclient.RPCClient{} - chanRPC := make(chan rpcclient.ClientConnector, 1) + chanRPC := make(chan birpc.ClientConnector, 1) chanRPC <- new(mockTypeConDispatch2) engine.IntRPC.AddInternalRPCClient(utils.AttributeSv1, chanRPC) engine.Cache.SetWithoutReplicate(utils.CacheDispatcherHosts, "testTenant:testID", @@ -880,7 +882,7 @@ func TestLibDispatcherSingleResultDispatcherCase3(t *testing.T) { }, }, } - rpcCl := map[string]chan rpcclient.ClientConnector{} + rpcCl := map[string]chan birpc.ClientConnector{} connMng := engine.NewConnManager(cfg, rpcCl) dm := engine.NewDataManager(nil, nil, connMng) newCache := engine.NewCacheS(cfg, dm, nil) @@ -896,7 +898,7 @@ func TestLibDispatcherSingleResultDispatcherCase3(t *testing.T) { } tmp := engine.IntRPC engine.IntRPC = map[string]*rpcclient.RPCClient{} - chanRPC := make(chan rpcclient.ClientConnector, 1) + chanRPC := make(chan birpc.ClientConnector, 1) chanRPC <- new(mockTypeConDispatch2) engine.IntRPC.AddInternalRPCClient(utils.AttributeSv1, chanRPC) engine.Cache.SetWithoutReplicate(utils.CacheDispatcherHosts, "testTenant:testID", diff --git a/dispatchers/rals.go b/dispatchers/rals.go index 0d0d10c97..251050927 100644 --- a/dispatchers/rals.go +++ b/dispatchers/rals.go @@ -21,10 +21,11 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) RALsV1Ping(args *utils.CGREvent, rpl *string) (err error) { +func (dS *DispatcherService) RALsV1Ping(ctx *context.Context, args *utils.CGREvent, rpl *string) (err error) { if args == nil { args = new(utils.CGREvent) } @@ -38,7 +39,7 @@ func (dS *DispatcherService) RALsV1Ping(args *utils.CGREvent, rpl *string) (err return dS.Dispatch(args, utils.MetaRALs, utils.RALsV1Ping, args, rpl) } -func (dS *DispatcherService) RALsV1GetRatingPlansCost(args *utils.RatingPlanCostArg, rpl *RatingPlanCost) (err error) { +func (dS *DispatcherService) RALsV1GetRatingPlansCost(ctx *context.Context, args *utils.RatingPlanCostArg, rpl *RatingPlanCost) (err error) { tenant := dS.cfg.GeneralCfg().DefaultTenant if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.RALsV1GetRatingPlansCost, tenant, diff --git a/dispatchers/rals_it_test.go b/dispatchers/rals_it_test.go index 100bca257..f6cdc19e6 100644 --- a/dispatchers/rals_it_test.go +++ b/dispatchers/rals_it_test.go @@ -25,6 +25,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) @@ -62,12 +63,12 @@ func TestDspRALsIT(t *testing.T) { func testDspRALsPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.RALsV1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.RALsV1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.RALsV1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.RALsV1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ @@ -91,7 +92,7 @@ func testDspRALsGetRatingPlanCost(t *testing.T) { }, } var reply RatingPlanCost - if err := dispEngine.RPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil { t.Error(err) } else if reply.RatingPlanID != "RP_1001" { t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID) diff --git a/dispatchers/rals_test.go b/dispatchers/rals_test.go index 73d744890..50a093014 100644 --- a/dispatchers/rals_test.go +++ b/dispatchers/rals_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -35,7 +36,7 @@ func TestRALsRALsV1PingErr1(t *testing.T) { var reply *string expected := "MANDATORY_IE_MISSING: [ApiKey]" - result := dspSrv.RALsV1Ping(CGREvent, reply) + result := dspSrv.RALsV1Ping(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -51,7 +52,7 @@ func TestRALsRALsV1PingErr2(t *testing.T) { var reply *string expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" - result := dspSrv.RALsV1Ping(CGREvent, reply) + result := dspSrv.RALsV1Ping(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -66,7 +67,7 @@ func TestRALsRALsV1PingErrNil(t *testing.T) { var reply *string expected := "MANDATORY_IE_MISSING: [ApiKey]" - result := dspSrv.RALsV1Ping(CGREvent, reply) + result := dspSrv.RALsV1Ping(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -81,7 +82,7 @@ func TestRALsRALsV1GetRatingPlansCostErr1(t *testing.T) { var reply *RatingPlanCost expected := "MANDATORY_IE_MISSING: [ApiKey]" - result := dspSrv.RALsV1GetRatingPlansCost(CGREvent, reply) + result := dspSrv.RALsV1GetRatingPlansCost(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -95,7 +96,7 @@ func TestRALsRALsV1GetRatingPlansCostErr2(t *testing.T) { var reply *RatingPlanCost expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" - result := dspSrv.RALsV1GetRatingPlansCost(CGREvent, reply) + result := dspSrv.RALsV1GetRatingPlansCost(context.Background(), CGREvent, reply) if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/replicator.go b/dispatchers/replicator.go index 7e5316c3b..1b3225077 100644 --- a/dispatchers/replicator.go +++ b/dispatchers/replicator.go @@ -21,11 +21,12 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) ReplicatorSv1Ping(args *utils.CGREvent, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1Ping(ctx *context.Context, args *utils.CGREvent, rpl *string) (err error) { if args == nil { args = new(utils.CGREvent) } @@ -39,7 +40,7 @@ func (dS *DispatcherService) ReplicatorSv1Ping(args *utils.CGREvent, rpl *string return dS.Dispatch(args, utils.MetaReplicator, utils.ReplicatorSv1Ping, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetAccount(args *utils.StringWithAPIOpts, rpl *engine.Account) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetAccount(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *engine.Account) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -56,7 +57,7 @@ func (dS *DispatcherService) ReplicatorSv1GetAccount(args *utils.StringWithAPIOp }, utils.MetaReplicator, utils.ReplicatorSv1GetAccount, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetDestination(args *utils.StringWithAPIOpts, rpl *engine.Destination) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetDestination(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *engine.Destination) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -73,7 +74,7 @@ func (dS *DispatcherService) ReplicatorSv1GetDestination(args *utils.StringWithA }, utils.MetaReplicator, utils.ReplicatorSv1GetDestination, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetReverseDestination(args *utils.StringWithAPIOpts, rpl *[]string) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetReverseDestination(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *[]string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -90,7 +91,7 @@ func (dS *DispatcherService) ReplicatorSv1GetReverseDestination(args *utils.Stri }, utils.MetaReplicator, utils.ReplicatorSv1GetReverseDestination, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetStatQueue(args *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetStatQueue(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -108,7 +109,7 @@ func (dS *DispatcherService) ReplicatorSv1GetStatQueue(args *utils.TenantIDWithA }, utils.MetaReplicator, utils.ReplicatorSv1GetStatQueue, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetFilter(args *utils.TenantIDWithAPIOpts, reply *engine.Filter) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetFilter(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.Filter) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -126,7 +127,7 @@ func (dS *DispatcherService) ReplicatorSv1GetFilter(args *utils.TenantIDWithAPIO }, utils.MetaReplicator, utils.ReplicatorSv1GetFilter, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetThreshold(args *utils.TenantIDWithAPIOpts, reply *engine.Threshold) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetThreshold(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.Threshold) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -144,7 +145,7 @@ func (dS *DispatcherService) ReplicatorSv1GetThreshold(args *utils.TenantIDWithA }, utils.MetaReplicator, utils.ReplicatorSv1GetThreshold, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetThresholdProfile(args *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetThresholdProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -162,7 +163,7 @@ func (dS *DispatcherService) ReplicatorSv1GetThresholdProfile(args *utils.Tenant }, utils.MetaReplicator, utils.ReplicatorSv1GetThresholdProfile, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetStatQueueProfile(args *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetStatQueueProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -180,7 +181,7 @@ func (dS *DispatcherService) ReplicatorSv1GetStatQueueProfile(args *utils.Tenant }, utils.MetaReplicator, utils.ReplicatorSv1GetStatQueueProfile, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetTiming(args *utils.StringWithAPIOpts, rpl *utils.TPTiming) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetTiming(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *utils.TPTiming) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -197,7 +198,7 @@ func (dS *DispatcherService) ReplicatorSv1GetTiming(args *utils.StringWithAPIOpt }, utils.MetaReplicator, utils.ReplicatorSv1GetTiming, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetResource(args *utils.TenantIDWithAPIOpts, reply *engine.Resource) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetResource(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.Resource) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -215,7 +216,7 @@ func (dS *DispatcherService) ReplicatorSv1GetResource(args *utils.TenantIDWithAP }, utils.MetaReplicator, utils.ReplicatorSv1GetResource, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetResourceProfile(args *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetResourceProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -233,7 +234,7 @@ func (dS *DispatcherService) ReplicatorSv1GetResourceProfile(args *utils.TenantI }, utils.MetaReplicator, utils.ReplicatorSv1GetResourceProfile, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetActionTriggers(args *utils.StringWithAPIOpts, rpl *engine.ActionTriggers) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetActionTriggers(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *engine.ActionTriggers) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -250,7 +251,7 @@ func (dS *DispatcherService) ReplicatorSv1GetActionTriggers(args *utils.StringWi }, utils.MetaReplicator, utils.ReplicatorSv1GetActionTriggers, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetSharedGroup(args *utils.StringWithAPIOpts, rpl *engine.SharedGroup) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetSharedGroup(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *engine.SharedGroup) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -267,7 +268,7 @@ func (dS *DispatcherService) ReplicatorSv1GetSharedGroup(args *utils.StringWithA }, utils.MetaReplicator, utils.ReplicatorSv1GetSharedGroup, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetActions(args *utils.StringWithAPIOpts, rpl *engine.Actions) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetActions(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *engine.Actions) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -284,7 +285,7 @@ func (dS *DispatcherService) ReplicatorSv1GetActions(args *utils.StringWithAPIOp }, utils.MetaReplicator, utils.ReplicatorSv1GetActions, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetActionPlan(args *utils.StringWithAPIOpts, rpl *engine.ActionPlan) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetActionPlan(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *engine.ActionPlan) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -301,7 +302,7 @@ func (dS *DispatcherService) ReplicatorSv1GetActionPlan(args *utils.StringWithAP }, utils.MetaReplicator, utils.ReplicatorSv1GetActionPlan, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetAllActionPlans(args *utils.StringWithAPIOpts, rpl *map[string]*engine.ActionPlan) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetAllActionPlans(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *map[string]*engine.ActionPlan) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -318,7 +319,7 @@ func (dS *DispatcherService) ReplicatorSv1GetAllActionPlans(args *utils.StringWi }, utils.MetaReplicator, utils.ReplicatorSv1GetAllActionPlans, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetAccountActionPlans(args *utils.StringWithAPIOpts, rpl *[]string) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetAccountActionPlans(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *[]string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -335,7 +336,7 @@ func (dS *DispatcherService) ReplicatorSv1GetAccountActionPlans(args *utils.Stri }, utils.MetaReplicator, utils.ReplicatorSv1GetAccountActionPlans, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetRatingPlan(args *utils.StringWithAPIOpts, rpl *engine.RatingPlan) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetRatingPlan(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *engine.RatingPlan) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -352,7 +353,7 @@ func (dS *DispatcherService) ReplicatorSv1GetRatingPlan(args *utils.StringWithAP }, utils.MetaReplicator, utils.ReplicatorSv1GetRatingPlan, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetRatingProfile(args *utils.StringWithAPIOpts, rpl *engine.RatingProfile) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetRatingProfile(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *engine.RatingProfile) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -369,7 +370,7 @@ func (dS *DispatcherService) ReplicatorSv1GetRatingProfile(args *utils.StringWit }, utils.MetaReplicator, utils.ReplicatorSv1GetRatingProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1GetRouteProfile(args *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetRouteProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -387,7 +388,7 @@ func (dS *DispatcherService) ReplicatorSv1GetRouteProfile(args *utils.TenantIDWi }, utils.MetaReplicator, utils.ReplicatorSv1GetRouteProfile, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetAttributeProfile(args *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetAttributeProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -405,7 +406,7 @@ func (dS *DispatcherService) ReplicatorSv1GetAttributeProfile(args *utils.Tenant }, utils.MetaReplicator, utils.ReplicatorSv1GetAttributeProfile, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetChargerProfile(args *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetChargerProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -423,7 +424,7 @@ func (dS *DispatcherService) ReplicatorSv1GetChargerProfile(args *utils.TenantID }, utils.MetaReplicator, utils.ReplicatorSv1GetChargerProfile, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetDispatcherProfile(args *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetDispatcherProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -441,7 +442,7 @@ func (dS *DispatcherService) ReplicatorSv1GetDispatcherProfile(args *utils.Tenan }, utils.MetaReplicator, utils.ReplicatorSv1GetDispatcherProfile, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetDispatcherHost(args *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetDispatcherHost(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -459,7 +460,7 @@ func (dS *DispatcherService) ReplicatorSv1GetDispatcherHost(args *utils.TenantID }, utils.MetaReplicator, utils.ReplicatorSv1GetDispatcherHost, args, reply) } -func (dS *DispatcherService) ReplicatorSv1GetItemLoadIDs(args *utils.StringWithAPIOpts, rpl *map[string]int64) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetItemLoadIDs(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *map[string]int64) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -476,7 +477,7 @@ func (dS *DispatcherService) ReplicatorSv1GetItemLoadIDs(args *utils.StringWithA }, utils.MetaReplicator, utils.ReplicatorSv1GetItemLoadIDs, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetThresholdProfile(args *engine.ThresholdProfileWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetThresholdProfile(ctx *context.Context, args *engine.ThresholdProfileWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.ThresholdProfileWithAPIOpts{ ThresholdProfile: &engine.ThresholdProfile{}, @@ -495,7 +496,7 @@ func (dS *DispatcherService) ReplicatorSv1SetThresholdProfile(args *engine.Thres }, utils.MetaReplicator, utils.ReplicatorSv1SetThresholdProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetThreshold(args *engine.ThresholdWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetThreshold(ctx *context.Context, args *engine.ThresholdWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.ThresholdWithAPIOpts{ Threshold: &engine.Threshold{}, @@ -514,7 +515,7 @@ func (dS *DispatcherService) ReplicatorSv1SetThreshold(args *engine.ThresholdWit }, utils.MetaReplicator, utils.ReplicatorSv1SetThreshold, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetDestination(args *engine.DestinationWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetDestination(ctx *context.Context, args *engine.DestinationWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.DestinationWithAPIOpts{} } @@ -531,7 +532,7 @@ func (dS *DispatcherService) ReplicatorSv1SetDestination(args *engine.Destinatio }, utils.MetaReplicator, utils.ReplicatorSv1SetDestination, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetAccount(args *engine.AccountWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetAccount(ctx *context.Context, args *engine.AccountWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.AccountWithAPIOpts{ Account: &engine.Account{}, @@ -550,7 +551,7 @@ func (dS *DispatcherService) ReplicatorSv1SetAccount(args *engine.AccountWithAPI }, utils.MetaReplicator, utils.ReplicatorSv1SetAccount, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetReverseDestination(args *engine.DestinationWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetReverseDestination(ctx *context.Context, args *engine.DestinationWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.DestinationWithAPIOpts{} } @@ -567,7 +568,7 @@ func (dS *DispatcherService) ReplicatorSv1SetReverseDestination(args *engine.Des }, utils.MetaReplicator, utils.ReplicatorSv1SetReverseDestination, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetStatQueue(args *engine.StatQueueWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetStatQueue(ctx *context.Context, args *engine.StatQueueWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.StatQueueWithAPIOpts{ StatQueue: &engine.StatQueue{}, @@ -586,7 +587,7 @@ func (dS *DispatcherService) ReplicatorSv1SetStatQueue(args *engine.StatQueueWit }, utils.MetaReplicator, utils.ReplicatorSv1SetStatQueue, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetFilter(args *engine.FilterWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetFilter(ctx *context.Context, args *engine.FilterWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.FilterWithAPIOpts{ Filter: &engine.Filter{}, @@ -605,7 +606,7 @@ func (dS *DispatcherService) ReplicatorSv1SetFilter(args *engine.FilterWithAPIOp }, utils.MetaReplicator, utils.ReplicatorSv1SetFilter, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetStatQueueProfile(args *engine.StatQueueProfileWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetStatQueueProfile(ctx *context.Context, args *engine.StatQueueProfileWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.StatQueueProfileWithAPIOpts{ StatQueueProfile: &engine.StatQueueProfile{}, @@ -624,7 +625,7 @@ func (dS *DispatcherService) ReplicatorSv1SetStatQueueProfile(args *engine.StatQ }, utils.MetaReplicator, utils.ReplicatorSv1SetStatQueueProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetTiming(args *utils.TPTimingWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetTiming(ctx *context.Context, args *utils.TPTimingWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TPTimingWithAPIOpts{} } @@ -641,7 +642,7 @@ func (dS *DispatcherService) ReplicatorSv1SetTiming(args *utils.TPTimingWithAPIO }, utils.MetaReplicator, utils.ReplicatorSv1SetTiming, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetResource(args *engine.ResourceWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetResource(ctx *context.Context, args *engine.ResourceWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.ResourceWithAPIOpts{ Resource: &engine.Resource{}, @@ -660,7 +661,7 @@ func (dS *DispatcherService) ReplicatorSv1SetResource(args *engine.ResourceWithA }, utils.MetaReplicator, utils.ReplicatorSv1SetResource, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetResourceProfile(args *engine.ResourceProfileWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetResourceProfile(ctx *context.Context, args *engine.ResourceProfileWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.ResourceProfileWithAPIOpts{ ResourceProfile: &engine.ResourceProfile{}, @@ -679,7 +680,7 @@ func (dS *DispatcherService) ReplicatorSv1SetResourceProfile(args *engine.Resour }, utils.MetaReplicator, utils.ReplicatorSv1SetResourceProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetActionTriggers(args *engine.SetActionTriggersArgWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetActionTriggers(ctx *context.Context, args *engine.SetActionTriggersArgWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.SetActionTriggersArgWithAPIOpts{} } @@ -696,7 +697,7 @@ func (dS *DispatcherService) ReplicatorSv1SetActionTriggers(args *engine.SetActi }, utils.MetaReplicator, utils.ReplicatorSv1SetActionTriggers, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetSharedGroup(args *engine.SharedGroupWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetSharedGroup(ctx *context.Context, args *engine.SharedGroupWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.SharedGroupWithAPIOpts{} } @@ -713,7 +714,7 @@ func (dS *DispatcherService) ReplicatorSv1SetSharedGroup(args *engine.SharedGrou }, utils.MetaReplicator, utils.ReplicatorSv1SetSharedGroup, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetActions(args *engine.SetActionsArgsWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetActions(ctx *context.Context, args *engine.SetActionsArgsWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.SetActionsArgsWithAPIOpts{} } @@ -730,7 +731,7 @@ func (dS *DispatcherService) ReplicatorSv1SetActions(args *engine.SetActionsArgs }, utils.MetaReplicator, utils.ReplicatorSv1SetActions, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetRatingPlan(args *engine.RatingPlanWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetRatingPlan(ctx *context.Context, args *engine.RatingPlanWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.RatingPlanWithAPIOpts{} } @@ -747,7 +748,7 @@ func (dS *DispatcherService) ReplicatorSv1SetRatingPlan(args *engine.RatingPlanW }, utils.MetaReplicator, utils.ReplicatorSv1SetRatingPlan, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetRatingProfile(args *engine.RatingProfileWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetRatingProfile(ctx *context.Context, args *engine.RatingProfileWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.RatingProfileWithAPIOpts{} } @@ -764,7 +765,7 @@ func (dS *DispatcherService) ReplicatorSv1SetRatingProfile(args *engine.RatingPr }, utils.MetaReplicator, utils.ReplicatorSv1SetRatingProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetRouteProfile(args *engine.RouteProfileWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetRouteProfile(ctx *context.Context, args *engine.RouteProfileWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.RouteProfileWithAPIOpts{ RouteProfile: &engine.RouteProfile{}, @@ -783,7 +784,7 @@ func (dS *DispatcherService) ReplicatorSv1SetRouteProfile(args *engine.RouteProf }, utils.MetaReplicator, utils.ReplicatorSv1SetRouteProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetAttributeProfile(args *engine.AttributeProfileWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetAttributeProfile(ctx *context.Context, args *engine.AttributeProfileWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.AttributeProfileWithAPIOpts{ AttributeProfile: &engine.AttributeProfile{}, @@ -802,7 +803,7 @@ func (dS *DispatcherService) ReplicatorSv1SetAttributeProfile(args *engine.Attri }, utils.MetaReplicator, utils.ReplicatorSv1SetAttributeProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetChargerProfile(args *engine.ChargerProfileWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetChargerProfile(ctx *context.Context, args *engine.ChargerProfileWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.ChargerProfileWithAPIOpts{ ChargerProfile: &engine.ChargerProfile{}, @@ -821,7 +822,7 @@ func (dS *DispatcherService) ReplicatorSv1SetChargerProfile(args *engine.Charger }, utils.MetaReplicator, utils.ReplicatorSv1SetChargerProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetDispatcherProfile(args *engine.DispatcherProfileWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetDispatcherProfile(ctx *context.Context, args *engine.DispatcherProfileWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.DispatcherProfileWithAPIOpts{ DispatcherProfile: &engine.DispatcherProfile{}, @@ -840,7 +841,7 @@ func (dS *DispatcherService) ReplicatorSv1SetDispatcherProfile(args *engine.Disp }, utils.MetaReplicator, utils.ReplicatorSv1SetDispatcherProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetActionPlan(args *engine.SetActionPlanArgWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetActionPlan(ctx *context.Context, args *engine.SetActionPlanArgWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.SetActionPlanArgWithAPIOpts{} } @@ -857,7 +858,7 @@ func (dS *DispatcherService) ReplicatorSv1SetActionPlan(args *engine.SetActionPl }, utils.MetaReplicator, utils.ReplicatorSv1SetActionPlan, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetAccountActionPlans(args *engine.SetAccountActionPlansArgWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetAccountActionPlans(ctx *context.Context, args *engine.SetAccountActionPlansArgWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.SetAccountActionPlansArgWithAPIOpts{} } @@ -874,7 +875,7 @@ func (dS *DispatcherService) ReplicatorSv1SetAccountActionPlans(args *engine.Set }, utils.MetaReplicator, utils.ReplicatorSv1SetAccountActionPlans, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetDispatcherHost(args *engine.DispatcherHostWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetDispatcherHost(ctx *context.Context, args *engine.DispatcherHostWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.DispatcherHostWithAPIOpts{ DispatcherHost: &engine.DispatcherHost{}, @@ -893,7 +894,7 @@ func (dS *DispatcherService) ReplicatorSv1SetDispatcherHost(args *engine.Dispatc }, utils.MetaReplicator, utils.ReplicatorSv1SetDispatcherHost, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveThreshold(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveThreshold(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -912,7 +913,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveThreshold(args *utils.TenantIDWi }, utils.MetaReplicator, utils.ReplicatorSv1RemoveThreshold, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveDestination(args *utils.StringWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveDestination(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -929,7 +930,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveDestination(args *utils.StringWi }, utils.MetaReplicator, utils.ReplicatorSv1RemoveDestination, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1SetLoadIDs(args *utils.LoadIDsWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetLoadIDs(ctx *context.Context, args *utils.LoadIDsWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.LoadIDsWithAPIOpts{} } @@ -946,7 +947,7 @@ func (dS *DispatcherService) ReplicatorSv1SetLoadIDs(args *utils.LoadIDsWithAPIO }, utils.MetaReplicator, utils.ReplicatorSv1SetLoadIDs, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveAccount(args *utils.StringWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveAccount(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -963,7 +964,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveAccount(args *utils.StringWithAP }, utils.MetaReplicator, utils.ReplicatorSv1RemoveAccount, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveStatQueue(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveStatQueue(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -982,7 +983,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveStatQueue(args *utils.TenantIDWi }, utils.MetaReplicator, utils.ReplicatorSv1RemoveStatQueue, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveFilter(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveFilter(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -1001,7 +1002,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveFilter(args *utils.TenantIDWithA }, utils.MetaReplicator, utils.ReplicatorSv1RemoveFilter, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveThresholdProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -1020,7 +1021,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveThresholdProfile(args *utils.Ten }, utils.MetaReplicator, utils.ReplicatorSv1RemoveThresholdProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveStatQueueProfile(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveStatQueueProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -1039,7 +1040,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveStatQueueProfile(args *utils.Ten }, utils.MetaReplicator, utils.ReplicatorSv1RemoveStatQueueProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveTiming(args *utils.StringWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveTiming(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -1056,7 +1057,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveTiming(args *utils.StringWithAPI }, utils.MetaReplicator, utils.ReplicatorSv1RemoveTiming, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveResource(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveResource(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -1075,7 +1076,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveResource(args *utils.TenantIDWit }, utils.MetaReplicator, utils.ReplicatorSv1RemoveResource, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveResourceProfile(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveResourceProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -1094,7 +1095,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveResourceProfile(args *utils.Tena }, utils.MetaReplicator, utils.ReplicatorSv1RemoveResourceProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveActionTriggers(args *utils.StringWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveActionTriggers(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -1111,7 +1112,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveActionTriggers(args *utils.Strin }, utils.MetaReplicator, utils.ReplicatorSv1RemoveActionTriggers, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveSharedGroup(args *utils.StringWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveSharedGroup(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -1128,7 +1129,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveSharedGroup(args *utils.StringWi }, utils.MetaReplicator, utils.ReplicatorSv1RemoveSharedGroup, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveActions(args *utils.StringWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveActions(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -1145,7 +1146,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveActions(args *utils.StringWithAP }, utils.MetaReplicator, utils.ReplicatorSv1RemoveActions, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveActionPlan(args *utils.StringWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveActionPlan(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -1162,7 +1163,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveActionPlan(args *utils.StringWit }, utils.MetaReplicator, utils.ReplicatorSv1RemoveActionPlan, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemAccountActionPlans(args *engine.RemAccountActionPlansArgsWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemAccountActionPlans(ctx *context.Context, args *engine.RemAccountActionPlansArgsWithAPIOpts, rpl *string) (err error) { if args == nil { args = &engine.RemAccountActionPlansArgsWithAPIOpts{} } @@ -1179,7 +1180,7 @@ func (dS *DispatcherService) ReplicatorSv1RemAccountActionPlans(args *engine.Rem }, utils.MetaReplicator, utils.ReplicatorSv1RemAccountActionPlans, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveRatingPlan(args *utils.StringWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveRatingPlan(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -1196,7 +1197,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveRatingPlan(args *utils.StringWit }, utils.MetaReplicator, utils.ReplicatorSv1RemoveRatingPlan, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveRatingProfile(args *utils.StringWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveRatingProfile(ctx *context.Context, args *utils.StringWithAPIOpts, rpl *string) (err error) { if args == nil { args = new(utils.StringWithAPIOpts) } @@ -1213,7 +1214,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveRatingProfile(args *utils.String }, utils.MetaReplicator, utils.ReplicatorSv1RemoveRatingProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveRouteProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -1232,7 +1233,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveRouteProfile(args *utils.TenantI }, utils.MetaReplicator, utils.ReplicatorSv1RemoveRouteProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveAttributeProfile(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveAttributeProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -1251,7 +1252,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveAttributeProfile(args *utils.Ten }, utils.MetaReplicator, utils.ReplicatorSv1RemoveAttributeProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveChargerProfile(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveChargerProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -1270,7 +1271,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveChargerProfile(args *utils.Tenan }, utils.MetaReplicator, utils.ReplicatorSv1RemoveChargerProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveDispatcherProfile(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveDispatcherProfile(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -1289,7 +1290,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveDispatcherProfile(args *utils.Te }, utils.MetaReplicator, utils.ReplicatorSv1RemoveDispatcherProfile, args, rpl) } -func (dS *DispatcherService) ReplicatorSv1RemoveDispatcherHost(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveDispatcherHost(ctx *context.Context, args *utils.TenantIDWithAPIOpts, rpl *string) (err error) { if args == nil { args = &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{}, @@ -1309,7 +1310,7 @@ func (dS *DispatcherService) ReplicatorSv1RemoveDispatcherHost(args *utils.Tenan } // ReplicatorSv1GetIndexes . -func (dS *DispatcherService) ReplicatorSv1GetIndexes(args *utils.GetIndexesArg, reply *map[string]utils.StringSet) (err error) { +func (dS *DispatcherService) ReplicatorSv1GetIndexes(ctx *context.Context, args *utils.GetIndexesArg, reply *map[string]utils.StringSet) (err error) { if args == nil { args = &utils.GetIndexesArg{} } @@ -1327,7 +1328,7 @@ func (dS *DispatcherService) ReplicatorSv1GetIndexes(args *utils.GetIndexesArg, } // ReplicatorSv1SetIndexes . -func (dS *DispatcherService) ReplicatorSv1SetIndexes(args *utils.SetIndexesArg, reply *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1SetIndexes(ctx *context.Context, args *utils.SetIndexesArg, reply *string) (err error) { if args == nil { args = &utils.SetIndexesArg{} } @@ -1345,7 +1346,7 @@ func (dS *DispatcherService) ReplicatorSv1SetIndexes(args *utils.SetIndexesArg, } // ReplicatorSv1RemoveIndexes . -func (dS *DispatcherService) ReplicatorSv1RemoveIndexes(args *utils.GetIndexesArg, reply *string) (err error) { +func (dS *DispatcherService) ReplicatorSv1RemoveIndexes(ctx *context.Context, args *utils.GetIndexesArg, reply *string) (err error) { if args == nil { args = &utils.GetIndexesArg{} } diff --git a/dispatchers/replicator_it_test.go b/dispatchers/replicator_it_test.go index 705e8fdc0..03cac35bc 100644 --- a/dispatchers/replicator_it_test.go +++ b/dispatchers/replicator_it_test.go @@ -25,6 +25,7 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -85,13 +86,13 @@ func TestDspReplicator(t *testing.T) { func testDspRplPingFailover(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.ReplicatorSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } reply = utils.EmptyString - if err := allEngine2.RPC.Call(utils.ReplicatorSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine2.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -104,27 +105,27 @@ func testDspRplPingFailover(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine.stopEngine(t) reply = utils.EmptyString - if err := dispEngine.RPC.Call(utils.ReplicatorSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine2.stopEngine(t) reply = utils.EmptyString - if err := dispEngine.RPC.Call(utils.ReplicatorSv1Ping, &ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, &ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine.startEngine(t) allEngine2.startEngine(t) reply = utils.EmptyString - if err := dispEngine.RPC.Call(utils.ReplicatorSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -144,7 +145,7 @@ func testDspRplAccount(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetAccount, attrSetAccount, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetAccount, attrSetAccount, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetAccount: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -157,7 +158,7 @@ func testDspRplAccount(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccount, argsGetAccount, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccount, argsGetAccount, &reply); err != nil { t.Errorf("Expecting: %+v, received: %+v", utils.ErrNotFound, err) } else if reply.ID != attrSetAccount.Account.ID { t.Errorf("Expecting: %+v, received: %+v", attrSetAccount.Account.ID, reply.ID) @@ -169,13 +170,13 @@ func testDspRplAccount(t *testing.T) { // Stop engine 1 allEngine.stopEngine(t) // Get - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccount, argsGetAccount, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccount, argsGetAccount, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } // Start engine 1 allEngine.startEngine(t) // Remove Account - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveAccount, &utils.StringWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveAccount, &utils.StringWithAPIOpts{ Arg: "cgrates.org:1008", APIOpts: map[string]any{ utils.OptsAPIKey: "repl12345", @@ -186,7 +187,7 @@ func testDspRplAccount(t *testing.T) { t.Error("Unexpected reply returned", replyStr) } // Get Account - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccount, argsGetAccount, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccount, argsGetAccount, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -204,7 +205,7 @@ func testDspRplSupplierProfile(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetRouteProfile, argSetSupplierProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetRouteProfile, argSetSupplierProfile, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetSupplierProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -221,7 +222,7 @@ func testDspRplSupplierProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRouteProfile, argRouteProfile, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRouteProfile, argRouteProfile, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetSupplierProfile: ", err) } else if reply.ID != argSetSupplierProfile.ID { t.Errorf("Expecting: %+v, received: %+v", argSetSupplierProfile.ID, reply.ID) @@ -233,7 +234,7 @@ func testDspRplSupplierProfile(t *testing.T) { allEngine.stopEngine(t) // Get RouteProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRouteProfile, argRouteProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRouteProfile, argRouteProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -241,13 +242,13 @@ func testDspRplSupplierProfile(t *testing.T) { allEngine.startEngine(t) // Remove SupplierProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveRouteProfile, argRouteProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveRouteProfile, argRouteProfile, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get RouteProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRouteProfile, argRouteProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRouteProfile, argRouteProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -264,7 +265,7 @@ func testDspRplAttributeProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetAttributeProfile, setAttributeProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetAttributeProfile, setAttributeProfile, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetAttributeProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -281,7 +282,7 @@ func testDspRplAttributeProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAttributeProfile, argAttributeProfile, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAttributeProfile, argAttributeProfile, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetAttributeProfile: ", err) } else if reply.ID != setAttributeProfile.ID { t.Errorf("Expecting: %+v, received: %+v", setAttributeProfile.ID, reply.ID) @@ -292,7 +293,7 @@ func testDspRplAttributeProfile(t *testing.T) { allEngine.stopEngine(t) // Get AttributeProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAttributeProfile, argAttributeProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAttributeProfile, argAttributeProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -300,14 +301,14 @@ func testDspRplAttributeProfile(t *testing.T) { allEngine.startEngine(t) // Remove AttributeProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveAttributeProfile, argAttributeProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveAttributeProfile, argAttributeProfile, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get AttributeProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAttributeProfile, argAttributeProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAttributeProfile, argAttributeProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -324,7 +325,7 @@ func testDspRplChargerProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetChargerProfile, setChargerProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetChargerProfile, setChargerProfile, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetChargerProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -340,7 +341,7 @@ func testDspRplChargerProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetChargerProfile, argsChargerProfile, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetChargerProfile, argsChargerProfile, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetChargerProfile: ", err) } else if reply.ID != argsChargerProfile.ID { t.Errorf("Expecting: %+v, received: %+v", argsChargerProfile.ID, reply.ID) @@ -351,7 +352,7 @@ func testDspRplChargerProfile(t *testing.T) { allEngine.stopEngine(t) // Get ChargerProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetChargerProfile, argsChargerProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetChargerProfile, argsChargerProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -359,14 +360,14 @@ func testDspRplChargerProfile(t *testing.T) { allEngine.startEngine(t) // Remove ChargerProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveChargerProfile, argsChargerProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveChargerProfile, argsChargerProfile, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get ChargerProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetChargerProfile, argsChargerProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetChargerProfile, argsChargerProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -383,7 +384,7 @@ func testDspRplDispatcherProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetDispatcherProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -399,7 +400,7 @@ func testDspRplDispatcherProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetDispatcherProfile, argsDispatcherProfile, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherProfile, argsDispatcherProfile, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetDispatcherProfile: ", err) } else if reply.ID != argsDispatcherProfile.ID { t.Errorf("Expecting: %+v, received: %+v", argsDispatcherProfile.ID, reply.ID) @@ -410,7 +411,7 @@ func testDspRplDispatcherProfile(t *testing.T) { allEngine.stopEngine(t) // Get DispatcherProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetDispatcherProfile, argsDispatcherProfile, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherProfile, argsDispatcherProfile, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -418,14 +419,14 @@ func testDspRplDispatcherProfile(t *testing.T) { allEngine.startEngine(t) // Remove DispatcherProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveDispatcherProfile, argsDispatcherProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveDispatcherProfile, argsDispatcherProfile, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get DispatcherProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetDispatcherProfile, argsDispatcherProfile, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherProfile, argsDispatcherProfile, &reply); err == nil || err.Error() != utils.ErrDSPProfileNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -444,7 +445,7 @@ func testDspRplDispatcherHost(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetDispatcherHost, setDispatcherHost, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetDispatcherHost, setDispatcherHost, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetDispatcherHost: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -460,7 +461,7 @@ func testDspRplDispatcherHost(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetDispatcherHost, argsDispatcherHost, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherHost, argsDispatcherHost, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetDispatcherHost: ", err) } else if reply.ID != argsDispatcherHost.ID { t.Errorf("Expecting: %+v, received: %+v", argsDispatcherHost.ID, reply.ID) @@ -471,7 +472,7 @@ func testDspRplDispatcherHost(t *testing.T) { allEngine.stopEngine(t) // Get DispatcherHost - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetDispatcherHost, argsDispatcherHost, &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherHost, argsDispatcherHost, &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -479,14 +480,14 @@ func testDspRplDispatcherHost(t *testing.T) { allEngine.startEngine(t) // Remove DispatcherHost - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveDispatcherHost, argsDispatcherHost, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveDispatcherHost, argsDispatcherHost, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get DispatcherHost - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetDispatcherHost, argsDispatcherHost, &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherHost, argsDispatcherHost, &reply); err == nil || err.Error() != utils.ErrDSPHostNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -503,7 +504,7 @@ func testDspRplFilter(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetFilter, setFilter, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetFilter, setFilter, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetFilter: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -519,7 +520,7 @@ func testDspRplFilter(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetFilter, argsFilter, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetFilter, argsFilter, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetFilter: ", err) } else if reply.ID != argsFilter.ID { t.Errorf("Expecting: %+v, received: %+v", argsFilter.ID, reply.ID) @@ -530,7 +531,7 @@ func testDspRplFilter(t *testing.T) { allEngine.stopEngine(t) // Get Filter - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetFilter, argsFilter, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetFilter, argsFilter, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -538,14 +539,14 @@ func testDspRplFilter(t *testing.T) { allEngine.startEngine(t) // Remove Filter - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveFilter, argsFilter, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveFilter, argsFilter, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get Filter - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetFilter, argsFilter, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetFilter, argsFilter, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -562,7 +563,7 @@ func testDspRplThreshold(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetThreshold, setThreshold, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetThreshold, setThreshold, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetThreshold: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -578,7 +579,7 @@ func testDspRplThreshold(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetThreshold, argsThreshold, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsThreshold, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetThreshold: ", err) } else if reply.ID != argsThreshold.ID { t.Errorf("Expecting: %+v, received: %+v", argsThreshold.ID, reply.ID) @@ -589,7 +590,7 @@ func testDspRplThreshold(t *testing.T) { allEngine.stopEngine(t) // Get Threshold - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetThreshold, argsThreshold, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsThreshold, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -597,14 +598,14 @@ func testDspRplThreshold(t *testing.T) { allEngine.startEngine(t) // Remove Threshold - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveThreshold, argsThreshold, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveThreshold, argsThreshold, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get Threshold - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetThreshold, argsThreshold, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsThreshold, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -621,7 +622,7 @@ func testDspRplThresholdProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetThresholdProfile, setThresholdProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetThresholdProfile, setThresholdProfile, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetThresholdProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -637,7 +638,7 @@ func testDspRplThresholdProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetThresholdProfile, argsThresholdProfile, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThresholdProfile, argsThresholdProfile, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetThresholdProfile: ", err) } else if reply.ID != argsThresholdProfile.ID { t.Errorf("Expecting: %+v, received: %+v", argsThresholdProfile.ID, reply.ID) @@ -648,7 +649,7 @@ func testDspRplThresholdProfile(t *testing.T) { allEngine.stopEngine(t) // Get ThresholdProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetThresholdProfile, argsThresholdProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThresholdProfile, argsThresholdProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -656,14 +657,14 @@ func testDspRplThresholdProfile(t *testing.T) { allEngine.startEngine(t) // Remove ThresholdProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveThresholdProfile, argsThresholdProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveThresholdProfile, argsThresholdProfile, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get ThresholdProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetThresholdProfile, argsThresholdProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetThresholdProfile, argsThresholdProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -680,7 +681,7 @@ func testDspRplStatQueue(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetStatQueue, setStatQueue, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetStatQueue, setStatQueue, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetStatQueue: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -696,7 +697,7 @@ func testDspRplStatQueue(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetStatQueue, argsStatQueue, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsStatQueue, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetStatQueue: ", err) } else if reply.ID != argsStatQueue.ID { t.Errorf("Expecting: %+v, received: %+v", argsStatQueue.ID, reply.ID) @@ -707,7 +708,7 @@ func testDspRplStatQueue(t *testing.T) { allEngine.stopEngine(t) // Get StatQueue - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetStatQueue, argsStatQueue, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsStatQueue, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -715,14 +716,14 @@ func testDspRplStatQueue(t *testing.T) { allEngine.startEngine(t) // Remove StatQueue - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveStatQueue, argsStatQueue, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveStatQueue, argsStatQueue, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get StatQueue - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetStatQueue, argsStatQueue, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsStatQueue, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -739,7 +740,7 @@ func testDspRplStatQueueProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetStatQueueProfile, setStatQueueProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetStatQueueProfile, setStatQueueProfile, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetStatQueueProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -755,7 +756,7 @@ func testDspRplStatQueueProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetStatQueueProfile, argsStatQueueProfile, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueueProfile, argsStatQueueProfile, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetStatQueueProfile: ", err) } else if reply.ID != argsStatQueueProfile.ID { t.Errorf("Expecting: %+v, received: %+v", argsStatQueueProfile.ID, reply.ID) @@ -766,7 +767,7 @@ func testDspRplStatQueueProfile(t *testing.T) { allEngine.stopEngine(t) // Get StatQueueProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetStatQueueProfile, argsStatQueueProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueueProfile, argsStatQueueProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -774,14 +775,14 @@ func testDspRplStatQueueProfile(t *testing.T) { allEngine.startEngine(t) // Remove StatQueueProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveStatQueueProfile, argsStatQueueProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveStatQueueProfile, argsStatQueueProfile, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get StatQueueProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetStatQueueProfile, argsStatQueueProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueueProfile, argsStatQueueProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -798,7 +799,7 @@ func testDspRplResource(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetResource, setResource, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetResource, setResource, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetResource: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -814,7 +815,7 @@ func testDspRplResource(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetResource, argsResource, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsResource, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetResource: ", err) } else if reply.ID != argsResource.ID { t.Errorf("Expecting: %+v, received: %+v", argsResource.ID, reply.ID) @@ -825,7 +826,7 @@ func testDspRplResource(t *testing.T) { allEngine.stopEngine(t) // Get Resource - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetResource, argsResource, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsResource, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -833,14 +834,14 @@ func testDspRplResource(t *testing.T) { allEngine.startEngine(t) // Remove Resource - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveResource, argsResource, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveResource, argsResource, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get Resource - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetResource, argsResource, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsResource, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -857,7 +858,7 @@ func testDspRplResourceProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetResourceProfile, setResourceProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetResourceProfile, setResourceProfile, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetResourceProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -873,7 +874,7 @@ func testDspRplResourceProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetResourceProfile, argsResourceProfile, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResourceProfile, argsResourceProfile, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetResourceProfile: ", err) } else if reply.ID != argsResourceProfile.ID { t.Errorf("Expecting: %+v, received: %+v", argsResourceProfile.ID, reply.ID) @@ -884,7 +885,7 @@ func testDspRplResourceProfile(t *testing.T) { allEngine.stopEngine(t) // Get ResourceProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetResourceProfile, argsResourceProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResourceProfile, argsResourceProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -892,14 +893,14 @@ func testDspRplResourceProfile(t *testing.T) { allEngine.startEngine(t) // Remove ResourceProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveResourceProfile, argsResourceProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveResourceProfile, argsResourceProfile, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get ResourceProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetResourceProfile, argsResourceProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetResourceProfile, argsResourceProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -917,7 +918,7 @@ func testDspRplTiming(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetTiming, setTiming, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetTiming, setTiming, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetTiming: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -931,7 +932,7 @@ func testDspRplTiming(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetTiming, argsTiming, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetTiming, argsTiming, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetTiming: ", err) } else if reply.ID != argsTiming.Arg { t.Errorf("Expecting: %+v, received: %+v", argsTiming.Arg, reply.ID) @@ -942,7 +943,7 @@ func testDspRplTiming(t *testing.T) { allEngine.stopEngine(t) // Get Timing - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetTiming, argsTiming, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetTiming, argsTiming, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -950,14 +951,14 @@ func testDspRplTiming(t *testing.T) { allEngine.startEngine(t) // Remove Timing - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveTiming, argsTiming, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveTiming, argsTiming, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get Timing - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetTiming, argsTiming, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetTiming, argsTiming, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -973,7 +974,7 @@ func testDspRplActionTriggers(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetActionTriggers, setActionTriggers, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetActionTriggers, setActionTriggers, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetActionTriggers: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -987,7 +988,7 @@ func testDspRplActionTriggers(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionTriggers, argsActionTriggers, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionTriggers, argsActionTriggers, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetActionTriggers: ", err) } else if reply[0].ID != argsActionTriggers.Arg { t.Errorf("Expecting: %+v, received: %+v", argsActionTriggers.Arg, reply[0].ID) @@ -996,7 +997,7 @@ func testDspRplActionTriggers(t *testing.T) { allEngine.stopEngine(t) // Get ActionTriggers - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionTriggers, argsActionTriggers, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionTriggers, argsActionTriggers, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -1004,14 +1005,14 @@ func testDspRplActionTriggers(t *testing.T) { allEngine.startEngine(t) // Remove ActionTriggers - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveActionTriggers, argsActionTriggers, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveActionTriggers, argsActionTriggers, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get ActionTriggers - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionTriggers, argsActionTriggers, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionTriggers, argsActionTriggers, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -1027,7 +1028,7 @@ func testDspRplSharedGroup(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetSharedGroup, setSharedGroup, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetSharedGroup, setSharedGroup, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetSharedGroup: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -1041,7 +1042,7 @@ func testDspRplSharedGroup(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetSharedGroup: ", err) } else if reply.Id != setSharedGroup.Id { t.Errorf("Expecting: %+v, received: %+v", setSharedGroup.Id, reply.Id) @@ -1050,7 +1051,7 @@ func testDspRplSharedGroup(t *testing.T) { allEngine.stopEngine(t) // Get SharedGroup - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -1058,14 +1059,14 @@ func testDspRplSharedGroup(t *testing.T) { allEngine.startEngine(t) // Remove SharedGroup - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveSharedGroup, argsSharedGroup, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveSharedGroup, argsSharedGroup, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get SharedGroup - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetSharedGroup, argsSharedGroup, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -1086,7 +1087,7 @@ func testDspRplActions(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetActions, setActions, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetActions, setActions, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetActions: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -1100,7 +1101,7 @@ func testDspRplActions(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActions, argsActions, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActions, argsActions, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetActions: ", err) } else if reply[0].Id != setActions.Acs[0].Id { t.Errorf("Expecting: %+v, received: %+v", setActions.Acs[0].Id, reply[0].Id) @@ -1111,7 +1112,7 @@ func testDspRplActions(t *testing.T) { allEngine.stopEngine(t) // Get Actions - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActions, argsActions, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActions, argsActions, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -1119,14 +1120,14 @@ func testDspRplActions(t *testing.T) { allEngine.startEngine(t) // Remove Actions - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveActions, argsActions, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveActions, argsActions, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get Actions - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActions, argsActions, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActions, argsActions, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -1152,7 +1153,7 @@ func testDspRplActionPlan(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetActionPlan, setActionPlan, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetActionPlan, setActionPlan, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetActionPlan: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -1166,7 +1167,7 @@ func testDspRplActionPlan(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetActionPlan: ", err) } else if reply.Id != setActionPlan.Ats.Id { t.Errorf("Expecting: %+v, received: %+v", setActionPlan.Ats.Id, reply.Id) @@ -1175,7 +1176,7 @@ func testDspRplActionPlan(t *testing.T) { allEngine.stopEngine(t) // Get ActionPlan - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -1183,14 +1184,14 @@ func testDspRplActionPlan(t *testing.T) { allEngine.startEngine(t) // Remove ActionPlan - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveActionPlan, argsActionPlan, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveActionPlan, argsActionPlan, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get ActionPlan - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetActionPlan, argsActionPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -1206,7 +1207,7 @@ func testDspRplAccountActionPlans(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetAccountActionPlans, setAccountActionPlans, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetAccountActionPlans, setAccountActionPlans, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetAccountActionPlans: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -1220,7 +1221,7 @@ func testDspRplAccountActionPlans(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetAccountActionPlans: ", err) } else if reply[0] != setAccountActionPlans.AcntID { t.Errorf("Expecting: %+v, received: %+v", setAccountActionPlans.AcntID, reply[0]) @@ -1229,7 +1230,7 @@ func testDspRplAccountActionPlans(t *testing.T) { allEngine.stopEngine(t) // Get AccountActionPlans - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -1237,14 +1238,14 @@ func testDspRplAccountActionPlans(t *testing.T) { allEngine.startEngine(t) // Remove AccountActionPlans - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemAccountActionPlans, argsAccountActionPlans, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemAccountActionPlans, argsAccountActionPlans, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get AccountActionPlans - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetAccountActionPlans, argsAccountActionPlans, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -1265,7 +1266,7 @@ func testDspRplRatingPlan(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetRatingPlan, setRatingPlan, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetRatingPlan, setRatingPlan, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetRatingPlan: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -1279,7 +1280,7 @@ func testDspRplRatingPlan(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRatingPlan, argsRatingPlan, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingPlan, argsRatingPlan, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetRatingPlan: ", err) } else if reply.Id != setRatingPlan.Id { t.Errorf("Expecting: %+v, received: %+v", setRatingPlan.Id, reply.Id) @@ -1288,7 +1289,7 @@ func testDspRplRatingPlan(t *testing.T) { allEngine.stopEngine(t) // Get RatingPlan - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRatingPlan, argsRatingPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingPlan, argsRatingPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -1296,14 +1297,14 @@ func testDspRplRatingPlan(t *testing.T) { allEngine.startEngine(t) // Remove RatingPlan - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveRatingPlan, argsRatingPlan, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveRatingPlan, argsRatingPlan, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get RatingPlan - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRatingPlan, argsRatingPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingPlan, argsRatingPlan, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -1322,7 +1323,7 @@ func testDspRplRatingProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetRatingProfile, setRatingProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetRatingProfile, setRatingProfile, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetRatingProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -1336,7 +1337,7 @@ func testDspRplRatingProfile(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRatingProfile, argsRatingProfile, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingProfile, argsRatingProfile, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetRatingProfile: ", err) } else if reply.Id != setRatingProfile.Id { t.Errorf("Expecting: %+v, received: %+v", setRatingProfile.Id, reply.Id) @@ -1345,7 +1346,7 @@ func testDspRplRatingProfile(t *testing.T) { allEngine.stopEngine(t) // Get RatingProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRatingProfile, argsRatingProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingProfile, argsRatingProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -1353,14 +1354,14 @@ func testDspRplRatingProfile(t *testing.T) { allEngine.startEngine(t) // Remove RatingProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveRatingProfile, argsRatingProfile, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveRatingProfile, argsRatingProfile, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get RatingProfile - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRatingProfile, argsRatingProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetRatingProfile, argsRatingProfile, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -1377,7 +1378,7 @@ func testDspRplDestination(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetDestination, setDestination, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetDestination, setDestination, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetDestination: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -1391,7 +1392,7 @@ func testDspRplDestination(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetDestination, argsDestination, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, argsDestination, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetDestination: ", err) } else if reply.Id != setDestination.Id { t.Errorf("Expecting: %+v, received: %+v", setDestination.Id, reply.Id) @@ -1400,7 +1401,7 @@ func testDspRplDestination(t *testing.T) { allEngine.stopEngine(t) // Get Destination - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetDestination, argsDestination, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, argsDestination, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } @@ -1408,14 +1409,14 @@ func testDspRplDestination(t *testing.T) { allEngine.startEngine(t) // Remove Destination - if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveDestination, argsDestination, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1RemoveDestination, argsDestination, &replyStr); err != nil { t.Error(err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) } // Get Destination - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetDestination, argsDestination, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, argsDestination, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } } @@ -1432,7 +1433,7 @@ func testDspRplLoadIDs(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetLoadIDs, setLoadIDs, &replyStr); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1SetLoadIDs, setLoadIDs, &replyStr); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.SetLoadIDs: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -1446,7 +1447,7 @@ func testDspRplLoadIDs(t *testing.T) { utils.OptsAPIKey: "repl12345", }, } - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetItemLoadIDs, argsLoadIDs, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetItemLoadIDs, argsLoadIDs, &reply); err != nil { t.Error("Unexpected error when calling ReplicatorSv1.GetItemLoadIDs: ", err) } else if reflect.DeepEqual(reply, setLoadIDs) { t.Errorf("Expecting: %+v, received: %+v", setLoadIDs, reply) @@ -1459,7 +1460,7 @@ func testDspRplLoadIDs(t *testing.T) { allEngine.stopEngine(t) // Get LoadIDs - if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetItemLoadIDs, argsLoadIDs, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dispEngine.RPC.Call(context.Background(), utils.ReplicatorSv1GetItemLoadIDs, argsLoadIDs, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err) } diff --git a/dispatchers/replicator_test.go b/dispatchers/replicator_test.go index 7e56d5338..5a090ed99 100644 --- a/dispatchers/replicator_test.go +++ b/dispatchers/replicator_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -31,7 +32,7 @@ func TestDspReplicatorSv1PingNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *string - result := dspSrv.ReplicatorSv1Ping(nil, reply) + result := dspSrv.ReplicatorSv1Ping(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -46,7 +47,7 @@ func TestDspReplicatorSv1PingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1Ping(CGREvent, reply) + result := dspSrv.ReplicatorSv1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -60,7 +61,7 @@ func TestDspReplicatorSv1PingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1Ping(CGREvent, reply) + result := dspSrv.ReplicatorSv1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -72,7 +73,7 @@ func TestDspReplicatorSv1GetAccountNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *engine.Account - result := dspSrv.ReplicatorSv1GetAccount(nil, reply) + result := dspSrv.ReplicatorSv1GetAccount(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -87,7 +88,7 @@ func TestDspReplicatorSv1GetAccountNil(t *testing.T) { Tenant: "tenant", } var reply *engine.Account - result := dspSrv.ReplicatorSv1GetAccount(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetAccount(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -101,7 +102,7 @@ func TestDspReplicatorSv1GetAccountErrorNil(t *testing.T) { Tenant: "tenant", } var reply *engine.Account - result := dspSrv.ReplicatorSv1GetAccount(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetAccount(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -114,7 +115,7 @@ func TestDspReplicatorSv1GetDestinationNilEvent(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *engine.Destination - result := dspSrv.ReplicatorSv1GetDestination(nil, reply) + result := dspSrv.ReplicatorSv1GetDestination(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -129,7 +130,7 @@ func TestDspReplicatorSv1GetDestinationNil(t *testing.T) { Tenant: "tenant", } var reply *engine.Destination - result := dspSrv.ReplicatorSv1GetDestination(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetDestination(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -143,7 +144,7 @@ func TestDspReplicatorSv1GetDestinationErrorNil(t *testing.T) { Tenant: "tenant", } var reply *engine.Destination - result := dspSrv.ReplicatorSv1GetDestination(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetDestination(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -155,7 +156,7 @@ func TestDspReplicatorSv1GetReverseDestinationNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *[]string - result := dspSrv.ReplicatorSv1GetReverseDestination(nil, reply) + result := dspSrv.ReplicatorSv1GetReverseDestination(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -170,7 +171,7 @@ func TestDspReplicatorSv1GetReverseDestinationNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.ReplicatorSv1GetReverseDestination(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetReverseDestination(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -184,7 +185,7 @@ func TestDspReplicatorSv1GetReverseDestinationErrorNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.ReplicatorSv1GetReverseDestination(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetReverseDestination(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -201,7 +202,7 @@ func TestDspReplicatorSv1GetStatQueueNil(t *testing.T) { }, } var reply *engine.StatQueue - result := dspSrv.ReplicatorSv1GetStatQueue(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetStatQueue(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -217,7 +218,7 @@ func TestDspReplicatorSv1GetStatQueueErrorNil(t *testing.T) { }, } var reply *engine.StatQueue - result := dspSrv.ReplicatorSv1GetStatQueue(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetStatQueue(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -234,7 +235,7 @@ func TestDspReplicatorSv1GetFilterNil(t *testing.T) { }, } var reply *engine.Filter - result := dspSrv.ReplicatorSv1GetFilter(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetFilter(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -250,7 +251,7 @@ func TestDspReplicatorSv1GetFilterErrorNil(t *testing.T) { }, } var reply *engine.Filter - result := dspSrv.ReplicatorSv1GetFilter(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetFilter(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -267,7 +268,7 @@ func TestDspReplicatorSv1GetThresholdNil(t *testing.T) { }, } var reply *engine.Threshold - result := dspSrv.ReplicatorSv1GetThreshold(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetThreshold(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -283,7 +284,7 @@ func TestDspReplicatorSv1GetThresholdErrorNil(t *testing.T) { }, } var reply *engine.Threshold - result := dspSrv.ReplicatorSv1GetThreshold(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetThreshold(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -300,7 +301,7 @@ func TestDspReplicatorSv1GetThresholdProfileNil(t *testing.T) { }, } var reply *engine.ThresholdProfile - result := dspSrv.ReplicatorSv1GetThresholdProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetThresholdProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -316,7 +317,7 @@ func TestDspReplicatorSv1GetThresholdProfileErrorNil(t *testing.T) { }, } var reply *engine.ThresholdProfile - result := dspSrv.ReplicatorSv1GetThresholdProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetThresholdProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -333,7 +334,7 @@ func TestDspReplicatorSv1GetStatQueueProfileNil(t *testing.T) { }, } var reply *engine.StatQueueProfile - result := dspSrv.ReplicatorSv1GetStatQueueProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetStatQueueProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -349,7 +350,7 @@ func TestDspReplicatorSv1GetStatQueueProfileErrorNil(t *testing.T) { }, } var reply *engine.StatQueueProfile - result := dspSrv.ReplicatorSv1GetStatQueueProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetStatQueueProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -361,7 +362,7 @@ func TestDspReplicatorSv1GetTimingNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *utils.TPTiming - result := dspSrv.ReplicatorSv1GetTiming(nil, reply) + result := dspSrv.ReplicatorSv1GetTiming(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -376,7 +377,7 @@ func TestDspReplicatorSv1GetTimingNil(t *testing.T) { Tenant: "tenant", } var reply *utils.TPTiming - result := dspSrv.ReplicatorSv1GetTiming(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetTiming(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -390,7 +391,7 @@ func TestDspReplicatorSv1GetTimingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *utils.TPTiming - result := dspSrv.ReplicatorSv1GetTiming(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetTiming(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -407,7 +408,7 @@ func TestDspReplicatorSv1GetResourceNil(t *testing.T) { }, } var reply *engine.Resource - result := dspSrv.ReplicatorSv1GetResource(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetResource(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -423,7 +424,7 @@ func TestDspReplicatorSv1GetResourceErrorNil(t *testing.T) { }, } var reply *engine.Resource - result := dspSrv.ReplicatorSv1GetResource(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetResource(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -440,7 +441,7 @@ func TestDspReplicatorSv1GetResourceProfileReplicatorSv1GetResourceProfileNil(t }, } var reply *engine.ResourceProfile - result := dspSrv.ReplicatorSv1GetResourceProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetResourceProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -456,7 +457,7 @@ func TestDspReplicatorSv1GetResourceProfileErrorNil(t *testing.T) { }, } var reply *engine.ResourceProfile - result := dspSrv.ReplicatorSv1GetResourceProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetResourceProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -468,7 +469,7 @@ func TestDspReplicatorSv1GetActionTriggersNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *engine.ActionTriggers - result := dspSrv.ReplicatorSv1GetActionTriggers(nil, reply) + result := dspSrv.ReplicatorSv1GetActionTriggers(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -483,7 +484,7 @@ func TestDspReplicatorSv1GetActionTriggersNil(t *testing.T) { Tenant: "tenant", } var reply *engine.ActionTriggers - result := dspSrv.ReplicatorSv1GetActionTriggers(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetActionTriggers(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -497,7 +498,7 @@ func TestDspReplicatorSv1GetActionTriggersErrorNil(t *testing.T) { Tenant: "tenant", } var reply *engine.ActionTriggers - result := dspSrv.ReplicatorSv1GetActionTriggers(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetActionTriggers(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -509,7 +510,7 @@ func TestDspReplicatorSv1GetSharedGroupNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *engine.SharedGroup - result := dspSrv.ReplicatorSv1GetSharedGroup(nil, reply) + result := dspSrv.ReplicatorSv1GetSharedGroup(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -524,7 +525,7 @@ func TestDspReplicatorSv1GetSharedGroupNil(t *testing.T) { Tenant: "tenant", } var reply *engine.SharedGroup - result := dspSrv.ReplicatorSv1GetSharedGroup(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetSharedGroup(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -538,7 +539,7 @@ func TestDspReplicatorSv1GetSharedGroupErrorNil(t *testing.T) { Tenant: "tenant", } var reply *engine.SharedGroup - result := dspSrv.ReplicatorSv1GetSharedGroup(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetSharedGroup(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -550,7 +551,7 @@ func TestDspReplicatorSv1GetActionsNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *engine.Actions - result := dspSrv.ReplicatorSv1GetActions(nil, reply) + result := dspSrv.ReplicatorSv1GetActions(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -565,7 +566,7 @@ func TestDspReplicatorSv1GetActionsNil(t *testing.T) { Tenant: "tenant", } var reply *engine.Actions - result := dspSrv.ReplicatorSv1GetActions(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetActions(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -576,7 +577,7 @@ func TestDspReplicatorSv1GetActionsErrorNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *engine.Actions - result := dspSrv.ReplicatorSv1GetActions(nil, reply) + result := dspSrv.ReplicatorSv1GetActions(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -590,7 +591,7 @@ func TestDspReplicatorSv1GetActionsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *engine.Actions - result := dspSrv.ReplicatorSv1GetActions(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetActions(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -605,7 +606,7 @@ func TestDspReplicatorSv1GetActionPlanNil(t *testing.T) { Tenant: "tenant", } var reply *engine.ActionPlan - result := dspSrv.ReplicatorSv1GetActionPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetActionPlan(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -616,7 +617,7 @@ func TestDspReplicatorSv1GetActionPlanErrorNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *engine.ActionPlan - result := dspSrv.ReplicatorSv1GetActionPlan(nil, reply) + result := dspSrv.ReplicatorSv1GetActionPlan(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -630,7 +631,7 @@ func TestDspReplicatorSv1GetActionPlanErrorNil(t *testing.T) { Tenant: "tenant", } var reply *engine.ActionPlan - result := dspSrv.ReplicatorSv1GetActionPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetActionPlan(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -642,7 +643,7 @@ func TestDspReplicatorSv1GetAllActionPlansNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *map[string]*engine.ActionPlan - result := dspSrv.ReplicatorSv1GetAllActionPlans(nil, reply) + result := dspSrv.ReplicatorSv1GetAllActionPlans(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -657,7 +658,7 @@ func TestDspReplicatorSv1GetAllActionPlansNil(t *testing.T) { Tenant: "tenant", } var reply *map[string]*engine.ActionPlan - result := dspSrv.ReplicatorSv1GetAllActionPlans(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetAllActionPlans(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -671,7 +672,7 @@ func TestDspReplicatorSv1GetAllActionPlansErrorNil(t *testing.T) { Tenant: "tenant", } var reply *map[string]*engine.ActionPlan - result := dspSrv.ReplicatorSv1GetAllActionPlans(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetAllActionPlans(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -683,7 +684,7 @@ func TestDspReplicatorSv1GetAccountActionPlansNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *[]string - result := dspSrv.ReplicatorSv1GetAccountActionPlans(nil, reply) + result := dspSrv.ReplicatorSv1GetAccountActionPlans(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -698,7 +699,7 @@ func TestDspReplicatorSv1GetAccountActionPlansNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.ReplicatorSv1GetAccountActionPlans(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetAccountActionPlans(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -712,7 +713,7 @@ func TestDspReplicatorSv1GetAccountActionPlansErrorNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.ReplicatorSv1GetAccountActionPlans(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetAccountActionPlans(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -725,7 +726,7 @@ func TestDspReplicatorSv1GetRatingPlanNilEvent(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *engine.RatingPlan - result := dspSrv.ReplicatorSv1GetRatingPlan(nil, reply) + result := dspSrv.ReplicatorSv1GetRatingPlan(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -740,7 +741,7 @@ func TestDspReplicatorSv1GetRatingPlanNil(t *testing.T) { Tenant: "tenant", } var reply *engine.RatingPlan - result := dspSrv.ReplicatorSv1GetRatingPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetRatingPlan(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -754,7 +755,7 @@ func TestDspReplicatorSv1GetRatingPlanErrorNil(t *testing.T) { Tenant: "tenant", } var reply *engine.RatingPlan - result := dspSrv.ReplicatorSv1GetRatingPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetRatingPlan(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -766,7 +767,7 @@ func TestDspReplicatorSv1GetRatingProfileNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *engine.RatingProfile - result := dspSrv.ReplicatorSv1GetRatingProfile(nil, reply) + result := dspSrv.ReplicatorSv1GetRatingProfile(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -781,7 +782,7 @@ func TestDspReplicatorSv1GetRatingProfileNil(t *testing.T) { Tenant: "tenant", } var reply *engine.RatingProfile - result := dspSrv.ReplicatorSv1GetRatingProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetRatingProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -795,7 +796,7 @@ func TestDspReplicatorSv1GetRatingProfileErrorNil(t *testing.T) { Tenant: "tenant", } var reply *engine.RatingProfile - result := dspSrv.ReplicatorSv1GetRatingProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetRatingProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -812,7 +813,7 @@ func TestDspReplicatorSv1GetRouteProfileNil(t *testing.T) { }, } var reply *engine.RouteProfile - result := dspSrv.ReplicatorSv1GetRouteProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetRouteProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -828,7 +829,7 @@ func TestDspReplicatorSv1GetRouteProfileErrorNil(t *testing.T) { }, } var reply *engine.RouteProfile - result := dspSrv.ReplicatorSv1GetRouteProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetRouteProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -845,7 +846,7 @@ func TestDspReplicatorSv1GetAttributeProfileNil(t *testing.T) { }, } var reply *engine.AttributeProfile - result := dspSrv.ReplicatorSv1GetAttributeProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetAttributeProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -861,7 +862,7 @@ func TestDspReplicatorSv1GetAttributeProfileErrorNil(t *testing.T) { }, } var reply *engine.AttributeProfile - result := dspSrv.ReplicatorSv1GetAttributeProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetAttributeProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -878,7 +879,7 @@ func TestDspReplicatorSv1GetChargerProfileNil(t *testing.T) { }, } var reply *engine.ChargerProfile - result := dspSrv.ReplicatorSv1GetChargerProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetChargerProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -894,7 +895,7 @@ func TestDspReplicatorSv1GetChargerProfileErrorNil(t *testing.T) { }, } var reply *engine.ChargerProfile - result := dspSrv.ReplicatorSv1GetChargerProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetChargerProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -911,7 +912,7 @@ func TestDspReplicatorSv1GetDispatcherProfileNil(t *testing.T) { }, } var reply *engine.DispatcherProfile - result := dspSrv.ReplicatorSv1GetDispatcherProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetDispatcherProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -927,7 +928,7 @@ func TestDspReplicatorSv1GetDispatcherProfileErrorNil(t *testing.T) { }, } var reply *engine.DispatcherProfile - result := dspSrv.ReplicatorSv1GetDispatcherProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetDispatcherProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -944,7 +945,7 @@ func TestDspReplicatorSv1GetDispatcherHostNil(t *testing.T) { }, } var reply *engine.DispatcherHost - result := dspSrv.ReplicatorSv1GetDispatcherHost(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetDispatcherHost(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -960,7 +961,7 @@ func TestDspReplicatorSv1GetDispatcherHostErrorNil(t *testing.T) { }, } var reply *engine.DispatcherHost - result := dspSrv.ReplicatorSv1GetDispatcherHost(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetDispatcherHost(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -972,7 +973,7 @@ func TestDspReplicatorSv1GetItemLoadIDsNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *map[string]int64 - result := dspSrv.ReplicatorSv1GetItemLoadIDs(nil, reply) + result := dspSrv.ReplicatorSv1GetItemLoadIDs(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -987,7 +988,7 @@ func TestDspReplicatorSv1GetItemLoadIDsNil(t *testing.T) { Tenant: "tenant", } var reply *map[string]int64 - result := dspSrv.ReplicatorSv1GetItemLoadIDs(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetItemLoadIDs(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1001,7 +1002,7 @@ func TestDspReplicatorSv1GetItemLoadIDsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *map[string]int64 - result := dspSrv.ReplicatorSv1GetItemLoadIDs(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetItemLoadIDs(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1018,7 +1019,7 @@ func TestDspReplicatorSv1SetThresholdProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetThresholdProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetThresholdProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1034,7 +1035,7 @@ func TestDspReplicatorSv1SetThresholdProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetThresholdProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetThresholdProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1045,7 +1046,7 @@ func TestDspReplicatorSv1SetThresholdProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetThresholdProfile(nil, reply) + result := dspSrv.ReplicatorSv1SetThresholdProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1062,7 +1063,7 @@ func TestDspReplicatorSv1SetThresholdNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetThreshold(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetThreshold(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1078,7 +1079,7 @@ func TestDspReplicatorSv1SetThresholdErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetThreshold(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetThreshold(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1089,7 +1090,7 @@ func TestDspReplicatorSv1SetThresholdNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetThreshold(nil, reply) + result := dspSrv.ReplicatorSv1SetThreshold(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1104,7 +1105,7 @@ func TestDspReplicatorSv1SetDestinationNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetDestination(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetDestination(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1118,7 +1119,7 @@ func TestDspReplicatorSv1SetDestinationErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetDestination(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetDestination(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1129,7 +1130,7 @@ func TestDspReplicatorSv1SetDestinationNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetDestination(nil, reply) + result := dspSrv.ReplicatorSv1SetDestination(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1144,7 +1145,7 @@ func TestDspReplicatorSv1SetAccountNil(t *testing.T) { Account: &engine.Account{}, } var reply *string - result := dspSrv.ReplicatorSv1SetAccount(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetAccount(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1160,7 +1161,7 @@ func TestDspReplicatorSv1SetAccountErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetAccount(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetAccount(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1171,7 +1172,7 @@ func TestDspReplicatorSv1SetAccountNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetAccount(nil, reply) + result := dspSrv.ReplicatorSv1SetAccount(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1188,7 +1189,7 @@ func TestDspReplicatorSv1SetReverseDestinationNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetReverseDestination(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetReverseDestination(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1204,7 +1205,7 @@ func TestDspReplicatorSv1SetReverseDestinationErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetReverseDestination(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetReverseDestination(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1215,7 +1216,7 @@ func TestDspReplicatorSv1SetReverseDestinationNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetReverseDestination(nil, reply) + result := dspSrv.ReplicatorSv1SetReverseDestination(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1232,7 +1233,7 @@ func TestDspReplicatorSv1SetStatQueueNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetStatQueue(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetStatQueue(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1248,7 +1249,7 @@ func TestDspReplicatorSv1SetStatQueueErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetStatQueue(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetStatQueue(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1259,7 +1260,7 @@ func TestDspReplicatorSv1SetStatQueueNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetStatQueue(nil, reply) + result := dspSrv.ReplicatorSv1SetStatQueue(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1276,7 +1277,7 @@ func TestDspReplicatorSv1SetFilterNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetFilter(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetFilter(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1292,7 +1293,7 @@ func TestDspReplicatorSv1SetFilterErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetFilter(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetFilter(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1303,7 +1304,7 @@ func TestDspReplicatorSv1SetFilterNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetFilter(nil, reply) + result := dspSrv.ReplicatorSv1SetFilter(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1320,7 +1321,7 @@ func TestDspReplicatorSv1SetStatQueueProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetStatQueueProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetStatQueueProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1336,7 +1337,7 @@ func TestDspReplicatorSv1SetStatQueueProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetStatQueueProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetStatQueueProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1347,7 +1348,7 @@ func TestDspReplicatorSv1SetStatQueueProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetStatQueueProfile(nil, reply) + result := dspSrv.ReplicatorSv1SetStatQueueProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1362,7 +1363,7 @@ func TestDspReplicatorSv1SetTimingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetTiming(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetTiming(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1376,7 +1377,7 @@ func TestDspReplicatorSv1SetTimingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetTiming(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetTiming(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1387,7 +1388,7 @@ func TestDspReplicatorSv1SetTimingNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetTiming(nil, reply) + result := dspSrv.ReplicatorSv1SetTiming(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1404,7 +1405,7 @@ func TestDspReplicatorSv1SetResourceNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetResource(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetResource(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1420,7 +1421,7 @@ func TestDspReplicatorSv1SetResourceErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetResource(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetResource(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1431,7 +1432,7 @@ func TestDspReplicatorSv1SetResourceNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetResource(nil, reply) + result := dspSrv.ReplicatorSv1SetResource(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1448,7 +1449,7 @@ func TestDspReplicatorSv1SetResourceProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetResourceProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetResourceProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1464,7 +1465,7 @@ func TestReplicatorSv1SetResourceProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetResourceProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetResourceProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1475,7 +1476,7 @@ func TestDspReplicatorSv1SetResourceProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetResourceProfile(nil, reply) + result := dspSrv.ReplicatorSv1SetResourceProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1490,7 +1491,7 @@ func TestDspReplicatorSv1SetSharedGroupNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetSharedGroup(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetSharedGroup(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1504,7 +1505,7 @@ func TestReplicatorSv1SetSharedGroupErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetSharedGroup(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetSharedGroup(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1515,7 +1516,7 @@ func TestDspReplicatorSv1SetSharedGroupNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetSharedGroup(nil, reply) + result := dspSrv.ReplicatorSv1SetSharedGroup(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1530,7 +1531,7 @@ func TestDspReplicatorSv1SetActionsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetActions(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetActions(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1544,7 +1545,7 @@ func TestReplicatorSv1SetActionsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetActions(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetActions(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1555,7 +1556,7 @@ func TestDspReplicatorSv1SetActionsNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetActions(nil, reply) + result := dspSrv.ReplicatorSv1SetActions(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1570,7 +1571,7 @@ func TestDspReplicatorSv1SetRatingProfileNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetRatingProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetRatingProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1584,7 +1585,7 @@ func TestReplicatorSv1SetRatingProfileErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetRatingProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetRatingProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1595,7 +1596,7 @@ func TestDspReplicatorSv1SetRatingProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetRatingProfile(nil, reply) + result := dspSrv.ReplicatorSv1SetRatingProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1610,7 +1611,7 @@ func TestDspReplicatorSv1SetRatingPlanNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetRatingPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetRatingPlan(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1624,7 +1625,7 @@ func TestDspReplicatorSv1SetRatingPlanErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetRatingPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetRatingPlan(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1635,7 +1636,7 @@ func TestDspReplicatorSv1SetRatingPlanNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetRatingPlan(nil, reply) + result := dspSrv.ReplicatorSv1SetRatingPlan(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1650,7 +1651,7 @@ func TestDspReplicatorSv1SetActionTriggersNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetActionTriggers(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetActionTriggers(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1664,7 +1665,7 @@ func TestDspReplicatorSv1SetActionTriggersErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetActionTriggers(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetActionTriggers(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1675,7 +1676,7 @@ func TestDspReplicatorSv1SetActionTriggersNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetActionTriggers(nil, reply) + result := dspSrv.ReplicatorSv1SetActionTriggers(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1692,7 +1693,7 @@ func TestDspReplicatorSv1SetRouteProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetRouteProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetRouteProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1708,7 +1709,7 @@ func TestDspReplicatorSv1SetRouteProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetRouteProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetRouteProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1719,7 +1720,7 @@ func TestDspReplicatorSv1SetRouteProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetRouteProfile(nil, reply) + result := dspSrv.ReplicatorSv1SetRouteProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1736,7 +1737,7 @@ func TestDspReplicatorSv1SetAttributeProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetAttributeProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetAttributeProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1752,7 +1753,7 @@ func TestDspReplicatorSv1SetAttributeProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetAttributeProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetAttributeProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1763,7 +1764,7 @@ func TestDspReplicatorSv1SetAttributeProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetAttributeProfile(nil, reply) + result := dspSrv.ReplicatorSv1SetAttributeProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1780,7 +1781,7 @@ func TestDspReplicatorSv1SetChargerProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetChargerProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetChargerProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1796,7 +1797,7 @@ func TestDspReplicatorSv1SetChargerProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetChargerProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetChargerProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1807,7 +1808,7 @@ func TestDspReplicatorSv1SetChargerProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetChargerProfile(nil, reply) + result := dspSrv.ReplicatorSv1SetChargerProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1824,7 +1825,7 @@ func TestDspReplicatorSv1SetDispatcherProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetDispatcherProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetDispatcherProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1840,7 +1841,7 @@ func TestDspReplicatorSv1SetDispatcherProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetDispatcherProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetDispatcherProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1851,7 +1852,7 @@ func TestDspReplicatorSv1SetDispatcherProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetDispatcherProfile(nil, reply) + result := dspSrv.ReplicatorSv1SetDispatcherProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1866,7 +1867,7 @@ func TestDspReplicatorSv1SetActionPlanNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetActionPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetActionPlan(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1880,7 +1881,7 @@ func TestDspReplicatorSv1SetActionPlanErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetActionPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetActionPlan(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1891,7 +1892,7 @@ func TestDspReplicatorSv1SetActionPlanNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetActionPlan(nil, reply) + result := dspSrv.ReplicatorSv1SetActionPlan(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1906,7 +1907,7 @@ func TestDspReplicatorSv1SetAccountActionPlansNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetAccountActionPlans(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetAccountActionPlans(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1920,7 +1921,7 @@ func TestDspReplicatorSv1SetAccountActionPlansErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetAccountActionPlans(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetAccountActionPlans(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1931,7 +1932,7 @@ func TestDspReplicatorSv1SetAccountActionPlansNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetAccountActionPlans(nil, reply) + result := dspSrv.ReplicatorSv1SetAccountActionPlans(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1948,7 +1949,7 @@ func TestDspReplicatorSv1SetDispatcherHostNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetDispatcherHost(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetDispatcherHost(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1964,7 +1965,7 @@ func TestReplicatorSv1SetDispatcherHostErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1SetDispatcherHost(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetDispatcherHost(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1975,7 +1976,7 @@ func TestDspReplicatorSv1SetDispatcherHostNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetDispatcherHost(nil, reply) + result := dspSrv.ReplicatorSv1SetDispatcherHost(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -1992,7 +1993,7 @@ func TestDspReplicatorSv1RemoveThresholdNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveThreshold(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveThreshold(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2008,7 +2009,7 @@ func TestReplicatorSv1RemoveThresholdErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveThreshold(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveThreshold(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2019,7 +2020,7 @@ func TestDspReplicatorSv1RemoveDestinationNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveDestination(nil, reply) + result := dspSrv.ReplicatorSv1RemoveDestination(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2034,7 +2035,7 @@ func TestDspReplicatorSv1RemoveDestinationNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveDestination(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveDestination(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2048,7 +2049,7 @@ func TestReplicatorSv1RemoveDestinationErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveDestination(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveDestination(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2063,7 +2064,7 @@ func TestDspReplicatorSv1SetLoadIDsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetLoadIDs(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetLoadIDs(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2077,7 +2078,7 @@ func TestDspReplicatorSv1SetLoadIDsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetLoadIDs(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetLoadIDs(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2088,7 +2089,7 @@ func TestDspReplicatorSv1SetLoadIDsNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetLoadIDs(nil, reply) + result := dspSrv.ReplicatorSv1SetLoadIDs(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2103,7 +2104,7 @@ func TestDspReplicatorSv1RemoveAccountNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveAccount(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveAccount(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2117,7 +2118,7 @@ func TestDspReplicatorSv1RemoveAccountErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveAccount(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveAccount(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2128,7 +2129,7 @@ func TestDspReplicatorSv1RemoveAccountNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveAccount(nil, reply) + result := dspSrv.ReplicatorSv1RemoveAccount(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2145,7 +2146,7 @@ func TestDspReplicatorSv1RemoveStatQueueNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveStatQueue(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveStatQueue(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2161,7 +2162,7 @@ func TestDspReplicatorSv1RemoveStatQueueErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveStatQueue(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveStatQueue(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2172,7 +2173,7 @@ func TestDspReplicatorSv1RemoveStatQueueNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveStatQueue(nil, reply) + result := dspSrv.ReplicatorSv1RemoveStatQueue(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2183,7 +2184,7 @@ func TestDspReplicatorSv1RemoveThresholdNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveThreshold(nil, reply) + result := dspSrv.ReplicatorSv1RemoveThreshold(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2200,7 +2201,7 @@ func TestDspReplicatorSv1RemoveFilterNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveFilter(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveFilter(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2216,7 +2217,7 @@ func TestDspReplicatorSv1RemoveFilterErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveFilter(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveFilter(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2227,7 +2228,7 @@ func TestDspReplicatorSv1RemoveFilterNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveFilter(nil, reply) + result := dspSrv.ReplicatorSv1RemoveFilter(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2244,7 +2245,7 @@ func TestDspReplicatorSv1RemoveThresholdProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveThresholdProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveThresholdProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2260,7 +2261,7 @@ func TestDspReplicatorSv1RemoveThresholdProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveThresholdProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveThresholdProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2271,7 +2272,7 @@ func TestDspReplicatorSv1RemoveThresholdProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveThresholdProfile(nil, reply) + result := dspSrv.ReplicatorSv1RemoveThresholdProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2288,7 +2289,7 @@ func TestDspReplicatorSv1RemoveStatQueueProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveStatQueueProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveStatQueueProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2304,7 +2305,7 @@ func TestDspReplicatorSv1RemoveStatQueueProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveStatQueueProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveStatQueueProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2315,7 +2316,7 @@ func TestDspReplicatorSv1RemoveStatQueueProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveStatQueueProfile(nil, reply) + result := dspSrv.ReplicatorSv1RemoveStatQueueProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2332,7 +2333,7 @@ func TestDspReplicatorSv1RemoveResourceNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveResource(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveResource(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2348,7 +2349,7 @@ func TestDspReplicatorSv1RemoveResourceErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveResource(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveResource(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2359,7 +2360,7 @@ func TestDspReplicatorSv1RemoveResourceNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveResource(nil, reply) + result := dspSrv.ReplicatorSv1RemoveResource(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2376,7 +2377,7 @@ func TestDspReplicatorSv1RemoveResourceProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveResourceProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveResourceProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2392,7 +2393,7 @@ func TestDspReplicatorSv1RemoveResourceProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveResourceProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveResourceProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2403,7 +2404,7 @@ func TestDspReplicatorSv1RemoveResourceProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveResourceProfile(nil, reply) + result := dspSrv.ReplicatorSv1RemoveResourceProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2418,7 +2419,7 @@ func TestDspReplicatorSv1RemoveTimingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveTiming(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveTiming(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2432,7 +2433,7 @@ func TestDspReplicatorSv1RemoveTimingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveTiming(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveTiming(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2443,7 +2444,7 @@ func TestDspReplicatorSv1RemoveTimingNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveTiming(nil, reply) + result := dspSrv.ReplicatorSv1RemoveTiming(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2458,7 +2459,7 @@ func TestDspReplicatorSv1RemoveActionTriggersNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveActionTriggers(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveActionTriggers(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2472,7 +2473,7 @@ func TestDspReplicatorSv1RemoveActionTriggersErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveActionTriggers(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveActionTriggers(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2483,7 +2484,7 @@ func TestDspReplicatorSv1RemoveActionTriggersNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveActionTriggers(nil, reply) + result := dspSrv.ReplicatorSv1RemoveActionTriggers(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2498,7 +2499,7 @@ func TestDspReplicatorSv1RemoveSharedGroupNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveSharedGroup(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveSharedGroup(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2512,7 +2513,7 @@ func TestDspReplicatorSv1RemoveSharedGroupErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveSharedGroup(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveSharedGroup(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2523,7 +2524,7 @@ func TestDspReplicatorSv1RemoveSharedGroupNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveSharedGroup(nil, reply) + result := dspSrv.ReplicatorSv1RemoveSharedGroup(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2538,7 +2539,7 @@ func TestDspReplicatorSv1RemoveActionsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveActions(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveActions(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2552,7 +2553,7 @@ func TestDspReplicatorSv1RemoveActionsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveActions(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveActions(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2563,7 +2564,7 @@ func TestDspReplicatorSv1RemoveActionsEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveActions(nil, reply) + result := dspSrv.ReplicatorSv1RemoveActions(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2578,7 +2579,7 @@ func TestDspReplicatorSv1RemoveActionPlanNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveActionPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveActionPlan(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2592,7 +2593,7 @@ func TestDspReplicatorSv1RemoveActionPlanErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveActionPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveActionPlan(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2603,7 +2604,7 @@ func TestDspReplicatorSv1RemoveActionPlanNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveActionPlan(nil, reply) + result := dspSrv.ReplicatorSv1RemoveActionPlan(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2617,7 +2618,7 @@ func TestDspReplicatorSv1RemAccountActionPlansNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemAccountActionPlans(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemAccountActionPlans(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2631,7 +2632,7 @@ func TestDspReplicatorSv1RemAccountActionPlansErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemAccountActionPlans(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemAccountActionPlans(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2642,7 +2643,7 @@ func TestDspReplicatorSv1RemAccountActionPlansNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemAccountActionPlans(nil, reply) + result := dspSrv.ReplicatorSv1RemAccountActionPlans(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2657,7 +2658,7 @@ func TestDspReplicatorSv1RemoveRatingPlanNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveRatingPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveRatingPlan(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2671,7 +2672,7 @@ func TestDspReplicatorSv1RemoveRatingPlanErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveRatingPlan(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveRatingPlan(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2682,7 +2683,7 @@ func TestDspReplicatorSv1RemoveRatingPlanNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveRatingPlan(nil, reply) + result := dspSrv.ReplicatorSv1RemoveRatingPlan(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2697,7 +2698,7 @@ func TestDspReplicatorSv1RemoveRatingProfileNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveRatingProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveRatingProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2711,7 +2712,7 @@ func TestDspReplicatorSv1RemoveRatingProfileErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveRatingProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveRatingProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2722,7 +2723,7 @@ func TestDspReplicatorSv1RemoveRatingProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveRatingProfile(nil, reply) + result := dspSrv.ReplicatorSv1RemoveRatingProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2739,7 +2740,7 @@ func TestDspReplicatorSv1RemoveRouteProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveRouteProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveRouteProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2755,7 +2756,7 @@ func TestDspReplicatorSv1RemoveRouteProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveRouteProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveRouteProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2766,7 +2767,7 @@ func TestDspReplicatorSv1RemoveRouteProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveRouteProfile(nil, reply) + result := dspSrv.ReplicatorSv1RemoveRouteProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2783,7 +2784,7 @@ func TestDspReplicatorSv1RemoveAttributeProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveAttributeProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveAttributeProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2799,7 +2800,7 @@ func TestDspReplicatorSv1RemoveAttributeProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveAttributeProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveAttributeProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2810,7 +2811,7 @@ func TestDspReplicatorSv1RemoveAttributeProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveAttributeProfile(nil, reply) + result := dspSrv.ReplicatorSv1RemoveAttributeProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2827,7 +2828,7 @@ func TestDspReplicatorSv1RemoveChargerProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveChargerProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveChargerProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2843,7 +2844,7 @@ func TestDspReplicatorSv1RemoveChargerProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveChargerProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveChargerProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2854,7 +2855,7 @@ func TestDspReplicatorSv1RemoveChargerProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveChargerProfile(nil, reply) + result := dspSrv.ReplicatorSv1RemoveChargerProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2871,7 +2872,7 @@ func TestDspReplicatorSv1RemoveDispatcherHostNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveDispatcherHost(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveDispatcherHost(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2887,7 +2888,7 @@ func TestDspReplicatorSv1RemoveDispatcherHostErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveDispatcherHost(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveDispatcherHost(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2898,7 +2899,7 @@ func TestDspReplicatorSv1RemoveDispatcherHostNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveDispatcherHost(nil, reply) + result := dspSrv.ReplicatorSv1RemoveDispatcherHost(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2915,7 +2916,7 @@ func TestDspReplicatorSv1RemoveDispatcherProfileNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveDispatcherProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveDispatcherProfile(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2931,7 +2932,7 @@ func TestDspReplicatorSv1RemoveDispatcherProfileErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.ReplicatorSv1RemoveDispatcherProfile(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveDispatcherProfile(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2942,7 +2943,7 @@ func TestDspReplicatorSv1RemoveDispatcherProfileNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveDispatcherProfile(nil, reply) + result := dspSrv.ReplicatorSv1RemoveDispatcherProfile(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2957,7 +2958,7 @@ func TestDspReplicatorSv1GetIndexesNil(t *testing.T) { Tenant: "tenant", } var reply *map[string]utils.StringSet - result := dspSrv.ReplicatorSv1GetIndexes(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetIndexes(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2971,7 +2972,7 @@ func TestDspReplicatorSv1GetIndexesErrorNil(t *testing.T) { Tenant: "tenant", } var reply *map[string]utils.StringSet - result := dspSrv.ReplicatorSv1GetIndexes(CGREvent, reply) + result := dspSrv.ReplicatorSv1GetIndexes(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2982,7 +2983,7 @@ func TestDspReplicatorSv1GetIndexesNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *map[string]utils.StringSet - result := dspSrv.ReplicatorSv1GetIndexes(nil, reply) + result := dspSrv.ReplicatorSv1GetIndexes(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -2997,7 +2998,7 @@ func TestDspReplicatorSv1SetIndexesNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetIndexes(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetIndexes(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -3011,7 +3012,7 @@ func TestDspReplicatorSv1SetIndexesErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1SetIndexes(CGREvent, reply) + result := dspSrv.ReplicatorSv1SetIndexes(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -3022,7 +3023,7 @@ func TestDspReplicatorSv1SetIndexesNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1SetIndexes(nil, reply) + result := dspSrv.ReplicatorSv1SetIndexes(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -3037,7 +3038,7 @@ func TestDspReplicatorSv1RemoveIndexesNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveIndexes(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveIndexes(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -3051,7 +3052,7 @@ func TestDspReplicatorSv1RemoveIndexesErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ReplicatorSv1RemoveIndexes(CGREvent, reply) + result := dspSrv.ReplicatorSv1RemoveIndexes(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -3062,7 +3063,7 @@ func TestDspReplicatorSv1RemoveIndexesNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ReplicatorSv1RemoveIndexes(nil, reply) + result := dspSrv.ReplicatorSv1RemoveIndexes(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/resources.go b/dispatchers/resources.go index 4d5a32737..9d142d8d8 100644 --- a/dispatchers/resources.go +++ b/dispatchers/resources.go @@ -21,11 +21,12 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) ResourceSv1Ping(args *utils.CGREvent, rpl *string) (err error) { +func (dS *DispatcherService) ResourceSv1Ping(ctx *context.Context, args *utils.CGREvent, rpl *string) (err error) { if args == nil { args = new(utils.CGREvent) } @@ -39,7 +40,7 @@ func (dS *DispatcherService) ResourceSv1Ping(args *utils.CGREvent, rpl *string) return dS.Dispatch(args, utils.MetaResources, utils.ResourceSv1Ping, args, rpl) } -func (dS *DispatcherService) ResourceSv1GetResourcesForEvent(args *utils.CGREvent, +func (dS *DispatcherService) ResourceSv1GetResourcesForEvent(ctx *context.Context, args *utils.CGREvent, reply *engine.Resources) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && args.Tenant != utils.EmptyString { @@ -54,7 +55,7 @@ func (dS *DispatcherService) ResourceSv1GetResourcesForEvent(args *utils.CGREven return dS.Dispatch(args, utils.MetaResources, utils.ResourceSv1GetResourcesForEvent, args, reply) } -func (dS *DispatcherService) ResourceSv1AuthorizeResources(args *utils.CGREvent, +func (dS *DispatcherService) ResourceSv1AuthorizeResources(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && args.Tenant != utils.EmptyString { @@ -69,7 +70,7 @@ func (dS *DispatcherService) ResourceSv1AuthorizeResources(args *utils.CGREvent, return dS.Dispatch(args, utils.MetaResources, utils.ResourceSv1AuthorizeResources, args, reply) } -func (dS *DispatcherService) ResourceSv1AllocateResources(args *utils.CGREvent, +func (dS *DispatcherService) ResourceSv1AllocateResources(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && args.Tenant != utils.EmptyString { @@ -84,7 +85,7 @@ func (dS *DispatcherService) ResourceSv1AllocateResources(args *utils.CGREvent, return dS.Dispatch(args, utils.MetaResources, utils.ResourceSv1AllocateResources, args, reply) } -func (dS *DispatcherService) ResourceSv1ReleaseResources(args *utils.CGREvent, +func (dS *DispatcherService) ResourceSv1ReleaseResources(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args != nil && args.Tenant != utils.EmptyString { @@ -99,7 +100,7 @@ func (dS *DispatcherService) ResourceSv1ReleaseResources(args *utils.CGREvent, return dS.Dispatch(args, utils.MetaResources, utils.ResourceSv1ReleaseResources, args, reply) } -func (dS *DispatcherService) ResourceSv1GetResource(args *utils.TenantIDWithAPIOpts, reply *engine.Resource) (err error) { +func (dS *DispatcherService) ResourceSv1GetResource(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.Resource) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant @@ -117,7 +118,7 @@ func (dS *DispatcherService) ResourceSv1GetResource(args *utils.TenantIDWithAPIO }, utils.MetaResources, utils.ResourceSv1GetResource, args, reply) } -func (dS *DispatcherService) ResourceSv1GetResourceWithConfig(args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) (err error) { +func (dS *DispatcherService) ResourceSv1GetResourceWithConfig(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant diff --git a/dispatchers/resources_it_test.go b/dispatchers/resources_it_test.go index d2c0c9560..ad9d7a649 100644 --- a/dispatchers/resources_it_test.go +++ b/dispatchers/resources_it_test.go @@ -25,6 +25,7 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -67,7 +68,7 @@ func TestDspResourceSIT(t *testing.T) { func testDspResPingFailover(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.ResourceSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.ResourceSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -79,19 +80,19 @@ func testDspResPingFailover(t *testing.T) { utils.OptsAPIKey: "res12345", }, } - if err := dispEngine.RPC.Call(utils.ResourceSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine.stopEngine(t) - if err := dispEngine.RPC.Call(utils.ResourceSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.ResourceSv1Ping, &ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1Ping, &ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine.startEngine(t) @@ -100,12 +101,12 @@ func testDspResPingFailover(t *testing.T) { func testDspResPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.ResourceSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.ResourceSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.ResourceSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ utils.OptsAPIKey: "res12345", @@ -132,7 +133,7 @@ func testDspResTestAuthKey(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.ResourceSv1GetResourcesForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() { t.Error(err) } @@ -160,7 +161,7 @@ func testDspResTestAuthKey2(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.ResourceSv1GetResourcesForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRs, rs) { @@ -184,7 +185,7 @@ func testDspResTestAuthKey3(t *testing.T) { utils.OptsResourcesUnits: 1, }, } - if err := dispEngine.RPC.Call(utils.ResourceSv1AllocateResources, + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } @@ -193,7 +194,7 @@ func testDspResTestAuthKey3(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", eAllocationMsg, reply) } - if err := dispEngine.RPC.Call(utils.ResourceSv1AuthorizeResources, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &ev, &reply); err != nil { t.Error(err) } else if reply != eAllocationMsg { // already 3 usages active before allow call, we should have now more than allowed t.Errorf("Expecting: %+v, received: %+v", eAllocationMsg, reply) @@ -211,7 +212,7 @@ func testDspResTestAuthKey3(t *testing.T) { utils.OptsResourcesUnits: 17, }, } - if err := dispEngine.RPC.Call(utils.ResourceSv1AuthorizeResources, + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &ev, &reply); err == nil || err.Error() != utils.ErrResourceUnauthorized.Error() { t.Error(err) } @@ -229,7 +230,7 @@ func testDspResTestAuthKey3(t *testing.T) { utils.OptsResourcesUsageID: "651a8db2-4f67-4cf8-b622-169e8a482e55", }, } - if err := dispEngine.RPC.Call(utils.ResourceSv1ReleaseResources, + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1ReleaseResources, ev, &reply); err != nil { t.Error(err) } @@ -248,7 +249,7 @@ func testDspResTestAuthKey3(t *testing.T) { utils.OptsResourcesUnits: 6, }, } - if err := dispEngine.RPC.Call(utils.ResourceSv1AuthorizeResources, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &ev, &reply); err != nil { t.Error(err) } else if reply != "ResGroup1" { t.Error("Unexpected reply returned", reply) @@ -266,7 +267,7 @@ func testDspResTestAuthKey3(t *testing.T) { utils.OptsResourcesUsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61", }, } - if err := dispEngine.RPC.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Error(err) } else if len(*rs) != 1 { t.Errorf("Resources: %+v", utils.ToJSON(rs)) @@ -292,7 +293,7 @@ func testDspResTestAuthKey3(t *testing.T) { utils.OptsAPIKey: "res12345", }, } - if err := dispEngine.RPC.Call(utils.ResourceSv1GetResource, argsGetResource, &r); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ResourceSv1GetResource, argsGetResource, &r); err != nil { t.Fatal(err) } // make sure Resource1 have no more active resources diff --git a/dispatchers/resources_test.go b/dispatchers/resources_test.go index 56bc9ff0a..762b70811 100644 --- a/dispatchers/resources_test.go +++ b/dispatchers/resources_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -31,7 +32,7 @@ func TestDspResourceSv1PingNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *string - result := dspSrv.ResourceSv1Ping(nil, reply) + result := dspSrv.ResourceSv1Ping(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -46,7 +47,7 @@ func TestDspResourceSv1PingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResourceSv1Ping(CGREvent, reply) + result := dspSrv.ResourceSv1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -60,7 +61,7 @@ func TestDspResourceSv1PingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResourceSv1Ping(CGREvent, reply) + result := dspSrv.ResourceSv1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -75,7 +76,7 @@ func TestDspResourceSv1GetResourcesForEventNil(t *testing.T) { Tenant: "tenant", } var reply *engine.Resources - result := dspSrv.ResourceSv1GetResourcesForEvent(CGREvent, reply) + result := dspSrv.ResourceSv1GetResourcesForEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -89,7 +90,7 @@ func TestDspResourceSv1GetResourcesForEventErrorNil(t *testing.T) { Tenant: "tenant", } var reply *engine.Resources - result := dspSrv.ResourceSv1GetResourcesForEvent(CGREvent, reply) + result := dspSrv.ResourceSv1GetResourcesForEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -104,7 +105,7 @@ func TestDspResourceSv1AuthorizeResourcesNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResourceSv1AuthorizeResources(CGREvent, reply) + result := dspSrv.ResourceSv1AuthorizeResources(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -118,7 +119,7 @@ func TestDspResourceSv1AuthorizeResourcesErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResourceSv1AuthorizeResources(CGREvent, reply) + result := dspSrv.ResourceSv1AuthorizeResources(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -133,7 +134,7 @@ func TestDspResourceSv1ReleaseResourcesNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResourceSv1ReleaseResources(CGREvent, reply) + result := dspSrv.ResourceSv1ReleaseResources(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -147,7 +148,7 @@ func TestDspResourceSv1ReleaseResourcesErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResourceSv1ReleaseResources(CGREvent, reply) + result := dspSrv.ResourceSv1ReleaseResources(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -164,7 +165,7 @@ func TestDspResourceSv1GetResourceNil(t *testing.T) { }, } var reply *engine.Resource - result := dspSrv.ResourceSv1GetResource(CGREvent, reply) + result := dspSrv.ResourceSv1GetResource(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -180,7 +181,7 @@ func TestDspResourceSv1GetResourceErrorNil(t *testing.T) { }, } var reply *engine.Resource - result := dspSrv.ResourceSv1GetResource(CGREvent, reply) + result := dspSrv.ResourceSv1GetResource(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -195,7 +196,7 @@ func TestDspResourceSv1AllocateResourcesNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResourceSv1AllocateResources(CGREvent, reply) + result := dspSrv.ResourceSv1AllocateResources(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -209,7 +210,7 @@ func TestDspResourceSv1AllocateResourcesErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResourceSv1AllocateResources(CGREvent, reply) + result := dspSrv.ResourceSv1AllocateResources(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -226,7 +227,7 @@ func TestDspResourceSv1GetResourceWithConfigNil(t *testing.T) { }, } var reply *engine.ResourceWithConfig - result := dspSrv.ResourceSv1GetResourceWithConfig(CGREvent, reply) + result := dspSrv.ResourceSv1GetResourceWithConfig(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -242,7 +243,7 @@ func TestDspResourceSv1GetResourceWithConfigErrorNil(t *testing.T) { }, } var reply *engine.ResourceWithConfig - result := dspSrv.ResourceSv1GetResourceWithConfig(CGREvent, reply) + result := dspSrv.ResourceSv1GetResourceWithConfig(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/responder.go b/dispatchers/responder.go index 3547bfb33..fbaa80cf2 100644 --- a/dispatchers/responder.go +++ b/dispatchers/responder.go @@ -21,12 +21,13 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) // ResponderPing interogates Responder server responsible to process the event -func (dS *DispatcherService) ResponderPing(args *utils.CGREvent, +func (dS *DispatcherService) ResponderPing(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) @@ -41,7 +42,7 @@ func (dS *DispatcherService) ResponderPing(args *utils.CGREvent, return dS.Dispatch(args, utils.MetaResponder, utils.ResponderPing, args, reply) } -func (dS *DispatcherService) ResponderGetCost(args *engine.CallDescriptorWithAPIOpts, +func (dS *DispatcherService) ResponderGetCost(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error) { if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.ResponderGetCost, args.Tenant, @@ -52,7 +53,7 @@ func (dS *DispatcherService) ResponderGetCost(args *engine.CallDescriptorWithAPI return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderGetCost, args, reply) } -func (dS *DispatcherService) ResponderDebit(args *engine.CallDescriptorWithAPIOpts, +func (dS *DispatcherService) ResponderDebit(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error) { if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.ResponderDebit, args.Tenant, @@ -63,7 +64,7 @@ func (dS *DispatcherService) ResponderDebit(args *engine.CallDescriptorWithAPIOp return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderDebit, args, reply) } -func (dS *DispatcherService) ResponderMaxDebit(args *engine.CallDescriptorWithAPIOpts, +func (dS *DispatcherService) ResponderMaxDebit(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *engine.CallCost) (err error) { if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.ResponderMaxDebit, args.Tenant, @@ -74,7 +75,7 @@ func (dS *DispatcherService) ResponderMaxDebit(args *engine.CallDescriptorWithAP return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderMaxDebit, args, reply) } -func (dS *DispatcherService) ResponderRefundIncrements(args *engine.CallDescriptorWithAPIOpts, +func (dS *DispatcherService) ResponderRefundIncrements(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *engine.Account) (err error) { if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.ResponderRefundIncrements, args.Tenant, @@ -85,7 +86,7 @@ func (dS *DispatcherService) ResponderRefundIncrements(args *engine.CallDescript return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderRefundIncrements, args, reply) } -func (dS *DispatcherService) ResponderRefundRounding(args *engine.CallDescriptorWithAPIOpts, +func (dS *DispatcherService) ResponderRefundRounding(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *engine.Account) (err error) { if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.ResponderRefundRounding, args.Tenant, @@ -96,7 +97,7 @@ func (dS *DispatcherService) ResponderRefundRounding(args *engine.CallDescriptor return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderRefundRounding, args, reply) } -func (dS *DispatcherService) ResponderGetMaxSessionTime(args *engine.CallDescriptorWithAPIOpts, +func (dS *DispatcherService) ResponderGetMaxSessionTime(ctx *context.Context, args *engine.CallDescriptorWithAPIOpts, reply *time.Duration) (err error) { if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.ResponderGetMaxSessionTime, args.Tenant, @@ -107,7 +108,7 @@ func (dS *DispatcherService) ResponderGetMaxSessionTime(args *engine.CallDescrip return dS.Dispatch(args.AsCGREvent(args.APIOpts), utils.MetaResponder, utils.ResponderGetMaxSessionTime, args, reply) } -func (dS *DispatcherService) ResponderShutdown(args *utils.TenantWithAPIOpts, +func (dS *DispatcherService) ResponderShutdown(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *string) (err error) { tnt := utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -122,7 +123,7 @@ func (dS *DispatcherService) ResponderShutdown(args *utils.TenantWithAPIOpts, }, utils.MetaResponder, utils.ResponderShutdown, args, reply) } -func (dS *DispatcherService) ResponderGetCostOnRatingPlans(arg *utils.GetCostOnRatingPlansArgs, reply *map[string]any) (err error) { +func (dS *DispatcherService) ResponderGetCostOnRatingPlans(ctx *context.Context, arg *utils.GetCostOnRatingPlansArgs, reply *map[string]any) (err error) { tnt := utils.FirstNonEmpty(arg.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.ResponderGetCostOnRatingPlans, tnt, @@ -136,7 +137,7 @@ func (dS *DispatcherService) ResponderGetCostOnRatingPlans(arg *utils.GetCostOnR }, utils.MetaResponder, utils.ResponderGetCostOnRatingPlans, arg, reply) } -func (dS *DispatcherService) ResponderGetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]any) (err error) { +func (dS *DispatcherService) ResponderGetMaxSessionTimeOnAccounts(ctx *context.Context, arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]any) (err error) { tnt := utils.FirstNonEmpty(arg.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.ResponderGetMaxSessionTimeOnAccounts, tnt, diff --git a/dispatchers/responder_it_test.go b/dispatchers/responder_it_test.go index 6c7b0e079..f50887cb0 100644 --- a/dispatchers/responder_it_test.go +++ b/dispatchers/responder_it_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" "github.com/cgrates/rpcclient" ) @@ -68,7 +69,7 @@ func TestDspResponder(t *testing.T) { func testDspResponderStatus(t *testing.T) { var reply map[string]any - if err := allEngine.RPC.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &reply); err != nil { t.Error(err) } else if reply[utils.NodeID] != "ALL" { t.Errorf("Received: %s", reply) @@ -79,13 +80,13 @@ func testDspResponderStatus(t *testing.T) { utils.OptsAPIKey: "rsp12345", }, } - if err := dispEngine.RPC.Call(utils.DispatcherSv1RemoteStatus, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.DispatcherSv1RemoteStatus, &ev, &reply); err != nil { t.Error(err) } else if reply[utils.NodeID] != "ALL" { t.Errorf("Received: %s", utils.ToJSON(reply)) } allEngine.stopEngine(t) - if err := dispEngine.RPC.Call(utils.DispatcherSv1RemoteStatus, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.DispatcherSv1RemoteStatus, &ev, &reply); err != nil { t.Error(err) } else if reply[utils.NodeID] != "ALL2" { t.Errorf("Received: %s", utils.ToJSON(reply)) @@ -115,12 +116,12 @@ func getNodeWithRoute(route string, t *testing.T) string { }, } - if err := dispEngine.RPC.Call(utils.DispatcherSv1RemotePing, pingEv, &pingReply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.DispatcherSv1RemotePing, pingEv, &pingReply); err != nil { t.Error(err) } else if pingReply != utils.Pong { t.Errorf("Received: %s", pingReply) } - if err := dispEngine.RPC.Call(utils.DispatcherSv1RemoteStatus, ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.DispatcherSv1RemoteStatus, ev, &reply); err != nil { t.Error(err) } if reply[utils.NodeID] == nil { @@ -148,17 +149,17 @@ func testDspResponderShutdown(t *testing.T) { utils.OptsAPIKey: "rsp12345", }, } - if err := dispEngine.RPC.Call(utils.ResponderShutdown, ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ResponderShutdown, ev, &reply); err != nil { t.Error(err) } else if reply != "Done!" { t.Errorf("Received: %s", utils.ToJSON(reply)) } - if err := dispEngine.RPC.Call(utils.DispatcherSv1RemoteStatus, &ev, &statusReply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.DispatcherSv1RemoteStatus, &ev, &statusReply); err != nil { t.Error(err) } else if statusReply[utils.NodeID] != "ALL2" { t.Errorf("Received: %s", utils.ToJSON(statusReply)) } - if err := dispEngine.RPC.Call(utils.ResponderShutdown, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ResponderShutdown, &ev, &reply); err != nil { t.Error(err) } else if reply != "Done!" { t.Errorf("Received: %s", utils.ToJSON(reply)) @@ -179,7 +180,7 @@ func testDspResponderBroadcast(t *testing.T) { utils.OptsAPIKey: "rsp12345", }, } - if err := dispEngine.RPC.Call(utils.ResponderPing, pingEv, &pingReply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ResponderPing, pingEv, &pingReply); err != nil { t.Error(err) } else if pingReply != utils.Pong { t.Errorf("Received: %s", pingReply) @@ -187,14 +188,14 @@ func testDspResponderBroadcast(t *testing.T) { allEngine2.stopEngine(t) pingReply = "" - if err := dispEngine.RPC.Call(utils.ResponderPing, pingEv, &pingReply); err == nil || + if err := dispEngine.RPC.Call(context.Background(), utils.ResponderPing, pingEv, &pingReply); err == nil || err.Error() != utils.ErrPartiallyExecuted.Error() { t.Errorf("Expected error: %s received error: %v and reply %q", utils.ErrPartiallyExecuted.Error(), err, pingReply) } allEngine.stopEngine(t) time.Sleep(10 * time.Millisecond) pingReply = "" - if err := dispEngine.RPC.Call(utils.ResponderPing, pingEv, &pingReply); err == nil || + if err := dispEngine.RPC.Call(context.Background(), utils.ResponderPing, pingEv, &pingReply); err == nil || !rpcclient.IsNetworkError(err) { t.Errorf("Expected error: %s received error: %v and reply %q", utils.ErrPartiallyExecuted.Error(), err, pingReply) } @@ -224,12 +225,12 @@ func testDspResponderInternal(t *testing.T) { utils.OptsRouteID: route, }, } - if err := dispEngine.RPC.Call(utils.DispatcherSv1RemotePing, pingEv, &pingReply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.DispatcherSv1RemotePing, pingEv, &pingReply); err != nil { t.Error(err) } else if pingReply != utils.Pong { t.Errorf("Received: %s", pingReply) } - if err := dispEngine.RPC.Call(utils.DispatcherSv1RemoteStatus, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.DispatcherSv1RemoteStatus, &ev, &reply); err != nil { t.Error(err) } if reply[utils.NodeID] == nil { diff --git a/dispatchers/responder_test.go b/dispatchers/responder_test.go index 6cfacf7a4..eae337ee7 100644 --- a/dispatchers/responder_test.go +++ b/dispatchers/responder_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -32,7 +33,7 @@ func TestDspResponderPingEventNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *string - result := dspSrv.ResponderPing(nil, reply) + result := dspSrv.ResponderPing(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -47,7 +48,7 @@ func TestDspResponderPingEventNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResponderPing(CGREvent, reply) + result := dspSrv.ResponderPing(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -61,7 +62,7 @@ func TestDspResponderPingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResponderPing(CGREvent, reply) + result := dspSrv.ResponderPing(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -78,7 +79,7 @@ func TestDspResponderDebitNil(t *testing.T) { }, } var reply *engine.CallCost - result := dspSrv.ResponderDebit(CGREvent, reply) + result := dspSrv.ResponderDebit(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -94,7 +95,7 @@ func TestDspResponderDebitErrorNil(t *testing.T) { }, } var reply *engine.CallCost - result := dspSrv.ResponderDebit(CGREvent, reply) + result := dspSrv.ResponderDebit(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -111,7 +112,7 @@ func TestDspResponderGetCostNil(t *testing.T) { }, } var reply *engine.CallCost - result := dspSrv.ResponderGetCost(CGREvent, reply) + result := dspSrv.ResponderGetCost(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -127,7 +128,7 @@ func TestDspResponderGetCostErrorNil(t *testing.T) { }, } var reply *engine.CallCost - result := dspSrv.ResponderGetCost(CGREvent, reply) + result := dspSrv.ResponderGetCost(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -144,7 +145,7 @@ func TestDspResponderMaxDebitNil(t *testing.T) { }, } var reply *engine.CallCost - result := dspSrv.ResponderMaxDebit(CGREvent, reply) + result := dspSrv.ResponderMaxDebit(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -160,7 +161,7 @@ func TestDspResponderMaxDebitErrorNil(t *testing.T) { }, } var reply *engine.CallCost - result := dspSrv.ResponderMaxDebit(CGREvent, reply) + result := dspSrv.ResponderMaxDebit(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -177,7 +178,7 @@ func TestDspResponderRefundIncrementsNil(t *testing.T) { }, } var reply *engine.Account - result := dspSrv.ResponderRefundIncrements(CGREvent, reply) + result := dspSrv.ResponderRefundIncrements(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -193,7 +194,7 @@ func TestDspResponderRefundIncrementsErrorNil(t *testing.T) { }, } var reply *engine.Account - result := dspSrv.ResponderRefundIncrements(CGREvent, reply) + result := dspSrv.ResponderRefundIncrements(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -210,7 +211,7 @@ func TestDspResponderRefundRoundingNil(t *testing.T) { }, } var reply engine.Account - result := dspSrv.ResponderRefundRounding(CGREvent, &reply) + result := dspSrv.ResponderRefundRounding(context.Background(), CGREvent, &reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -226,7 +227,7 @@ func TestDspResponderRefundRoundingErrorNil(t *testing.T) { }, } var reply engine.Account - result := dspSrv.ResponderRefundRounding(CGREvent, &reply) + result := dspSrv.ResponderRefundRounding(context.Background(), CGREvent, &reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -243,7 +244,7 @@ func TestDspResponderGetMaxSessionTimeNil(t *testing.T) { }, } var reply *time.Duration - result := dspSrv.ResponderGetMaxSessionTime(CGREvent, reply) + result := dspSrv.ResponderGetMaxSessionTime(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -259,7 +260,7 @@ func TestDspResponderGetMaxSessionTimeErrorNil(t *testing.T) { }, } var reply *time.Duration - result := dspSrv.ResponderGetMaxSessionTime(CGREvent, reply) + result := dspSrv.ResponderGetMaxSessionTime(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -274,7 +275,7 @@ func TestDspResponderShutdownNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResponderShutdown(CGREvent, reply) + result := dspSrv.ResponderShutdown(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -288,7 +289,7 @@ func TestDspResponderShutdownErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ResponderShutdown(CGREvent, reply) + result := dspSrv.ResponderShutdown(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -337,7 +338,7 @@ func TestDspResponderGetCostOnRatingPlans(t *testing.T) { t.Error(err) } var reply map[string]any - if err := dsp.ResponderGetCostOnRatingPlans(args, &reply); err == nil { + if err := dsp.ResponderGetCostOnRatingPlans(context.Background(), args, &reply); err == nil { t.Error(err) } } @@ -379,7 +380,7 @@ func TestDspResponderGetCostOnRatingPlans(t *testing.T) { // t.Error(err) // } // var reply map[string]any -// if err := dsp.ResponderGetMaxSessionTimeOnAccounts(args, &reply); err == nil { +// if err := dsp.ResponderGetMaxSessionTimeOnAccounts(context.Background(),args, &reply); err == nil { // t.Error(err) // } // } diff --git a/dispatchers/routes.go b/dispatchers/routes.go index d11187a0c..d5cc5fe6d 100644 --- a/dispatchers/routes.go +++ b/dispatchers/routes.go @@ -19,11 +19,12 @@ along with this program. If not, see package dispatchers import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) RouteSv1Ping(args *utils.CGREvent, reply *string) (err error) { +func (dS *DispatcherService) RouteSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) } @@ -38,7 +39,7 @@ func (dS *DispatcherService) RouteSv1Ping(args *utils.CGREvent, reply *string) ( return dS.Dispatch(args, utils.MetaRoutes, utils.RouteSv1Ping, args, reply) } -func (dS *DispatcherService) RouteSv1GetRoutes(args *utils.CGREvent, reply *engine.SortedRoutesList) (err error) { +func (dS *DispatcherService) RouteSv1GetRoutes(ctx *context.Context, args *utils.CGREvent, reply *engine.SortedRoutesList) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.RouteSv1GetRoutes, @@ -50,7 +51,7 @@ func (dS *DispatcherService) RouteSv1GetRoutes(args *utils.CGREvent, reply *engi return dS.Dispatch(args, utils.MetaRoutes, utils.RouteSv1GetRoutes, args, reply) } -func (dS *DispatcherService) RouteSv1GetRoutesList(args *utils.CGREvent, reply *[]string) (err error) { +func (dS *DispatcherService) RouteSv1GetRoutesList(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.RouteSv1GetRoutesList, @@ -62,7 +63,7 @@ func (dS *DispatcherService) RouteSv1GetRoutesList(args *utils.CGREvent, reply * return dS.Dispatch(args, utils.MetaRoutes, utils.RouteSv1GetRoutesList, args, reply) } -func (dS *DispatcherService) RouteSv1GetRouteProfilesForEvent(args *utils.CGREvent, reply *[]*engine.RouteProfile) (err error) { +func (dS *DispatcherService) RouteSv1GetRouteProfilesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*engine.RouteProfile) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.RouteSv1GetRouteProfilesForEvent, diff --git a/dispatchers/routes_it_test.go b/dispatchers/routes_it_test.go index 22594459a..b23b0d7b6 100644 --- a/dispatchers/routes_it_test.go +++ b/dispatchers/routes_it_test.go @@ -27,6 +27,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -74,12 +75,12 @@ func TestDspSupplierS(t *testing.T) { func testDspSupPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.RouteSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.RouteSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.RouteSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ utils.OptsAPIKey: "sup12345", @@ -93,7 +94,7 @@ func testDspSupPing(t *testing.T) { func testDspSupPingFailover(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.RouteSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.RouteSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -105,19 +106,19 @@ func testDspSupPingFailover(t *testing.T) { utils.OptsAPIKey: "sup12345", }, } - if err := dispEngine.RPC.Call(utils.RouteSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine.stopEngine(t) - if err := dispEngine.RPC.Call(utils.RouteSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.RouteSv1Ping, &ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1Ping, &ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine.startEngine(t) @@ -180,14 +181,14 @@ func testDspSupGetSupFailover(t *testing.T) { utils.OptsAPIKey: "sup12345", }, } - if err := dispEngine.RPC.Call(utils.RouteSv1GetRoutes, + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1GetRoutes, args, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRpl1, rpl) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRpl1), utils.ToJSON(rpl)) } allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.RouteSv1GetRoutes, + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1GetRoutes, args, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRpl, rpl) { @@ -213,7 +214,7 @@ func testDspSupTestAuthKey(t *testing.T) { utils.OptsAPIKey: "12345", }, } - if err := dispEngine.RPC.Call(utils.RouteSv1GetRoutes, + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1GetRoutes, args, &rpl); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() { t.Error(err) } @@ -261,7 +262,7 @@ func testDspSupTestAuthKey2(t *testing.T) { utils.OptsAPIKey: "sup12345", }, } - if err := dispEngine.RPC.Call(utils.RouteSv1GetRoutes, + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1GetRoutes, args, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRpl, rpl) { @@ -325,13 +326,13 @@ func testDspSupGetSupRoundRobin(t *testing.T) { utils.OptsAPIKey: "sup12345", }, } - if err := dispEngine.RPC.Call(utils.RouteSv1GetRoutes, + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1GetRoutes, args, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRpl1, rpl) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(eRpl1), utils.ToJSON(rpl)) } - if err := dispEngine.RPC.Call(utils.RouteSv1GetRoutes, + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1GetRoutes, args, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(eRpl, rpl) { @@ -394,7 +395,7 @@ func testDspSupGetSupplierForEvent(t *testing.T) { expected.SortingParameters = nil // empty slices are nil in gob } var supProf []*engine.RouteProfile - if err := dispEngine.RPC.Call(utils.RouteSv1GetRouteProfilesForEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.RouteSv1GetRouteProfilesForEvent, ev, &supProf); err != nil { t.Fatal(err) } diff --git a/dispatchers/routes_test.go b/dispatchers/routes_test.go index 1aa2e566a..41474196d 100644 --- a/dispatchers/routes_test.go +++ b/dispatchers/routes_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -31,7 +32,7 @@ func TestDspRouteSv1PingNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *string - result := dspSrv.RouteSv1Ping(nil, reply) + result := dspSrv.RouteSv1Ping(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -46,7 +47,7 @@ func TestDspRouteSv1PingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.RouteSv1Ping(CGREvent, reply) + result := dspSrv.RouteSv1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -60,7 +61,7 @@ func TestDspRouteSv1PingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.RouteSv1Ping(CGREvent, reply) + result := dspSrv.RouteSv1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -75,7 +76,7 @@ func TestDspRouteSv1GetRoutesNil(t *testing.T) { Tenant: "tenant", } var reply *engine.SortedRoutesList - result := dspSrv.RouteSv1GetRoutes(CGREvent, reply) + result := dspSrv.RouteSv1GetRoutes(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -89,7 +90,7 @@ func TestDspRouteSv1GetRoutesErrorNil(t *testing.T) { Tenant: "tenant", } var reply *engine.SortedRoutesList - result := dspSrv.RouteSv1GetRoutes(CGREvent, reply) + result := dspSrv.RouteSv1GetRoutes(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -104,7 +105,7 @@ func TestDspRouteSv1GetRoutesListNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.RouteSv1GetRoutesList(CGREvent, reply) + result := dspSrv.RouteSv1GetRoutesList(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -118,7 +119,7 @@ func TestDspRouteSv1GetRoutesListErrorNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.RouteSv1GetRoutesList(CGREvent, reply) + result := dspSrv.RouteSv1GetRoutesList(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -133,7 +134,7 @@ func TestDspRouteSv1GetRouteProfilesForEventNil(t *testing.T) { Tenant: "tenant", } var reply *[]*engine.RouteProfile - result := dspSrv.RouteSv1GetRouteProfilesForEvent(CGREvent, reply) + result := dspSrv.RouteSv1GetRouteProfilesForEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -147,7 +148,7 @@ func TestDspRouteSv1GetRouteProfilesForEventErrorNil(t *testing.T) { Tenant: "tenant", } var reply *[]*engine.RouteProfile - result := dspSrv.RouteSv1GetRouteProfilesForEvent(CGREvent, reply) + result := dspSrv.RouteSv1GetRouteProfilesForEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/scheduler.go b/dispatchers/scheduler.go index 56e7c1120..dd48910ed 100644 --- a/dispatchers/scheduler.go +++ b/dispatchers/scheduler.go @@ -21,10 +21,11 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) SchedulerSv1Ping(args *utils.CGREvent, reply *string) (err error) { +func (dS *DispatcherService) SchedulerSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) } @@ -38,7 +39,7 @@ func (dS *DispatcherService) SchedulerSv1Ping(args *utils.CGREvent, reply *strin return dS.Dispatch(args, utils.MetaScheduler, utils.SchedulerSv1Ping, args, reply) } -func (dS *DispatcherService) SchedulerSv1Reload(args *utils.CGREvent, reply *string) (err error) { +func (dS *DispatcherService) SchedulerSv1Reload(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.SchedulerSv1Ping, args.Tenant, @@ -49,7 +50,7 @@ func (dS *DispatcherService) SchedulerSv1Reload(args *utils.CGREvent, reply *str return dS.Dispatch(args, utils.MetaScheduler, utils.SchedulerSv1Reload, args, reply) } -func (dS *DispatcherService) SchedulerSv1ExecuteActions(args *utils.AttrsExecuteActions, reply *string) (err error) { +func (dS *DispatcherService) SchedulerSv1ExecuteActions(ctx *context.Context, args *utils.AttrsExecuteActions, reply *string) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.SchedulerSv1ExecuteActions, args.Tenant, @@ -63,7 +64,7 @@ func (dS *DispatcherService) SchedulerSv1ExecuteActions(args *utils.AttrsExecute }, utils.MetaScheduler, utils.SchedulerSv1ExecuteActions, args, reply) } -func (dS *DispatcherService) SchedulerSv1ExecuteActionPlans(args *utils.AttrsExecuteActionPlans, reply *string) (err error) { +func (dS *DispatcherService) SchedulerSv1ExecuteActionPlans(ctx *context.Context, args *utils.AttrsExecuteActionPlans, reply *string) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.SchedulerSv1ExecuteActionPlans, args.Tenant, diff --git a/dispatchers/scheduler_it_test.go b/dispatchers/scheduler_it_test.go index c01964d7e..2e695c35a 100644 --- a/dispatchers/scheduler_it_test.go +++ b/dispatchers/scheduler_it_test.go @@ -24,6 +24,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) @@ -61,12 +62,12 @@ func TestDspSchedulerS(t *testing.T) { func testDspSchedPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.SchedulerSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.SchedulerSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.SchedulerSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.SchedulerSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ diff --git a/dispatchers/scheduler_test.go b/dispatchers/scheduler_test.go index a892ffa04..dc79b6e43 100644 --- a/dispatchers/scheduler_test.go +++ b/dispatchers/scheduler_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -30,7 +31,7 @@ func TestDspSchedulerSv1PingErrorNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *string - result := dspSrv.SchedulerSv1Ping(nil, reply) + result := dspSrv.SchedulerSv1Ping(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -45,7 +46,7 @@ func TestDspSchedulerSv1PingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SchedulerSv1Ping(CGREvent, reply) + result := dspSrv.SchedulerSv1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -59,7 +60,7 @@ func TestDspSchedulerSv1PingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SchedulerSv1Ping(CGREvent, reply) + result := dspSrv.SchedulerSv1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -74,7 +75,7 @@ func TestDspSchedulerSv1ReloadErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SchedulerSv1Reload(CGREvent, reply) + result := dspSrv.SchedulerSv1Reload(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -88,7 +89,7 @@ func TestDspSchedulerSv1ReloadPingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SchedulerSv1Reload(CGREvent, reply) + result := dspSrv.SchedulerSv1Reload(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -103,7 +104,7 @@ func TestDspSchedulerSv1ExecuteActionsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SchedulerSv1ExecuteActions(CGREvent, reply) + result := dspSrv.SchedulerSv1ExecuteActions(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -117,7 +118,7 @@ func TestDspSchedulerSv1ExecuteActionsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SchedulerSv1ExecuteActions(CGREvent, reply) + result := dspSrv.SchedulerSv1ExecuteActions(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -132,7 +133,7 @@ func TestDspSchedulerSv1ExecuteActionPlansErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SchedulerSv1ExecuteActionPlans(CGREvent, reply) + result := dspSrv.SchedulerSv1ExecuteActionPlans(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -146,7 +147,7 @@ func TestDspSchedulerSv1ExecuteActionPlansNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SchedulerSv1ExecuteActionPlans(CGREvent, reply) + result := dspSrv.SchedulerSv1ExecuteActionPlans(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/servicemanager.go b/dispatchers/servicemanager.go index 925338253..a4ac260d9 100644 --- a/dispatchers/servicemanager.go +++ b/dispatchers/servicemanager.go @@ -21,11 +21,12 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) // ServiceManagerV1Ping interogates ServiceManager server responsible to process the event -func (dS *DispatcherService) ServiceManagerV1Ping(args *utils.CGREvent, +func (dS *DispatcherService) ServiceManagerV1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) @@ -40,7 +41,7 @@ func (dS *DispatcherService) ServiceManagerV1Ping(args *utils.CGREvent, return dS.Dispatch(args, utils.MetaServiceManager, utils.ServiceManagerV1Ping, args, reply) } -func (dS *DispatcherService) ServiceManagerV1StartService(args ArgStartServiceWithAPIOpts, +func (dS *DispatcherService) ServiceManagerV1StartService(ctx *context.Context, args ArgStartServiceWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -58,7 +59,7 @@ func (dS *DispatcherService) ServiceManagerV1StartService(args ArgStartServiceWi }, utils.MetaServiceManager, utils.ServiceManagerV1StartService, args, reply) } -func (dS *DispatcherService) ServiceManagerV1StopService(args ArgStartServiceWithAPIOpts, +func (dS *DispatcherService) ServiceManagerV1StopService(ctx *context.Context, args ArgStartServiceWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -76,7 +77,7 @@ func (dS *DispatcherService) ServiceManagerV1StopService(args ArgStartServiceWit }, utils.MetaServiceManager, utils.ServiceManagerV1StopService, args, reply) } -func (dS *DispatcherService) ServiceManagerV1ServiceStatus(args ArgStartServiceWithAPIOpts, +func (dS *DispatcherService) ServiceManagerV1ServiceStatus(ctx *context.Context, args ArgStartServiceWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { diff --git a/dispatchers/servicemanager_test.go b/dispatchers/servicemanager_test.go index cedd0c59b..235af6e00 100644 --- a/dispatchers/servicemanager_test.go +++ b/dispatchers/servicemanager_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -30,7 +31,7 @@ func TestDspServiceManagerV1PingErrorNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *string - result := dspSrv.ServiceManagerV1Ping(nil, reply) + result := dspSrv.ServiceManagerV1Ping(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -45,7 +46,7 @@ func TestDspServiceManagerV1PingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ServiceManagerV1Ping(CGREvent, reply) + result := dspSrv.ServiceManagerV1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -59,7 +60,7 @@ func TestDspServiceManagerV1PingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ServiceManagerV1Ping(CGREvent, reply) + result := dspSrv.ServiceManagerV1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -74,7 +75,7 @@ func TestDspServiceManagerV1StartServiceErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ServiceManagerV1StartService(CGREvent, reply) + result := dspSrv.ServiceManagerV1StartService(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -88,7 +89,7 @@ func TestDspServiceManagerV1StartServiceNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ServiceManagerV1StartService(CGREvent, reply) + result := dspSrv.ServiceManagerV1StartService(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -103,7 +104,7 @@ func TestDspServiceManagerV1StopServiceErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ServiceManagerV1StopService(CGREvent, reply) + result := dspSrv.ServiceManagerV1StopService(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -117,7 +118,7 @@ func TestDspServiceManagerV1StopServiceNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ServiceManagerV1StopService(CGREvent, reply) + result := dspSrv.ServiceManagerV1StopService(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -132,7 +133,7 @@ func TestDspServiceManagerV1ServiceStatusNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ServiceManagerV1ServiceStatus(CGREvent, reply) + result := dspSrv.ServiceManagerV1ServiceStatus(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -146,7 +147,7 @@ func TestDspServiceManagerV1ServiceStatusErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ServiceManagerV1ServiceStatus(CGREvent, reply) + result := dspSrv.ServiceManagerV1ServiceStatus(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/sessions.go b/dispatchers/sessions.go index 7f716666c..14fa89ebe 100644 --- a/dispatchers/sessions.go +++ b/dispatchers/sessions.go @@ -21,11 +21,12 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) SessionSv1Ping(args *utils.CGREvent, reply *string) (err error) { +func (dS *DispatcherService) SessionSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.SessionSv1Ping, args.Tenant, @@ -36,7 +37,7 @@ func (dS *DispatcherService) SessionSv1Ping(args *utils.CGREvent, reply *string) return dS.Dispatch(args, utils.MetaSessionS, utils.SessionSv1Ping, args, reply) } -func (dS *DispatcherService) SessionSv1AuthorizeEvent(args *sessions.V1AuthorizeArgs, +func (dS *DispatcherService) SessionSv1AuthorizeEvent(ctx *context.Context, args *sessions.V1AuthorizeArgs, reply *sessions.V1AuthorizeReply) (err error) { args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -48,7 +49,7 @@ func (dS *DispatcherService) SessionSv1AuthorizeEvent(args *sessions.V1Authorize return dS.Dispatch(args.CGREvent, utils.MetaSessionS, utils.SessionSv1AuthorizeEvent, args, reply) } -func (dS *DispatcherService) SessionSv1AuthorizeEventWithDigest(args *sessions.V1AuthorizeArgs, +func (dS *DispatcherService) SessionSv1AuthorizeEventWithDigest(ctx *context.Context, args *sessions.V1AuthorizeArgs, reply *sessions.V1AuthorizeReplyWithDigest) (err error) { args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -60,7 +61,7 @@ func (dS *DispatcherService) SessionSv1AuthorizeEventWithDigest(args *sessions.V return dS.Dispatch(args.CGREvent, utils.MetaSessionS, utils.SessionSv1AuthorizeEventWithDigest, args, reply) } -func (dS *DispatcherService) SessionSv1InitiateSession(args *sessions.V1InitSessionArgs, +func (dS *DispatcherService) SessionSv1InitiateSession(ctx *context.Context, args *sessions.V1InitSessionArgs, reply *sessions.V1InitSessionReply) (err error) { args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -72,7 +73,7 @@ func (dS *DispatcherService) SessionSv1InitiateSession(args *sessions.V1InitSess return dS.Dispatch(args.CGREvent, utils.MetaSessionS, utils.SessionSv1InitiateSession, args, reply) } -func (dS *DispatcherService) SessionSv1InitiateSessionWithDigest(args *sessions.V1InitSessionArgs, +func (dS *DispatcherService) SessionSv1InitiateSessionWithDigest(ctx *context.Context, args *sessions.V1InitSessionArgs, reply *sessions.V1InitReplyWithDigest) (err error) { args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -84,7 +85,7 @@ func (dS *DispatcherService) SessionSv1InitiateSessionWithDigest(args *sessions. return dS.Dispatch(args.CGREvent, utils.MetaSessionS, utils.SessionSv1InitiateSessionWithDigest, args, reply) } -func (dS *DispatcherService) SessionSv1UpdateSession(args *sessions.V1UpdateSessionArgs, +func (dS *DispatcherService) SessionSv1UpdateSession(ctx *context.Context, args *sessions.V1UpdateSessionArgs, reply *sessions.V1UpdateSessionReply) (err error) { args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -96,7 +97,7 @@ func (dS *DispatcherService) SessionSv1UpdateSession(args *sessions.V1UpdateSess return dS.Dispatch(args.CGREvent, utils.MetaSessionS, utils.SessionSv1UpdateSession, args, reply) } -func (dS *DispatcherService) SessionSv1SyncSessions(args *utils.TenantWithAPIOpts, +func (dS *DispatcherService) SessionSv1SyncSessions(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -114,7 +115,7 @@ func (dS *DispatcherService) SessionSv1SyncSessions(args *utils.TenantWithAPIOpt }, utils.MetaSessionS, utils.SessionSv1SyncSessions, args, reply) } -func (dS *DispatcherService) SessionSv1TerminateSession(args *sessions.V1TerminateSessionArgs, +func (dS *DispatcherService) SessionSv1TerminateSession(ctx *context.Context, args *sessions.V1TerminateSessionArgs, reply *string) (err error) { args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -126,7 +127,7 @@ func (dS *DispatcherService) SessionSv1TerminateSession(args *sessions.V1Termina return dS.Dispatch(args.CGREvent, utils.MetaSessionS, utils.SessionSv1TerminateSession, args, reply) } -func (dS *DispatcherService) SessionSv1ProcessCDR(args *utils.CGREvent, +func (dS *DispatcherService) SessionSv1ProcessCDR(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -138,7 +139,7 @@ func (dS *DispatcherService) SessionSv1ProcessCDR(args *utils.CGREvent, return dS.Dispatch(args, utils.MetaSessionS, utils.SessionSv1ProcessCDR, args, reply) } -func (dS *DispatcherService) SessionSv1ProcessMessage(args *sessions.V1ProcessMessageArgs, +func (dS *DispatcherService) SessionSv1ProcessMessage(ctx *context.Context, args *sessions.V1ProcessMessageArgs, reply *sessions.V1ProcessMessageReply) (err error) { args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -150,7 +151,7 @@ func (dS *DispatcherService) SessionSv1ProcessMessage(args *sessions.V1ProcessMe return dS.Dispatch(args.CGREvent, utils.MetaSessionS, utils.SessionSv1ProcessMessage, args, reply) } -func (dS *DispatcherService) SessionSv1ProcessEvent(args *sessions.V1ProcessEventArgs, +func (dS *DispatcherService) SessionSv1ProcessEvent(ctx *context.Context, args *sessions.V1ProcessEventArgs, reply *sessions.V1ProcessEventReply) (err error) { args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -162,7 +163,7 @@ func (dS *DispatcherService) SessionSv1ProcessEvent(args *sessions.V1ProcessEven return dS.Dispatch(args.CGREvent, utils.MetaSessionS, utils.SessionSv1ProcessEvent, args, reply) } -func (dS *DispatcherService) SessionSv1GetCost(args *sessions.V1ProcessEventArgs, +func (dS *DispatcherService) SessionSv1GetCost(ctx *context.Context, args *sessions.V1ProcessEventArgs, reply *sessions.V1GetCostReply) (err error) { args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -174,7 +175,7 @@ func (dS *DispatcherService) SessionSv1GetCost(args *sessions.V1ProcessEventArgs return dS.Dispatch(args.CGREvent, utils.MetaSessionS, utils.SessionSv1GetCost, args, reply) } -func (dS *DispatcherService) SessionSv1GetActiveSessions(args *utils.SessionFilter, +func (dS *DispatcherService) SessionSv1GetActiveSessions(ctx *context.Context, args *utils.SessionFilter, reply *[]*sessions.ExternalSession) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -192,7 +193,7 @@ func (dS *DispatcherService) SessionSv1GetActiveSessions(args *utils.SessionFilt }, utils.MetaSessionS, utils.SessionSv1GetActiveSessions, args, reply) } -func (dS *DispatcherService) SessionSv1GetActiveSessionsCount(args *utils.SessionFilter, +func (dS *DispatcherService) SessionSv1GetActiveSessionsCount(ctx *context.Context, args *utils.SessionFilter, reply *int) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -210,7 +211,7 @@ func (dS *DispatcherService) SessionSv1GetActiveSessionsCount(args *utils.Sessio }, utils.MetaSessionS, utils.SessionSv1GetActiveSessionsCount, args, reply) } -func (dS *DispatcherService) SessionSv1ForceDisconnect(args *utils.SessionFilter, +func (dS *DispatcherService) SessionSv1ForceDisconnect(ctx *context.Context, args *utils.SessionFilter, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -228,7 +229,7 @@ func (dS *DispatcherService) SessionSv1ForceDisconnect(args *utils.SessionFilter }, utils.MetaSessionS, utils.SessionSv1ForceDisconnect, args, reply) } -func (dS *DispatcherService) SessionSv1GetPassiveSessions(args *utils.SessionFilter, +func (dS *DispatcherService) SessionSv1GetPassiveSessions(ctx *context.Context, args *utils.SessionFilter, reply *[]*sessions.ExternalSession) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -246,7 +247,7 @@ func (dS *DispatcherService) SessionSv1GetPassiveSessions(args *utils.SessionFil }, utils.MetaSessionS, utils.SessionSv1GetPassiveSessions, args, reply) } -func (dS *DispatcherService) SessionSv1GetPassiveSessionsCount(args *utils.SessionFilter, +func (dS *DispatcherService) SessionSv1GetPassiveSessionsCount(ctx *context.Context, args *utils.SessionFilter, reply *int) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -264,7 +265,7 @@ func (dS *DispatcherService) SessionSv1GetPassiveSessionsCount(args *utils.Sessi }, utils.MetaSessionS, utils.SessionSv1GetPassiveSessionsCount, args, reply) } -func (dS *DispatcherService) SessionSv1ReplicateSessions(args ArgsReplicateSessionsWithAPIOpts, +func (dS *DispatcherService) SessionSv1ReplicateSessions(ctx *context.Context, args ArgsReplicateSessionsWithAPIOpts, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -282,7 +283,7 @@ func (dS *DispatcherService) SessionSv1ReplicateSessions(args ArgsReplicateSessi }, utils.MetaSessionS, utils.SessionSv1ReplicateSessions, args, reply) } -func (dS *DispatcherService) SessionSv1SetPassiveSession(args *sessions.Session, +func (dS *DispatcherService) SessionSv1SetPassiveSession(ctx *context.Context, args *sessions.Session, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { @@ -300,7 +301,7 @@ func (dS *DispatcherService) SessionSv1SetPassiveSession(args *sessions.Session, }, utils.MetaSessionS, utils.SessionSv1SetPassiveSession, args, reply) } -func (dS *DispatcherService) SessionSv1ActivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) { +func (dS *DispatcherService) SessionSv1ActivateSessions(ctx *context.Context, args *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -317,7 +318,7 @@ func (dS *DispatcherService) SessionSv1ActivateSessions(args *utils.SessionIDsWi }, utils.MetaSessionS, utils.SessionSv1ActivateSessions, args, reply) } -func (dS *DispatcherService) SessionSv1DeactivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) { +func (dS *DispatcherService) SessionSv1DeactivateSessions(ctx *context.Context, args *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -334,7 +335,7 @@ func (dS *DispatcherService) SessionSv1DeactivateSessions(args *utils.SessionIDs }, utils.MetaSessionS, utils.SessionSv1DeactivateSessions, args, reply) } -func (dS *DispatcherService) SessionSv1STIRAuthenticate(args *sessions.V1STIRAuthenticateArgs, reply *string) (err error) { +func (dS *DispatcherService) SessionSv1STIRAuthenticate(ctx *context.Context, args *sessions.V1STIRAuthenticateArgs, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.SessionSv1STIRAuthenticate, @@ -348,7 +349,7 @@ func (dS *DispatcherService) SessionSv1STIRAuthenticate(args *sessions.V1STIRAut }, utils.MetaSessionS, utils.SessionSv1STIRAuthenticate, args, reply) } -func (dS *DispatcherService) SessionSv1STIRIdentity(args *sessions.V1STIRIdentityArgs, reply *string) (err error) { +func (dS *DispatcherService) SessionSv1STIRIdentity(ctx *context.Context, args *sessions.V1STIRIdentityArgs, reply *string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.SessionSv1STIRIdentity, diff --git a/dispatchers/sessions_it_test.go b/dispatchers/sessions_it_test.go index f97b84ab7..69c4a1fcf 100644 --- a/dispatchers/sessions_it_test.go +++ b/dispatchers/sessions_it_test.go @@ -29,6 +29,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" @@ -102,7 +103,7 @@ func testDspSessionAddBalacne(t *testing.T) { }, } var reply string - if err := allEngine.RPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -113,18 +114,18 @@ func testDspSessionAddBalacne(t *testing.T) { Account: attrSetBalance.Account, } eAcntVal := float64(initUsage) - if err := allEngine.RPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %v, received: %v", time.Duration(eAcntVal), time.Duration(acnt.BalanceMap[utils.MetaVoice].GetTotalValue())) } - if err := allEngine2.RPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := allEngine2.RPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } - if err := allEngine2.RPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := allEngine2.RPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %v, received: %v", @@ -134,12 +135,12 @@ func testDspSessionAddBalacne(t *testing.T) { func testDspSessionPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.SessionSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.SessionSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.SessionSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ @@ -154,7 +155,7 @@ func testDspSessionPing(t *testing.T) { func testDspSessionPingFailover(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.SessionSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.SessionSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -166,19 +167,19 @@ func testDspSessionPingFailover(t *testing.T) { utils.OptsAPIKey: "ses12345", }, } - if err := dispEngine.RPC.Call(utils.SessionSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine.stopEngine(t) - if err := dispEngine.RPC.Call(utils.SessionSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.SessionSv1Ping, &ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1Ping, &ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine.startEngine(t) @@ -213,7 +214,7 @@ func testDspSessionTestAuthKey(t *testing.T) { }, } var rply sessions.V1AuthorizeReplyWithDigest - if err := dispEngine.RPC.Call(utils.SessionSv1AuthorizeEventWithDigest, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1AuthorizeEventWithDigest, args, &rply); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() { t.Error(err) } @@ -249,7 +250,7 @@ func testDspSessionAuthorize(t *testing.T) { }, } var rply sessions.V1AuthorizeReplyWithDigest - if err := dispEngine.RPC.Call(utils.SessionSv1AuthorizeEventWithDigest, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1AuthorizeEventWithDigest, argsAuth, &rply); err != nil { t.Error(err) return @@ -302,7 +303,7 @@ func testDspSessionInit(t *testing.T) { }, } var rply sessions.V1InitReplyWithDigest - if err := dispEngine.RPC.Call(utils.SessionSv1InitiateSessionWithDigest, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1InitiateSessionWithDigest, argsInit, &rply); err != nil { t.Fatal(err) } @@ -323,28 +324,28 @@ func testDspGetSessions(t *testing.T) { Filters: []string{}, } var reply int - if err := dispEngine.RPC.Call(utils.SessionSv1GetActiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetActiveSessionsCount, &filtr, &reply); err != nil { t.Fatal(err) } else if reply != 3 { t.Errorf("Expected 3 active sessions received %v", reply) } var rply []*sessions.ExternalSession - if err := dispEngine.RPC.Call(utils.SessionSv1GetActiveSessions, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, &filtr, &rply); err != nil { t.Fatal(err) } else if len(rply) != 3 { t.Errorf("Unexpected number of sessions returned %v :%s", len(rply), utils.ToJSON(rply)) } - if err := dispEngine.RPC.Call(utils.SessionSv1GetPassiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetPassiveSessionsCount, &filtr, &reply); err != nil { t.Fatal(err) } else if reply != 0 { t.Errorf("Expected no pasive sessions received %v", reply) } rply = nil - if err := dispEngine.RPC.Call(utils.SessionSv1GetPassiveSessions, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, &filtr, &rply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected %v received %v with reply %s", utils.ErrNotFound, err, utils.ToJSON(rply)) } @@ -378,7 +379,7 @@ func testDspSessionUpdate(t *testing.T) { }, } var rply sessions.V1UpdateSessionReply - if err := dispEngine.RPC.Call(utils.SessionSv1UpdateSession, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1UpdateSession, argsUpdate, &rply); err != nil { t.Error(err) } @@ -451,7 +452,7 @@ func testDspSessionUpdate2(t *testing.T) { }, } var rply sessions.V1UpdateSessionReply - if err := dispEngine.RPC.Call(utils.SessionSv1UpdateSession, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1UpdateSession, argsUpdate, &rply); err != nil { t.Fatal(err) } @@ -532,7 +533,7 @@ func testDspSessionTerminate(t *testing.T) { }, } var rply string - if err := dispEngine.RPC.Call(utils.SessionSv1TerminateSession, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } @@ -563,7 +564,7 @@ func testDspSessionProcessCDR(t *testing.T) { } var rply string - if err := dispEngine.RPC.Call(utils.SessionSv1ProcessCDR, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1ProcessCDR, args, &rply); err != nil { t.Fatal(err) } @@ -602,7 +603,7 @@ func testDspSessionProcessEvent(t *testing.T) { }, } var rply sessions.V1ProcessMessageReply - if err := dispEngine.RPC.Call(utils.SessionSv1ProcessMessage, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -685,7 +686,7 @@ func testDspSessionProcessEvent2(t *testing.T) { }, } var rply sessions.V1ProcessMessageReply - if err := dispEngine.RPC.Call(utils.SessionSv1ProcessMessage, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -743,7 +744,7 @@ func testDspSessionReplicate(t *testing.T) { allEngine.resetStorDb(t) var reply string // reload cache in order to corectly cahce the indexes - if err := allEngine.RPC.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := allEngine.RPC.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ CacheIDs: nil, }, &reply); err != nil { t.Error(err) @@ -755,7 +756,7 @@ func testDspSessionReplicate(t *testing.T) { testDspSessionAuthorize(t) testDspSessionInit(t) - if err := dispEngine.RPC.Call(utils.SessionSv1ReplicateSessions, &ArgsReplicateSessionsWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1ReplicateSessions, &ArgsReplicateSessionsWithAPIOpts{ APIOpts: map[string]any{ utils.OptsAPIKey: "ses12345", }, @@ -773,7 +774,7 @@ func testDspSessionReplicate(t *testing.T) { var repl int time.Sleep(10 * time.Millisecond) - if err := allEngine2.RPC.Call(utils.SessionSv1GetPassiveSessionsCount, + if err := allEngine2.RPC.Call(context.Background(), utils.SessionSv1GetPassiveSessionsCount, new(utils.SessionFilter), &repl); err != nil { t.Fatal(err) } else if repl != 3 { @@ -793,13 +794,13 @@ func testDspSessionPassive(t *testing.T) { Filters: []string{}, } time.Sleep(10 * time.Millisecond) - if err := dispEngine.RPC.Call(utils.SessionSv1GetPassiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetPassiveSessionsCount, filtr, &repl); err != nil { t.Fatal(err) } else if repl != 0 { t.Errorf("Expected no passive sessions received %v", repl) } - if err := dispEngine.RPC.Call(utils.SessionSv1GetActiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetActiveSessionsCount, filtr, &repl); err != nil { t.Fatal(err) } else if repl != 3 { @@ -807,7 +808,7 @@ func testDspSessionPassive(t *testing.T) { } var rply []*sessions.ExternalSession - if err := dispEngine.RPC.Call(utils.SessionSv1GetActiveSessions, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, &filtr, &rply); err != nil { t.Fatal(err) } else if len(rply) != 3 { @@ -815,7 +816,7 @@ func testDspSessionPassive(t *testing.T) { } var reply string - if err := dispEngine.RPC.Call(utils.SessionSv1SetPassiveSession, sessions.Session{ + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1SetPassiveSession, sessions.Session{ CGRID: rply[0].CGRID, Tenant: rply[0].Tenant, ResourceID: "TestSSv1It1", @@ -864,13 +865,13 @@ func testDspSessionPassive(t *testing.T) { t.Errorf("Unexpected reply %s", reply) } time.Sleep(10 * time.Millisecond) - if err := dispEngine.RPC.Call(utils.SessionSv1GetPassiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetPassiveSessionsCount, filtr, &repl); err != nil { t.Fatal(err) } else if repl != 1 { t.Errorf("Expected 1 passive sessions received %v", repl) } - if err := dispEngine.RPC.Call(utils.SessionSv1GetActiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetActiveSessionsCount, filtr, &repl); err != nil { t.Fatal(err) } else if repl != 0 { @@ -895,13 +896,13 @@ func testDspSessionForceDisconect(t *testing.T) { Filters: []string{}, } time.Sleep(10 * time.Millisecond) - if err := dispEngine.RPC.Call(utils.SessionSv1GetPassiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetPassiveSessionsCount, filtr, &repl); err != nil { t.Fatal(err) } else if repl != 0 { t.Errorf("Expected no passive sessions received %v", repl) } - if err := dispEngine.RPC.Call(utils.SessionSv1GetActiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetActiveSessionsCount, filtr, &repl); err != nil { t.Fatal(err) } else if repl != 3 { @@ -909,7 +910,7 @@ func testDspSessionForceDisconect(t *testing.T) { } var rply []*sessions.ExternalSession - if err := dispEngine.RPC.Call(utils.SessionSv1GetActiveSessions, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, &filtr, &rply); err != nil { t.Fatal(err) } else if len(rply) != 3 { @@ -917,19 +918,19 @@ func testDspSessionForceDisconect(t *testing.T) { } var reply string - if err := dispEngine.RPC.Call(utils.SessionSv1ForceDisconnect, &filtr, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1ForceDisconnect, &filtr, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Errorf("Unexpected reply %s", reply) } time.Sleep(10 * time.Millisecond) - if err := dispEngine.RPC.Call(utils.SessionSv1GetPassiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetPassiveSessionsCount, filtr, &repl); err != nil { t.Fatal(err) } else if repl != 0 { t.Errorf("Expected 1 passive sessions received %v", repl) } - if err := dispEngine.RPC.Call(utils.SessionSv1GetActiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetActiveSessionsCount, filtr, &repl); err != nil { t.Fatal(err) } else if repl != 0 { @@ -962,13 +963,13 @@ func testDspSessionProcessEvent3(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := dispEngine.RPC.Call(utils.SessionSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Error(err) } var repl int - if err := dispEngine.RPC.Call(utils.SessionSv1GetActiveSessionsCount, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetActiveSessionsCount, utils.SessionFilter{ APIOpts: map[string]any{ utils.OptsAPIKey: "ses12345", @@ -1007,7 +1008,7 @@ func testDspSessionGetCost(t *testing.T) { } var rply sessions.V1GetCostReply - if err := dispEngine.RPC.Call(utils.SessionSv1GetCost, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1GetCost, args, &rply); err != nil { t.Error(err) } @@ -1024,7 +1025,7 @@ func testDspSessionGetCost(t *testing.T) { func testDspSessionSTIRAuthenticate(t *testing.T) { var rply string - if err := dispEngine.RPC.Call(utils.SessionSv1STIRAuthenticate, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1STIRAuthenticate, &sessions.V1STIRAuthenticateArgs{ Attest: []string{"A"}, PayloadMaxDuration: "-1", @@ -1058,7 +1059,7 @@ func testDspSessionSTIRIdentity(t *testing.T) { }, } var rply string - if err := dispEngine.RPC.Call(utils.SessionSv1STIRIdentity, + if err := dispEngine.RPC.Call(context.Background(), utils.SessionSv1STIRIdentity, args, &rply); err != nil { t.Error(err) } diff --git a/dispatchers/sessions_test.go b/dispatchers/sessions_test.go index 3727ed657..43511694e 100644 --- a/dispatchers/sessions_test.go +++ b/dispatchers/sessions_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" @@ -33,7 +34,7 @@ func TestDspSessionSv1PingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1Ping(CGREvent, reply) + result := dspSrv.SessionSv1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -48,7 +49,7 @@ func TestDspSessionSv1PingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1Ping(CGREvent, reply) + result := dspSrv.SessionSv1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -64,7 +65,7 @@ func TestDspSessionSv1AuthorizeEventNil(t *testing.T) { }, } var reply *sessions.V1AuthorizeReply - result := dspSrv.SessionSv1AuthorizeEvent(CGREvent, reply) + result := dspSrv.SessionSv1AuthorizeEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -81,7 +82,7 @@ func TestDspSessionSv1AuthorizeEventErrorNil(t *testing.T) { }, } var reply *sessions.V1AuthorizeReply - result := dspSrv.SessionSv1AuthorizeEvent(CGREvent, reply) + result := dspSrv.SessionSv1AuthorizeEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -97,7 +98,7 @@ func TestDspSessionSv1AuthorizeEventWithDigestNil(t *testing.T) { }, } var reply *sessions.V1AuthorizeReplyWithDigest - result := dspSrv.SessionSv1AuthorizeEventWithDigest(CGREvent, reply) + result := dspSrv.SessionSv1AuthorizeEventWithDigest(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -114,7 +115,7 @@ func TestDspSessionSv1AuthorizeEventWithDigestErrorNil(t *testing.T) { }, } var reply *sessions.V1AuthorizeReplyWithDigest - result := dspSrv.SessionSv1AuthorizeEventWithDigest(CGREvent, reply) + result := dspSrv.SessionSv1AuthorizeEventWithDigest(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -130,7 +131,7 @@ func TestDspSessionSv1InitiateSessionNil(t *testing.T) { }, } var reply *sessions.V1InitSessionReply - result := dspSrv.SessionSv1InitiateSession(CGREvent, reply) + result := dspSrv.SessionSv1InitiateSession(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -147,7 +148,7 @@ func TestDspSessionSv1InitiateSessionErrorNil(t *testing.T) { }, } var reply *sessions.V1InitSessionReply - result := dspSrv.SessionSv1InitiateSession(CGREvent, reply) + result := dspSrv.SessionSv1InitiateSession(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -163,7 +164,7 @@ func TestDspSessionSv1InitiateSessionWithDigestNil(t *testing.T) { }, } var reply *sessions.V1InitReplyWithDigest - result := dspSrv.SessionSv1InitiateSessionWithDigest(CGREvent, reply) + result := dspSrv.SessionSv1InitiateSessionWithDigest(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -180,7 +181,7 @@ func TestDspSessionSv1InitiateSessionWithDigestErrorNil(t *testing.T) { }, } var reply *sessions.V1InitReplyWithDigest - result := dspSrv.SessionSv1InitiateSessionWithDigest(CGREvent, reply) + result := dspSrv.SessionSv1InitiateSessionWithDigest(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -196,7 +197,7 @@ func TestDspSessionSv1UpdateSessionNil(t *testing.T) { }, } var reply *sessions.V1UpdateSessionReply - result := dspSrv.SessionSv1UpdateSession(CGREvent, reply) + result := dspSrv.SessionSv1UpdateSession(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -213,7 +214,7 @@ func TestDspSessionSv1UpdateSessionErrorNil(t *testing.T) { }, } var reply *sessions.V1UpdateSessionReply - result := dspSrv.SessionSv1UpdateSession(CGREvent, reply) + result := dspSrv.SessionSv1UpdateSession(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -227,7 +228,7 @@ func TestDspSessionSv1SyncSessionsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1SyncSessions(CGREvent, reply) + result := dspSrv.SessionSv1SyncSessions(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -242,7 +243,7 @@ func TestDspSessionSv1SyncSessionsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1SyncSessions(CGREvent, reply) + result := dspSrv.SessionSv1SyncSessions(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -258,7 +259,7 @@ func TestDspSessionSv1TerminateSessionNil(t *testing.T) { }, } var reply *string - result := dspSrv.SessionSv1TerminateSession(CGREvent, reply) + result := dspSrv.SessionSv1TerminateSession(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -275,7 +276,7 @@ func TestDspSessionSv1TerminateSessionErrorNil(t *testing.T) { }, } var reply *string - result := dspSrv.SessionSv1TerminateSession(CGREvent, reply) + result := dspSrv.SessionSv1TerminateSession(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -289,7 +290,7 @@ func TestDspSessionSv1ProcessCDRNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1ProcessCDR(CGREvent, reply) + result := dspSrv.SessionSv1ProcessCDR(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -304,7 +305,7 @@ func TestDspSessionSv1ProcessCDRErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1ProcessCDR(CGREvent, reply) + result := dspSrv.SessionSv1ProcessCDR(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -320,7 +321,7 @@ func TestDspSessionSv1ProcessMessageNil(t *testing.T) { }, } var reply *sessions.V1ProcessMessageReply - result := dspSrv.SessionSv1ProcessMessage(CGREvent, reply) + result := dspSrv.SessionSv1ProcessMessage(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -337,7 +338,7 @@ func TestDspSessionSv1ProcessMessageErrorNil(t *testing.T) { }, } var reply *sessions.V1ProcessMessageReply - result := dspSrv.SessionSv1ProcessMessage(CGREvent, reply) + result := dspSrv.SessionSv1ProcessMessage(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -353,7 +354,7 @@ func TestDspSessionSv1ProcessEventNil(t *testing.T) { }, } var reply *sessions.V1ProcessEventReply - result := dspSrv.SessionSv1ProcessEvent(CGREvent, reply) + result := dspSrv.SessionSv1ProcessEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -370,7 +371,7 @@ func TestDspSessionSv1ProcessEventErrorNil(t *testing.T) { }, } var reply *sessions.V1ProcessEventReply - result := dspSrv.SessionSv1ProcessEvent(CGREvent, reply) + result := dspSrv.SessionSv1ProcessEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -386,7 +387,7 @@ func TestDspSessionSv1GetCostNil(t *testing.T) { }, } var reply *sessions.V1GetCostReply - result := dspSrv.SessionSv1GetCost(CGREvent, reply) + result := dspSrv.SessionSv1GetCost(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -403,7 +404,7 @@ func TestDspSessionSv1GetCostErrorNil(t *testing.T) { }, } var reply *sessions.V1GetCostReply - result := dspSrv.SessionSv1GetCost(CGREvent, reply) + result := dspSrv.SessionSv1GetCost(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -417,7 +418,7 @@ func TestDspSessionSv1GetActiveSessionsNil(t *testing.T) { Tenant: "tenant", } var reply *[]*sessions.ExternalSession - result := dspSrv.SessionSv1GetActiveSessions(CGREvent, reply) + result := dspSrv.SessionSv1GetActiveSessions(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -432,7 +433,7 @@ func TestDspSessionSv1GetActiveSessionsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *[]*sessions.ExternalSession - result := dspSrv.SessionSv1GetActiveSessions(CGREvent, reply) + result := dspSrv.SessionSv1GetActiveSessions(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -446,7 +447,7 @@ func TestDspSessionSv1GetActiveSessionsCountNil(t *testing.T) { Tenant: "tenant", } var reply *int - result := dspSrv.SessionSv1GetActiveSessionsCount(CGREvent, reply) + result := dspSrv.SessionSv1GetActiveSessionsCount(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -461,7 +462,7 @@ func TestDspSessionSv1GetActiveSessionsCountErrorNil(t *testing.T) { Tenant: "tenant", } var reply *int - result := dspSrv.SessionSv1GetActiveSessionsCount(CGREvent, reply) + result := dspSrv.SessionSv1GetActiveSessionsCount(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -475,7 +476,7 @@ func TestDspSessionSv1ForceDisconnectNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1ForceDisconnect(CGREvent, reply) + result := dspSrv.SessionSv1ForceDisconnect(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -490,7 +491,7 @@ func TestDspSessionSv1ForceDisconnectErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1ForceDisconnect(CGREvent, reply) + result := dspSrv.SessionSv1ForceDisconnect(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -504,7 +505,7 @@ func TestDspSessionSv1GetPassiveSessionsNil(t *testing.T) { Tenant: "tenant", } var reply *[]*sessions.ExternalSession - result := dspSrv.SessionSv1GetPassiveSessions(CGREvent, reply) + result := dspSrv.SessionSv1GetPassiveSessions(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -519,7 +520,7 @@ func TestDspSessionSv1GetPassiveSessionsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *[]*sessions.ExternalSession - result := dspSrv.SessionSv1GetPassiveSessions(CGREvent, reply) + result := dspSrv.SessionSv1GetPassiveSessions(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -533,7 +534,7 @@ func TestDspSessionSv1ReplicateSessionsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1ReplicateSessions(CGREvent, reply) + result := dspSrv.SessionSv1ReplicateSessions(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -548,7 +549,7 @@ func TestDspSessionSv1ReplicateSessionsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1ReplicateSessions(CGREvent, reply) + result := dspSrv.SessionSv1ReplicateSessions(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -562,7 +563,7 @@ func TestDspSessionSv1GetPassiveSessionsCountNil(t *testing.T) { Tenant: "tenant", } var reply *int - result := dspSrv.SessionSv1GetPassiveSessionsCount(CGREvent, reply) + result := dspSrv.SessionSv1GetPassiveSessionsCount(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -577,7 +578,7 @@ func TestDspSessionSv1GetPassiveSessionsCountErrorNil(t *testing.T) { Tenant: "tenant", } var reply *int - result := dspSrv.SessionSv1GetPassiveSessionsCount(CGREvent, reply) + result := dspSrv.SessionSv1GetPassiveSessionsCount(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -591,7 +592,7 @@ func TestDspSessionSv1SetPassiveSessionNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1SetPassiveSession(CGREvent, reply) + result := dspSrv.SessionSv1SetPassiveSession(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -606,7 +607,7 @@ func TestDspSessionSv1SetPassiveSessionErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1SetPassiveSession(CGREvent, reply) + result := dspSrv.SessionSv1SetPassiveSession(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -620,7 +621,7 @@ func TestDspSessionSv1ActivateSessionsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1ActivateSessions(CGREvent, reply) + result := dspSrv.SessionSv1ActivateSessions(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -635,7 +636,7 @@ func TestDspSessionSv1ActivateSessionsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1ActivateSessions(CGREvent, reply) + result := dspSrv.SessionSv1ActivateSessions(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -649,7 +650,7 @@ func TestDspSessionSv1DeactivateSessionsNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1DeactivateSessions(CGREvent, reply) + result := dspSrv.SessionSv1DeactivateSessions(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -664,7 +665,7 @@ func TestDspSessionSv1DeactivateSessionsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.SessionSv1DeactivateSessions(CGREvent, reply) + result := dspSrv.SessionSv1DeactivateSessions(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -676,7 +677,7 @@ func TestDspSessionSv1STIRAuthenticateNil(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) CGREvent := &sessions.V1STIRAuthenticateArgs{} var reply *string - result := dspSrv.SessionSv1STIRAuthenticate(CGREvent, reply) + result := dspSrv.SessionSv1STIRAuthenticate(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -689,7 +690,7 @@ func TestDspSessionSv1STIRAuthenticateErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &sessions.V1STIRAuthenticateArgs{} var reply *string - result := dspSrv.SessionSv1STIRAuthenticate(CGREvent, reply) + result := dspSrv.SessionSv1STIRAuthenticate(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -701,7 +702,7 @@ func TestDspSessionSv1STIRIdentityNil(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) CGREvent := &sessions.V1STIRIdentityArgs{} var reply *string - result := dspSrv.SessionSv1STIRIdentity(CGREvent, reply) + result := dspSrv.SessionSv1STIRIdentity(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -714,7 +715,7 @@ func TestDspSessionSv1STIRIdentityErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &sessions.V1STIRIdentityArgs{} var reply *string - result := dspSrv.SessionSv1STIRIdentity(CGREvent, reply) + result := dspSrv.SessionSv1STIRIdentity(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/stats.go b/dispatchers/stats.go index a189887b3..2ff34d3ea 100644 --- a/dispatchers/stats.go +++ b/dispatchers/stats.go @@ -21,10 +21,11 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) StatSv1Ping(args *utils.CGREvent, reply *string) (err error) { +func (dS *DispatcherService) StatSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) } @@ -39,7 +40,7 @@ func (dS *DispatcherService) StatSv1Ping(args *utils.CGREvent, reply *string) (e return dS.Dispatch(args, utils.MetaStats, utils.StatSv1Ping, args, reply) } -func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *utils.CGREvent, +func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -52,7 +53,7 @@ func (dS *DispatcherService) StatSv1GetStatQueuesForEvent(args *utils.CGREvent, return dS.Dispatch(args, utils.MetaStats, utils.StatSv1GetStatQueuesForEvent, args, reply) } -func (dS *DispatcherService) StatSv1GetQueueStringMetrics(args *utils.TenantIDWithAPIOpts, +func (dS *DispatcherService) StatSv1GetQueueStringMetrics(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *map[string]string) (err error) { if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -69,7 +70,7 @@ func (dS *DispatcherService) StatSv1GetQueueStringMetrics(args *utils.TenantIDWi }, utils.MetaStats, utils.StatSv1GetQueueStringMetrics, args, reply) } -func (dS *DispatcherService) StatSv1ProcessEvent(args *utils.CGREvent, +func (dS *DispatcherService) StatSv1ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -82,7 +83,7 @@ func (dS *DispatcherService) StatSv1ProcessEvent(args *utils.CGREvent, return dS.Dispatch(args, utils.MetaStats, utils.StatSv1ProcessEvent, args, reply) } -func (dS *DispatcherService) StatSv1GetQueueFloatMetrics(args *utils.TenantIDWithAPIOpts, +func (dS *DispatcherService) StatSv1GetQueueFloatMetrics(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *map[string]float64) (err error) { if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { if err = dS.authorize(utils.StatSv1GetQueueFloatMetrics, @@ -98,7 +99,7 @@ func (dS *DispatcherService) StatSv1GetQueueFloatMetrics(args *utils.TenantIDWit }, utils.MetaStats, utils.StatSv1GetQueueFloatMetrics, args, reply) } -func (dS *DispatcherService) StatSv1GetQueueIDs(args *utils.TenantWithAPIOpts, +func (dS *DispatcherService) StatSv1GetQueueIDs(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *[]string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { diff --git a/dispatchers/stats_it_test.go b/dispatchers/stats_it_test.go index 83661186b..10c30e5dd 100644 --- a/dispatchers/stats_it_test.go +++ b/dispatchers/stats_it_test.go @@ -27,6 +27,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) @@ -69,7 +70,7 @@ func TestDspStatS(t *testing.T) { func testDspStsPingFailover(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.StatSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.StatSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -80,19 +81,19 @@ func testDspStsPingFailover(t *testing.T) { utils.OptsAPIKey: "stat12345", }, } - if err := dispEngine.RPC.Call(utils.StatSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine.stopEngine(t) - if err := dispEngine.RPC.Call(utils.StatSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.StatSv1Ping, &ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1Ping, &ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine.startEngine(t) @@ -120,7 +121,7 @@ func testDspStsGetStatFailover(t *testing.T) { utils.OptsAPIKey: "stat12345", }, } - if err := dispEngine.RPC.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1ProcessEvent, args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -136,7 +137,7 @@ func testDspStsGetStatFailover(t *testing.T) { }, } allEngine.stopEngine(t) - if err := dispEngine.RPC.Call(utils.StatSv1GetQueueStringMetrics, + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, args2, &metrics); err != nil { t.Error(err) } @@ -144,7 +145,7 @@ func testDspStsGetStatFailover(t *testing.T) { allEngine.startEngine(t) allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.StatSv1GetQueueStringMetrics, + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, args2, &metrics); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error NOT_FOUND but received %v and reply %v\n", err, reply) } @@ -153,12 +154,12 @@ func testDspStsGetStatFailover(t *testing.T) { func testDspStsPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.StatSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.StatSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.StatSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ utils.OptsAPIKey: "stat12345", @@ -185,7 +186,7 @@ func testDspStsTestAuthKey(t *testing.T) { utils.OptsAPIKey: "12345", }, } - if err := dispEngine.RPC.Call(utils.StatSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1ProcessEvent, args, &reply); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() { t.Error(err) } @@ -201,7 +202,7 @@ func testDspStsTestAuthKey(t *testing.T) { } var metrics map[string]string - if err := dispEngine.RPC.Call(utils.StatSv1GetQueueStringMetrics, + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, args2, &metrics); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() { t.Error(err) } @@ -225,7 +226,7 @@ func testDspStsTestAuthKey2(t *testing.T) { utils.OptsAPIKey: "stat12345", }, } - if err := dispEngine.RPC.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1ProcessEvent, args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -245,7 +246,7 @@ func testDspStsTestAuthKey2(t *testing.T) { utils.MetaTCD: "2m15s", } - if err := dispEngine.RPC.Call(utils.StatSv1GetQueueStringMetrics, + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, args2, &metrics); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics, metrics) { @@ -267,7 +268,7 @@ func testDspStsTestAuthKey2(t *testing.T) { utils.OptsAPIKey: "stat12345", }, } - if err := dispEngine.RPC.Call(utils.StatSv1ProcessEvent, args, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1ProcessEvent, args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -277,7 +278,7 @@ func testDspStsTestAuthKey2(t *testing.T) { utils.MetaTCC: "133", utils.MetaTCD: "3m0s", } - if err := dispEngine.RPC.Call(utils.StatSv1GetQueueStringMetrics, + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, args2, &metrics); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics, metrics) { @@ -303,7 +304,7 @@ func testDspStsTestAuthKey3(t *testing.T) { utils.MetaTCD: 180 * 1e9, } - if err := dispEngine.RPC.Call(utils.StatSv1GetQueueFloatMetrics, + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1GetQueueFloatMetrics, args2, &metrics); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics, metrics) { @@ -311,7 +312,7 @@ func testDspStsTestAuthKey3(t *testing.T) { } estats := []string{"Stats2", "Stats2_1"} - if err := dispEngine.RPC.Call(utils.StatSv1GetQueueIDs, + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1GetQueueIDs, &utils.TenantWithAPIOpts{ Tenant: "cgrates.org", APIOpts: map[string]any{ @@ -327,7 +328,7 @@ func testDspStsTestAuthKey3(t *testing.T) { } estats = []string{"Stats2"} - if err := dispEngine.RPC.Call(utils.StatSv1GetStatQueuesForEvent, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.StatSv1GetStatQueuesForEvent, &utils.CGREvent{ Tenant: "cgrates.org", ID: "GetStats", Event: map[string]any{ diff --git a/dispatchers/stats_test.go b/dispatchers/stats_test.go index 2bbce11b1..3f6796cc5 100644 --- a/dispatchers/stats_test.go +++ b/dispatchers/stats_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -32,7 +33,7 @@ func TestDspStatSv1PingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.StatSv1Ping(CGREvent, reply) + result := dspSrv.StatSv1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -44,7 +45,7 @@ func TestDspStatSv1PingNilEvent(t *testing.T) { dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} var reply *string - result := dspSrv.StatSv1Ping(nil, reply) + result := dspSrv.StatSv1Ping(context.Background(), nil, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -59,7 +60,7 @@ func TestDspStatSv1PingErrorNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.StatSv1Ping(CGREvent, reply) + result := dspSrv.StatSv1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -73,7 +74,7 @@ func TestDspStatSv1GetStatQueuesForEventNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.StatSv1GetStatQueuesForEvent(CGREvent, reply) + result := dspSrv.StatSv1GetStatQueuesForEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -88,7 +89,7 @@ func TestDspStatSv1GetStatQueuesForEventErrorNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.StatSv1GetStatQueuesForEvent(CGREvent, reply) + result := dspSrv.StatSv1GetStatQueuesForEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -104,7 +105,7 @@ func TestDspStatSv1GetQueueStringMetricsNil(t *testing.T) { }, } var reply *map[string]string - result := dspSrv.StatSv1GetQueueStringMetrics(CGREvent, reply) + result := dspSrv.StatSv1GetQueueStringMetrics(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -121,7 +122,7 @@ func TestDspStatSv1GetQueueStringMetricsErrorNil(t *testing.T) { }, } var reply *map[string]string - result := dspSrv.StatSv1GetQueueStringMetrics(CGREvent, reply) + result := dspSrv.StatSv1GetQueueStringMetrics(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -135,7 +136,7 @@ func TestDspStatSv1ProcessEventNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.StatSv1ProcessEvent(CGREvent, reply) + result := dspSrv.StatSv1ProcessEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -150,7 +151,7 @@ func TestDspStatSv1ProcessEventErrorNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.StatSv1ProcessEvent(CGREvent, reply) + result := dspSrv.StatSv1ProcessEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -166,7 +167,7 @@ func TestDspStatSv1GetQueueFloatMetricsNil(t *testing.T) { }, } var reply *map[string]float64 - result := dspSrv.StatSv1GetQueueFloatMetrics(CGREvent, reply) + result := dspSrv.StatSv1GetQueueFloatMetrics(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -183,7 +184,7 @@ func TestDspStatSv1GetQueueFloatMetricsErrorNil(t *testing.T) { }, } var reply *map[string]float64 - result := dspSrv.StatSv1GetQueueFloatMetrics(CGREvent, reply) + result := dspSrv.StatSv1GetQueueFloatMetrics(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -197,7 +198,7 @@ func TestDspStatSv1GetQueueIDsNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.StatSv1GetQueueIDs(CGREvent, reply) + result := dspSrv.StatSv1GetQueueIDs(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -212,7 +213,7 @@ func TestDspStatSv1GetQueueIDsErrorNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.StatSv1GetQueueIDs(CGREvent, reply) + result := dspSrv.StatSv1GetQueueIDs(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/dispatchers/thresholds.go b/dispatchers/thresholds.go index 059c0d7b0..b89b6d370 100644 --- a/dispatchers/thresholds.go +++ b/dispatchers/thresholds.go @@ -21,11 +21,12 @@ package dispatchers import ( "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) -func (dS *DispatcherService) ThresholdSv1Ping(args *utils.CGREvent, reply *string) (err error) { +func (dS *DispatcherService) ThresholdSv1Ping(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { args = new(utils.CGREvent) } @@ -39,7 +40,7 @@ func (dS *DispatcherService) ThresholdSv1Ping(args *utils.CGREvent, reply *strin return dS.Dispatch(args, utils.MetaThresholds, utils.ThresholdSv1Ping, args, reply) } -func (dS *DispatcherService) ThresholdSv1GetThresholdsForEvent(args *utils.CGREvent, +func (dS *DispatcherService) ThresholdSv1GetThresholdsForEvent(ctx *context.Context, args *utils.CGREvent, t *engine.Thresholds) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -52,7 +53,7 @@ func (dS *DispatcherService) ThresholdSv1GetThresholdsForEvent(args *utils.CGREv return dS.Dispatch(args, utils.MetaThresholds, utils.ThresholdSv1GetThresholdsForEvent, args, t) } -func (dS *DispatcherService) ThresholdSv1ProcessEvent(args *utils.CGREvent, +func (dS *DispatcherService) ThresholdSv1ProcessEvent(ctx *context.Context, args *utils.CGREvent, tIDs *[]string) (err error) { args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant) if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 { @@ -65,7 +66,7 @@ func (dS *DispatcherService) ThresholdSv1ProcessEvent(args *utils.CGREvent, return dS.Dispatch(args, utils.MetaThresholds, utils.ThresholdSv1ProcessEvent, args, tIDs) } -func (dS *DispatcherService) ThresholdSv1GetThresholdIDs(args *utils.TenantWithAPIOpts, tIDs *[]string) (err error) { +func (dS *DispatcherService) ThresholdSv1GetThresholdIDs(ctx *context.Context, args *utils.TenantWithAPIOpts, tIDs *[]string) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.Tenant != utils.EmptyString { tnt = args.Tenant @@ -82,7 +83,7 @@ func (dS *DispatcherService) ThresholdSv1GetThresholdIDs(args *utils.TenantWithA }, utils.MetaThresholds, utils.ThresholdSv1GetThresholdIDs, args, tIDs) } -func (dS *DispatcherService) ThresholdSv1GetThreshold(args *utils.TenantIDWithAPIOpts, th *engine.Threshold) (err error) { +func (dS *DispatcherService) ThresholdSv1GetThreshold(ctx *context.Context, args *utils.TenantIDWithAPIOpts, th *engine.Threshold) (err error) { tnt := dS.cfg.GeneralCfg().DefaultTenant if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString { tnt = args.TenantID.Tenant diff --git a/dispatchers/thresholds_it_test.go b/dispatchers/thresholds_it_test.go index 139579ffd..a3da35482 100644 --- a/dispatchers/thresholds_it_test.go +++ b/dispatchers/thresholds_it_test.go @@ -27,6 +27,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" ) @@ -70,7 +71,7 @@ func TestDspThresholdS(t *testing.T) { func testDspThPingFailover(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.ThresholdSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.ThresholdSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) @@ -82,19 +83,19 @@ func testDspThPingFailover(t *testing.T) { utils.OptsAPIKey: "thr12345", }, } - if err := dispEngine.RPC.Call(utils.ThresholdSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine.stopEngine(t) - if err := dispEngine.RPC.Call(utils.ThresholdSv1Ping, &ev, &reply); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1Ping, &ev, &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.ThresholdSv1Ping, &ev, &reply); err == nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1Ping, &ev, &reply); err == nil { t.Errorf("Expected error but received %v and reply %v\n", err, reply) } allEngine.startEngine(t) @@ -118,12 +119,12 @@ func testDspThProcessEventFailover(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.ThresholdSv1ProcessEvent, args, + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1ProcessEvent, args, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error NOT_FOUND but received %v and reply %v\n", err, ids) } allEngine2.stopEngine(t) - if err := dispEngine.RPC.Call(utils.ThresholdSv1ProcessEvent, args, &ids); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1ProcessEvent, args, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(eIDs, ids) { t.Errorf("expecting: %+v, received: %+v", eIDs, ids) @@ -133,12 +134,12 @@ func testDspThProcessEventFailover(t *testing.T) { func testDspThPing(t *testing.T) { var reply string - if err := allEngine.RPC.Call(utils.ThresholdSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := allEngine.RPC.Call(context.Background(), utils.ThresholdSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := dispEngine.RPC.Call(utils.ThresholdSv1Ping, &utils.CGREvent{ + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ @@ -166,12 +167,12 @@ func testDspThTestAuthKey(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.ThresholdSv1ProcessEvent, + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1ProcessEvent, args, &ids); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() { t.Error(err) } var th *engine.Thresholds - if err := dispEngine.RPC.Call(utils.ThresholdSv1GetThresholdsForEvent, args, + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1GetThresholdsForEvent, args, &th); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() { t.Error(err) } @@ -193,7 +194,7 @@ func testDspThTestAuthKey2(t *testing.T) { }, } - if err := dispEngine.RPC.Call(utils.ThresholdSv1ProcessEvent, args, &ids); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1ProcessEvent, args, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(eIDs, ids) { t.Errorf("expecting: %+v, received: %+v", eIDs, ids) @@ -206,7 +207,7 @@ func testDspThTestAuthKey2(t *testing.T) { Hits: 1, }, } - if err := dispEngine.RPC.Call(utils.ThresholdSv1GetThresholdsForEvent, args, &th); err != nil { + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1GetThresholdsForEvent, args, &th); err != nil { t.Error(err) } else if !reflect.DeepEqual((*eTh)[0].Tenant, (*th)[0].Tenant) { t.Errorf("expecting: %+v, received: %+v", (*eTh)[0].Tenant, (*th)[0].Tenant) @@ -224,7 +225,7 @@ func testDspThTestAuthKey3(t *testing.T) { ID: "THD_ACNT_1002", Hits: 1, } - if err := dispEngine.RPC.Call(utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: "cgrates.org", ID: "THD_ACNT_1002", @@ -245,7 +246,7 @@ func testDspThTestAuthKey3(t *testing.T) { var ids []string eIDs := []string{"THD_ACNT_1002"} - if err := dispEngine.RPC.Call(utils.ThresholdSv1GetThresholdIDs, &utils.TenantWithAPIOpts{ + if err := dispEngine.RPC.Call(context.Background(), utils.ThresholdSv1GetThresholdIDs, &utils.TenantWithAPIOpts{ Tenant: "cgrates.org", APIOpts: map[string]any{ utils.OptsAPIKey: "thr12345", diff --git a/dispatchers/thresholds_test.go b/dispatchers/thresholds_test.go index 3051ed09d..edfc86bee 100644 --- a/dispatchers/thresholds_test.go +++ b/dispatchers/thresholds_test.go @@ -21,6 +21,7 @@ package dispatchers import ( "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -30,7 +31,7 @@ func TestDspThresholdSv1PingNilEvent(t *testing.T) { cgrCfg := config.NewDefaultCGRConfig() dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil) var reply *string - result := dspSrv.ThresholdSv1Ping(nil, reply) + result := dspSrv.ThresholdSv1Ping(context.Background(), nil, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -44,7 +45,7 @@ func TestDspThresholdSv1PingNil(t *testing.T) { Tenant: "tenant", } var reply *string - result := dspSrv.ThresholdSv1Ping(CGREvent, reply) + result := dspSrv.ThresholdSv1Ping(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -57,7 +58,7 @@ func TestDspThresholdSv1PingErrorNil(t *testing.T) { cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"} CGREvent := &utils.CGREvent{} var reply *string - result := dspSrv.ThresholdSv1Ping(CGREvent, reply) + result := dspSrv.ThresholdSv1Ping(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -71,7 +72,7 @@ func TestDspThresholdSv1GetThresholdsForEventNil(t *testing.T) { Tenant: "tenant", } var reply *engine.Thresholds - result := dspSrv.ThresholdSv1GetThresholdsForEvent(CGREvent, reply) + result := dspSrv.ThresholdSv1GetThresholdsForEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -86,7 +87,7 @@ func TestDspThresholdSv1GetThresholdsEvnil(t *testing.T) { Tenant: "tenant", } var reply *engine.Thresholds - result := dspSrv.ThresholdSv1GetThresholdsForEvent(CGREvent, reply) + result := dspSrv.ThresholdSv1GetThresholdsForEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -100,7 +101,7 @@ func TestDspThresholdSv1ProcessEventNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.ThresholdSv1ProcessEvent(CGREvent, reply) + result := dspSrv.ThresholdSv1ProcessEvent(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -115,7 +116,7 @@ func TestDspThresholdSv1ProcessEventnNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.ThresholdSv1ProcessEvent(CGREvent, reply) + result := dspSrv.ThresholdSv1ProcessEvent(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -129,7 +130,7 @@ func TestDspThresholdSv1GetThresholdIDsNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.ThresholdSv1GetThresholdIDs(CGREvent, reply) + result := dspSrv.ThresholdSv1GetThresholdIDs(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -144,7 +145,7 @@ func TestDspThresholdSv1GetThresholdIDErrorNil(t *testing.T) { Tenant: "tenant", } var reply *[]string - result := dspSrv.ThresholdSv1GetThresholdIDs(CGREvent, reply) + result := dspSrv.ThresholdSv1GetThresholdIDs(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -160,7 +161,7 @@ func TestDspThresholdSv1GetThresholdNil(t *testing.T) { }, } var reply *engine.Threshold - result := dspSrv.ThresholdSv1GetThreshold(CGREvent, reply) + result := dspSrv.ThresholdSv1GetThreshold(context.Background(), CGREvent, reply) expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) @@ -177,7 +178,7 @@ func TestDspThresholdSv1GetThresholdErrorNil(t *testing.T) { }, } var reply *engine.Threshold - result := dspSrv.ThresholdSv1GetThreshold(CGREvent, reply) + result := dspSrv.ThresholdSv1GetThreshold(context.Background(), CGREvent, reply) expected := "MANDATORY_IE_MISSING: [ApiKey]" if result == nil || result.Error() != expected { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result) diff --git a/ees/amqp_it_test.go b/ees/amqp_it_test.go index ee4b5aec2..99122d5cb 100644 --- a/ees/amqp_it_test.go +++ b/ees/amqp_it_test.go @@ -22,11 +22,13 @@ along with this program. If not, see package ees import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +39,7 @@ var ( amqpConfDir string amqpCfgPath string amqpCfg *config.CGRConfig - amqpRPC *rpc.Client + amqpRPC *birpc.Client amqpExportPath string sTestsAMQP = []func(t *testing.T){ @@ -130,7 +132,7 @@ func testAMQPExportEvent(t *testing.T) { } var reply map[string]utils.MapStorage - if err := amqpRPC.Call(utils.EeSv1ProcessEvent, ev, &reply); err != nil { + if err := amqpRPC.Call(context.Background(), utils.EeSv1ProcessEvent, ev, &reply); err != nil { t.Error(err) } diff --git a/ees/amqpv1_it_test.go b/ees/amqpv1_it_test.go index 2dfd196f2..50c56a8d3 100644 --- a/ees/amqpv1_it_test.go +++ b/ees/amqpv1_it_test.go @@ -19,14 +19,15 @@ along with this program. If not, see package ees import ( - "context" "flag" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc/context" + amqpv1 "github.com/Azure/go-amqp" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ var ( amqpv1ConfDir string amqpv1CfgPath string amqpv1Cfg *config.CGRConfig - amqpv1RPC *rpc.Client + amqpv1RPC *birpc.Client amqpv1DialURL string amqpv1ConnOpts *amqpv1.ConnOptions @@ -135,7 +136,7 @@ func testAMQPv1ExportEvent(t *testing.T) { } var reply map[string]utils.MapStorage - if err := amqpv1RPC.Call(utils.EeSv1ProcessEvent, ev, &reply); err != nil { + if err := amqpv1RPC.Call(context.Background(), utils.EeSv1ProcessEvent, ev, &reply); err != nil { t.Error(err) } time.Sleep(2 * time.Second) diff --git a/ees/ees.go b/ees/ees.go index 7774bd61c..d5669c892 100644 --- a/ees/ees.go +++ b/ees/ees.go @@ -23,6 +23,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -79,8 +80,8 @@ func (eeS *EventExporterS) Shutdown() { eeS.setupCache(nil) // cleanup exporters } -// Call implements rpcclient.ClientConnector interface for internal RPC -func (eeS *EventExporterS) Call(serviceMethod string, args any, reply any) error { +// Call implements birpc.ClientConnector interface for internal RPC +func (eeS *EventExporterS) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.RPCCall(eeS, serviceMethod, args, reply) } @@ -110,7 +111,8 @@ func (eeS *EventExporterS) attrSProcessEvent(cgrEv *utils.CGREvent, attrIDs []st cgrEv.APIOpts[utils.OptsAttributesProfileIDs] = attrIDs cgrEv.APIOpts[utils.OptsContext] = utils.FirstNonEmpty(ctx, utils.IfaceAsString(cgrEv.APIOpts[utils.OptsContext]), utils.MetaEEs) - if err = eeS.connMgr.Call(eeS.cfg.EEsNoLksCfg().AttributeSConns, nil, utils.AttributeSv1ProcessEvent, + if err = eeS.connMgr.Call(context.TODO(), eeS.cfg.EEsNoLksCfg().AttributeSConns, + utils.AttributeSv1ProcessEvent, cgrEv, &rplyEv); err == nil && len(rplyEv.AlteredFields) != 0 { *cgrEv = *rplyEv.CGREvent } else if err != nil && @@ -122,7 +124,7 @@ func (eeS *EventExporterS) attrSProcessEvent(cgrEv *utils.CGREvent, attrIDs []st // V1ProcessEvent will be called each time a new event is received from readers // rply -> map[string]map[string]any -func (eeS *EventExporterS) V1ProcessEvent(cgrEv *engine.CGREventWithEeIDs, rply *map[string]map[string]any) (err error) { +func (eeS *EventExporterS) V1ProcessEvent(ctx *context.Context, cgrEv *engine.CGREventWithEeIDs, rply *map[string]map[string]any) (err error) { eeS.cfg.RLocks(config.EEsJson) defer eeS.cfg.RUnlocks(config.EEsJson) diff --git a/ees/ees_test.go b/ees/ees_test.go index 88cadea49..2fe6833ef 100644 --- a/ees/ees_test.go +++ b/ees/ees_test.go @@ -27,6 +27,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -80,7 +82,7 @@ func TestCall(t *testing.T) { filterS := engine.NewFilterS(cfg, nil, newDM) eeS := NewEventExporterS(cfg, filterS, nil) errExpect := "UNSUPPORTED_SERVICE_METHOD" - if err := eeS.Call("test", 24532, 43643); err == nil || err.Error() != errExpect { + if err := eeS.Call(context.Background(), "test", 24532, 43643); err == nil || err.Error() != errExpect { t.Errorf("Expected %q but received %q", errExpect, err) } } @@ -89,7 +91,7 @@ type testMockEvent struct { calls map[string]func(args any, reply any) error } -func (sT *testMockEvent) Call(method string, arg any, rply any) error { +func (sT *testMockEvent) Call(_ *context.Context, method string, arg any, rply any) error { if call, has := sT.calls[method]; !has { return rpcclient.ErrUnsupporteServiceMethod } else { @@ -119,9 +121,9 @@ func TestAttrSProcessEvent(t *testing.T) { newIDb := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) newDM := engine.NewDataManager(newIDb, cfg.CacheCfg(), nil) filterS := engine.NewFilterS(cfg, nil, newDM) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- testMock - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): clientConn, }) eeS := NewEventExporterS(cfg, filterS, connMgr) @@ -148,9 +150,9 @@ func TestAttrSProcessEvent2(t *testing.T) { newIDb := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) newDM := engine.NewDataManager(newIDb, cfg.CacheCfg(), nil) filterS := engine.NewFilterS(cfg, nil, newDM) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- testMock - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): clientConn, }) eeS := NewEventExporterS(cfg, filterS, connMgr) @@ -204,7 +206,7 @@ func TestV1ProcessEvent(t *testing.T) { rplyExpect := map[string]map[string]any{ "SQLExporterFull": {}, } - if err := eeS.V1ProcessEvent(cgrEv, &rply); err != nil { + if err := eeS.V1ProcessEvent(context.Background(), cgrEv, &rply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rply, rplyExpect) { t.Errorf("Expected %q but received %q", rplyExpect, rply) @@ -241,13 +243,13 @@ func TestV1ProcessEvent2(t *testing.T) { } var rply map[string]map[string]any errExpect := "NOT_FOUND" - if err := eeS.V1ProcessEvent(cgrEv, &rply); err == nil || err.Error() != errExpect { + if err := eeS.V1ProcessEvent(context.Background(), cgrEv, &rply); err == nil || err.Error() != errExpect { t.Errorf("Expecting %q but received %q", errExpect, err) } errExpect = "NOT_FOUND:test" eeS.cfg.EEsCfg().Exporters[0].Filters = []string{"test"} - if err := eeS.V1ProcessEvent(cgrEv, &rply); err == nil || err.Error() != errExpect { + if err := eeS.V1ProcessEvent(context.Background(), cgrEv, &rply); err == nil || err.Error() != errExpect { t.Errorf("Expecting %q but received %q", errExpect, err) } } @@ -274,7 +276,7 @@ func TestV1ProcessEvent3(t *testing.T) { } var rply map[string]map[string]any errExpect := "MANDATORY_IE_MISSING: [connIDs]" - if err := eeS.V1ProcessEvent(cgrEv, &rply); err == nil || err.Error() != errExpect { + if err := eeS.V1ProcessEvent(context.Background(), cgrEv, &rply); err == nil || err.Error() != errExpect { t.Errorf("Expecting %q but received %q", errExpect, err) } } @@ -311,7 +313,7 @@ func TestV1ProcessEvent4(t *testing.T) { } var rply map[string]map[string]any errExpect := "PARTIALLY_EXECUTED" - if err := eeS.V1ProcessEvent(cgrEv, &rply); err == nil || err.Error() != errExpect { + if err := eeS.V1ProcessEvent(context.Background(), cgrEv, &rply); err == nil || err.Error() != errExpect { t.Errorf("Expecting %q but received %q", errExpect, err) } else if len(rply) != 0 { t.Error("Unexpected reply result") @@ -373,7 +375,7 @@ func TestV1ProcessEventMockMetrics(t *testing.T) { } var rply map[string]map[string]any errExpect := "cannot cast to map[string]any 5 for positive exports" - if err := eeS.V1ProcessEvent(cgrEv, &rply); err == nil || err.Error() != errExpect { + if err := eeS.V1ProcessEvent(context.Background(), cgrEv, &rply); err == nil || err.Error() != errExpect { t.Errorf("Expecting %q but received %q", errExpect, err) } } @@ -406,7 +408,7 @@ func TestV1ProcessEvent5(t *testing.T) { eeS := NewEventExporterS(cfg, filterS, nil) var rply map[string]map[string]any errExpect := "unsupported exporter type: " - if err := eeS.V1ProcessEvent(cgrEv, &rply); err == nil || err.Error() != errExpect { + if err := eeS.V1ProcessEvent(context.Background(), cgrEv, &rply); err == nil || err.Error() != errExpect { t.Errorf("Expected %v but received %v", errExpect, err) } } @@ -432,7 +434,7 @@ func TestV1ProcessEvent6(t *testing.T) { }, } var rply map[string]map[string]any - if err := eeS.V1ProcessEvent(cgrEv, &rply); err != nil { + if err := eeS.V1ProcessEvent(context.Background(), cgrEv, &rply); err != nil { t.Error(err) } } diff --git a/ees/elastic_it_test.go b/ees/elastic_it_test.go index a50e99165..a21cf55fc 100644 --- a/ees/elastic_it_test.go +++ b/ees/elastic_it_test.go @@ -23,16 +23,17 @@ package ees import ( "bytes" - "context" "encoding/json" "flag" - "net/rpc" "os/exec" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/utils" elasticsearch "github.com/elastic/go-elasticsearch/v8" @@ -44,7 +45,7 @@ var ( elasticConfigDir string elasticCfgPath string elasticCfg *config.CGRConfig - elasticRpc *rpc.Client + elasticRpc *birpc.Client elasticServerPath = flag.Bool("elastic", false, "Run only if the user specify it") sTestsElastic = []func(t *testing.T){ @@ -225,16 +226,16 @@ func testElasticExportEvents(t *testing.T) { }, } var reply map[string]utils.MapStorage - if err := elasticRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { + if err := elasticRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { t.Error(err) } - if err := elasticRpc.Call(utils.EeSv1ProcessEvent, eventData, &reply); err != nil { + if err := elasticRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventData, &reply); err != nil { t.Error(err) } - if err := elasticRpc.Call(utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { + if err := elasticRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { t.Error(err) } - if err := elasticRpc.Call(utils.EeSv1ProcessEvent, eventSMSNoFields, &reply); err != nil { + if err := elasticRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventSMSNoFields, &reply); err != nil { t.Error(err) } } diff --git a/ees/filecsv_it_test.go b/ees/filecsv_it_test.go index fe4ed3dc8..218e6dd91 100644 --- a/ees/filecsv_it_test.go +++ b/ees/filecsv_it_test.go @@ -22,7 +22,6 @@ along with this program. If not, see package ees import ( - "net/rpc" "os" "path" "path/filepath" @@ -30,6 +29,9 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/utils" "github.com/cgrates/cgrates/engine" @@ -41,7 +43,7 @@ var ( csvConfigDir string csvCfgPath string csvCfg *config.CGRConfig - csvRpc *rpc.Client + csvRpc *birpc.Client sTestsCsv = []func(t *testing.T){ testCreateDirectory, @@ -184,13 +186,13 @@ func testCsvExportEvent(t *testing.T) { }, } var reply map[string]utils.MapStorage - if err := csvRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { + if err := csvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { t.Error(err) } - if err := csvRpc.Call(utils.EeSv1ProcessEvent, eventData, &reply); err != nil { + if err := csvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventData, &reply); err != nil { t.Error(err) } - if err := csvRpc.Call(utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { + if err := csvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { t.Error(err) } time.Sleep(time.Second) @@ -410,10 +412,10 @@ func testCsvExportComposedEvent(t *testing.T) { }, } var reply map[string]utils.MapStorage - if err := csvRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { + if err := csvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { t.Error(err) } - if err := csvRpc.Call(utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { + if err := csvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { t.Error(err) } time.Sleep(time.Second) @@ -448,7 +450,7 @@ func testCsvExportMaskedDestination(t *testing.T) { attrs := utils.AttrSetDestination{Id: "MASKED_DESTINATIONS", Prefixes: []string{"+4986517174963"}} var reply string - if err := csvRpc.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil { + if err := csvRpc.Call(context.Background(), utils.APIerSv1SetDestination, &attrs, &reply); err != nil { t.Error("Unexpected error", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -480,7 +482,7 @@ func testCsvExportMaskedDestination(t *testing.T) { }, } var rply map[string]utils.MapStorage - if err := csvRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &rply); err != nil { + if err := csvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &rply); err != nil { t.Error(err) } time.Sleep(time.Second) @@ -593,13 +595,13 @@ func testCsvExportEventWithInflateTemplate(t *testing.T) { }, } var reply map[string]utils.MapStorage - if err := csvRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { + if err := csvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { t.Error(err) } - if err := csvRpc.Call(utils.EeSv1ProcessEvent, eventData, &reply); err != nil { + if err := csvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventData, &reply); err != nil { t.Error(err) } - if err := csvRpc.Call(utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { + if err := csvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { t.Error(err) } time.Sleep(time.Second) @@ -662,7 +664,7 @@ func testCsvExportNotFoundExporter(t *testing.T) { } var reply map[string]utils.MapStorage - if err := csvRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &reply); err == nil || + if err := csvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/ees/filefwv_it_test.go b/ees/filefwv_it_test.go index 61e0a1ca8..858aadcc4 100644 --- a/ees/filefwv_it_test.go +++ b/ees/filefwv_it_test.go @@ -22,7 +22,6 @@ along with this program. If not, see package ees import ( - "net/rpc" "os" "path" "path/filepath" @@ -30,6 +29,9 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -39,7 +41,7 @@ var ( fwvConfigDir string fwvCfgPath string fwvCfg *config.CGRConfig - fwvRpc *rpc.Client + fwvRpc *birpc.Client sTestsFwv = []func(t *testing.T){ testCreateDirectory, @@ -125,7 +127,7 @@ func testFwvExportEvent(t *testing.T) { }, } var reply map[string]utils.MapStorage - if err := fwvRpc.Call(utils.EeSv1ProcessEvent, event, &reply); err != nil { + if err := fwvRpc.Call(context.Background(), utils.EeSv1ProcessEvent, event, &reply); err != nil { t.Error(err) } time.Sleep(time.Second) diff --git a/ees/httppost_it_test.go b/ees/httppost_it_test.go index ef2498630..af454ba1c 100644 --- a/ees/httppost_it_test.go +++ b/ees/httppost_it_test.go @@ -24,12 +24,14 @@ package ees import ( "io" "net/http" - "net/rpc" "net/url" "path" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/utils" "github.com/cgrates/cgrates/config" @@ -40,7 +42,7 @@ var ( httpPostConfigDir string httpPostCfgPath string httpPostCfg *config.CGRConfig - httpPostRpc *rpc.Client + httpPostRpc *birpc.Client httpValues url.Values sTestsHTTPPost = []func(t *testing.T){ @@ -221,7 +223,7 @@ func testHTTPExportEvent(t *testing.T) { } var reply map[string]utils.MapStorage - if err := httpPostRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { + if err := httpPostRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) @@ -244,7 +246,7 @@ func testHTTPExportEvent(t *testing.T) { t.Errorf("Expected %+v, received: %+v", expHeader, httpJsonHdr["Origin"]) } - if err := httpPostRpc.Call(utils.EeSv1ProcessEvent, eventData, &reply); err != nil { + if err := httpPostRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventData, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) @@ -267,7 +269,7 @@ func testHTTPExportEvent(t *testing.T) { t.Errorf("Expected %+v, received: %+v", expHeader, httpJsonHdr["Origin"]) } - if err := httpPostRpc.Call(utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { + if err := httpPostRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) @@ -289,7 +291,7 @@ func testHTTPExportEvent(t *testing.T) { if len(httpJsonHdr["Origin"]) == 0 || httpJsonHdr["Origin"][0] != expHeader { t.Errorf("Expected %+v, received: %+v", expHeader, httpJsonHdr["Origin"]) } - if err := httpPostRpc.Call(utils.EeSv1ProcessEvent, eventSMSNoFields, &reply); err != nil { + if err := httpPostRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventSMSNoFields, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) diff --git a/ees/kafka_it_test.go b/ees/kafka_it_test.go index 88614eb9f..8a54f3a95 100644 --- a/ees/kafka_it_test.go +++ b/ees/kafka_it_test.go @@ -22,16 +22,17 @@ along with this program. If not, see package ees import ( - "context" "net" - "net/rpc" "path" "strconv" "testing" "time" + "github.com/cgrates/birpc/context" + kafka "github.com/segmentio/kafka-go" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -41,7 +42,7 @@ var ( kafkaConfigDir string kafkaCfgPath string kafkaCfg *config.CGRConfig - kafkaRpc *rpc.Client + kafkaRpc *birpc.Client sTestsKafka = []func(t *testing.T){ testCreateDirectory, @@ -159,7 +160,7 @@ func testKafkaExportEvent(t *testing.T) { } var reply map[string]map[string]any - if err := kafkaRpc.Call(utils.EeSv1ProcessEvent, event, &reply); err != nil { + if err := kafkaRpc.Call(context.Background(), utils.EeSv1ProcessEvent, event, &reply); err != nil { t.Error(err) } time.Sleep(time.Second) diff --git a/ees/lib_test.go b/ees/lib_test.go index 336974885..9cc31703f 100644 --- a/ees/lib_test.go +++ b/ees/lib_test.go @@ -21,11 +21,11 @@ package ees import ( "errors" "flag" - "net/rpc" - "net/rpc/jsonrpc" "os" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/config" @@ -38,12 +38,12 @@ var ( encoding = flag.String("rpc", utils.MetaJSON, "what encoding would be used for rpc communication") ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/ees/poster_it_test.go b/ees/poster_it_test.go index 5f2403b93..b77d8289b 100644 --- a/ees/poster_it_test.go +++ b/ees/poster_it_test.go @@ -21,7 +21,6 @@ along with this program. If not, see package ees import ( - "context" "encoding/json" "flag" "net/http" @@ -31,6 +30,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" + amqpv1 "github.com/Azure/go-amqp" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" diff --git a/ees/posterjsonmap_it_test.go b/ees/posterjsonmap_it_test.go index ea2527f86..7806ca176 100644 --- a/ees/posterjsonmap_it_test.go +++ b/ees/posterjsonmap_it_test.go @@ -24,11 +24,13 @@ package ees import ( "encoding/json" "net/http" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/utils" "github.com/cgrates/cgrates/config" @@ -39,7 +41,7 @@ var ( httpJSONMapConfigDir string httpJSONMapCfgPath string httpJSONMapCfg *config.CGRConfig - httpJSONMapRpc *rpc.Client + httpJSONMapRpc *birpc.Client httpJsonMap map[string]string httpJsonHdr http.Header @@ -224,7 +226,7 @@ func testHTTPJsonMapExportEvent(t *testing.T) { }, } var reply map[string]utils.MapStorage - if err := httpJSONMapRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { + if err := httpJSONMapRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) @@ -247,7 +249,7 @@ func testHTTPJsonMapExportEvent(t *testing.T) { if len(httpJsonHdr["Origin"]) == 0 || httpJsonHdr["Origin"][0] != expHeader { t.Errorf("Expected %+v, received: %+v", expHeader, httpJsonHdr["Origin"]) } - if err := httpJSONMapRpc.Call(utils.EeSv1ProcessEvent, eventData, &reply); err != nil { + if err := httpJSONMapRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventData, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) @@ -270,7 +272,7 @@ func testHTTPJsonMapExportEvent(t *testing.T) { if len(httpJsonHdr["Origin"]) == 0 || httpJsonHdr["Origin"][0] != expHeader { t.Errorf("Expected %+v, received: %+v", expHeader, httpJsonHdr["Origin"]) } - if err := httpJSONMapRpc.Call(utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { + if err := httpJSONMapRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventSMS, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) @@ -294,7 +296,7 @@ func testHTTPJsonMapExportEvent(t *testing.T) { t.Errorf("Expected %+v, received: %+v", expHeader, httpJsonHdr["Origin"]) } - if err := httpJSONMapRpc.Call(utils.EeSv1ProcessEvent, eventSMSNoFields, &reply); err != nil { + if err := httpJSONMapRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventSMSNoFields, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) diff --git a/ees/rpc.go b/ees/rpc.go index 86ddb4563..6aace36a3 100644 --- a/ees/rpc.go +++ b/ees/rpc.go @@ -23,6 +23,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -70,7 +71,7 @@ func (e *RPCee) ExportEvent(args any, _ string) (err error) { e.Lock() defer e.Unlock() var rply string - return e.connMgr.Call(e.connIDs, nil, e.serviceMethod, args, &rply) + return e.connMgr.Call(context.TODO(), e.connIDs, e.serviceMethod, args, &rply) } func (e *RPCee) Close() (err error) { diff --git a/ees/rpc_test.go b/ees/rpc_test.go index 1bbab90eb..a74a000e5 100644 --- a/ees/rpc_test.go +++ b/ees/rpc_test.go @@ -23,10 +23,10 @@ import ( "testing" "time" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestNewRpcEE(t *testing.T) { @@ -35,7 +35,7 @@ func TestNewRpcEE(t *testing.T) { if err != nil { t.Error(err) } - connMgr := engine.NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan rpcclient.ClientConnector)) + connMgr := engine.NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan birpc.ClientConnector)) rcv, err := NewRpcEE(eeSCfg, dc, connMgr) if err != nil { @@ -108,7 +108,7 @@ func TestRPCConnect(t *testing.T) { if err != nil { t.Error(err) } - connMgr := engine.NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan rpcclient.ClientConnector)) + connMgr := engine.NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan birpc.ClientConnector)) rpcEe, err := NewRpcEE(eeSCfg, dc, connMgr) if err != nil { t.Error(err) @@ -124,7 +124,7 @@ func TestRPCClose(t *testing.T) { if err != nil { t.Error(err) } - connMgr := engine.NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan rpcclient.ClientConnector)) + connMgr := engine.NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan birpc.ClientConnector)) rpcEe, err := NewRpcEE(eeSCfg, dc, connMgr) if err != nil { t.Error(err) @@ -145,7 +145,7 @@ func TestRPCGetMetrics(t *testing.T) { "just_a_field": "just_a_value", }, } - connMgr := engine.NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan rpcclient.ClientConnector)) + connMgr := engine.NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan birpc.ClientConnector)) rpcEe, err := NewRpcEE(eeSCfg, dc, connMgr) if err != nil { t.Error(err) @@ -162,7 +162,7 @@ func TestRPCPrepareMap(t *testing.T) { if err != nil { t.Error(err) } - connMgr := engine.NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan rpcclient.ClientConnector)) + connMgr := engine.NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan birpc.ClientConnector)) rpcEe, err := NewRpcEE(eeSCfg, dc, connMgr) if err != nil { t.Error(err) diff --git a/ees/s3_it_test.go b/ees/s3_it_test.go index 69f8926dc..45edb89d3 100644 --- a/ees/s3_it_test.go +++ b/ees/s3_it_test.go @@ -24,16 +24,18 @@ package ees import ( "flag" "fmt" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc/context" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3/s3manager" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -45,7 +47,7 @@ var ( s3ConfDir string s3CfgPath string s3Cfg *config.CGRConfig - s3RPC *rpc.Client + s3RPC *birpc.Client sTestsS3 = []func(t *testing.T){ testS3LoadConfig, @@ -138,7 +140,7 @@ func testS3ExportEvent(t *testing.T) { } var reply map[string]utils.MapStorage - if err := s3RPC.Call(utils.EeSv1ProcessEvent, ev, &reply); err != nil { + if err := s3RPC.Call(context.Background(), utils.EeSv1ProcessEvent, ev, &reply); err != nil { t.Error(err) } time.Sleep(2 * time.Second) diff --git a/ees/sql_it_test.go b/ees/sql_it_test.go index 25b56b6bd..978fa528c 100644 --- a/ees/sql_it_test.go +++ b/ees/sql_it_test.go @@ -23,11 +23,13 @@ package ees import ( "fmt" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/utils" "gorm.io/driver/mysql" @@ -42,7 +44,7 @@ var ( sqlEeConfigDir string sqlEeCfgPath string sqlEeCfg *config.CGRConfig - sqlEeRpc *rpc.Client + sqlEeRpc *birpc.Client db2 *gorm.DB dbConnString = "cgrates:CGRateS.org@tcp(127.0.0.1:3306)/%s?charset=utf8&loc=Local&parseTime=true&sql_mode='ALLOW_INVALID_DATES'" @@ -300,7 +302,7 @@ func testSqlEeExportEventFull(t *testing.T) { } var reply map[string]utils.MapStorage - if err := sqlEeRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { + if err := sqlEeRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) @@ -336,7 +338,7 @@ func testSqlEeExportEventPartial(t *testing.T) { } var reply map[string]utils.MapStorage - if err := sqlEeRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { + if err := sqlEeRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) diff --git a/ees/sqs_it_test.go b/ees/sqs_it_test.go index a5a3e64f5..9382c9170 100644 --- a/ees/sqs_it_test.go +++ b/ees/sqs_it_test.go @@ -23,16 +23,18 @@ package ees import ( "flag" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc/context" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sqs" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -45,7 +47,7 @@ var ( sqsConfDir string sqsCfgPath string sqsCfg *config.CGRConfig - sqsRPC *rpc.Client + sqsRPC *birpc.Client sTestsSQS = []func(t *testing.T){ testSQSLoadConfig, @@ -137,7 +139,7 @@ func testSQSExportEvent(t *testing.T) { } var reply map[string]utils.MapStorage - if err := sqsRPC.Call(utils.EeSv1ProcessEvent, ev, &reply); err != nil { + if err := sqsRPC.Call(context.Background(), utils.EeSv1ProcessEvent, ev, &reply); err != nil { t.Error(err) } diff --git a/ees/virtual_ee_it_test.go b/ees/virtual_ee_it_test.go index 7a7f01d67..eca784b5e 100644 --- a/ees/virtual_ee_it_test.go +++ b/ees/virtual_ee_it_test.go @@ -22,7 +22,6 @@ along with this program. If not, see package ees import ( - "net/rpc" "os" "path" "path/filepath" @@ -30,6 +29,9 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/utils" "github.com/cgrates/cgrates/config" @@ -40,7 +42,7 @@ var ( virtConfigDir string virtCfgPath string virtCfg *config.CGRConfig - virtRpc *rpc.Client + virtRpc *birpc.Client sTestsVirt = []func(t *testing.T){ testCreateDirectory, @@ -126,7 +128,7 @@ func testVirtExportSupplierEvent(t *testing.T) { } var reply map[string]utils.MapStorage - if err := virtRpc.Call(utils.EeSv1ProcessEvent, supplierEvent, &reply); err != nil { + if err := virtRpc.Call(context.Background(), utils.EeSv1ProcessEvent, supplierEvent, &reply); err != nil { t.Error(err) } time.Sleep(10 * time.Millisecond) @@ -159,7 +161,7 @@ func testVirtExportEvents(t *testing.T) { }, } var reply map[string]utils.MapStorage - if err := virtRpc.Call(utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { + if err := virtRpc.Call(context.Background(), utils.EeSv1ProcessEvent, eventVoice, &reply); err != nil { t.Error(err) } time.Sleep(time.Second) diff --git a/engine/account.go b/engine/account.go index b5727e9b3..9d26b4c9e 100644 --- a/engine/account.go +++ b/engine/account.go @@ -26,6 +26,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" @@ -565,7 +566,7 @@ func (acc *Account) debitCreditBalance(cd *CallDescriptor, count bool, dryRun bo }, } var tIDs []string - if err := connMgr.Call(config.CgrConfig().RalsCfg().ThresholdSConns, nil, + if err := connMgr.Call(context.TODO(), config.CgrConfig().RalsCfg().ThresholdSConns, utils.ThresholdSv1ProcessEvent, thEv, &tIDs); err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning( @@ -1082,7 +1083,7 @@ func (acc *Account) Publish(initBal map[string]float64) { } if len(config.CgrConfig().RalsCfg().ThresholdSConns) != 0 { var tIDs []string - if err := connMgr.Call(config.CgrConfig().RalsCfg().ThresholdSConns, nil, + if err := connMgr.Call(context.TODO(), config.CgrConfig().RalsCfg().ThresholdSConns, utils.ThresholdSv1ProcessEvent, cgrEv, &tIDs); err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning( @@ -1091,7 +1092,7 @@ func (acc *Account) Publish(initBal map[string]float64) { } if len(config.CgrConfig().RalsCfg().StatSConns) != 0 { var stsIDs []string - if err := connMgr.Call(config.CgrConfig().RalsCfg().StatSConns, nil, + if err := connMgr.Call(context.TODO(), config.CgrConfig().RalsCfg().StatSConns, utils.StatSv1ProcessEvent, cgrEv, &stsIDs); err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning( diff --git a/engine/account_test.go b/engine/account_test.go index e0fe0b164..23cb01551 100644 --- a/engine/account_test.go +++ b/engine/account_test.go @@ -29,9 +29,10 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) var ( @@ -3030,17 +3031,17 @@ func TestDebitCreditBalance(t *testing.T) { config.SetCgrConfig(config.NewDefaultCGRConfig()) }() cfg.RalsCfg().ThresholdSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ThresholdSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpl := &[]string{"id"} *reply.(*[]string) = *rpl return errors.New("Can't process Event") }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): clientConn, }) cd := &CallDescriptor{ diff --git a/engine/action.go b/engine/action.go index bde218e4e..02046ad05 100644 --- a/engine/action.go +++ b/engine/action.go @@ -32,6 +32,8 @@ import ( "strings" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" @@ -216,7 +218,7 @@ func cdrLogAction(acc *Account, a *Action, acs Actions, _ *FilterS, extraData an cdrs = append(cdrs, cdr) var rply string // After compute the CDR send it to CDR Server to be processed - if err := connMgr.Call(config.CgrConfig().SchedulerCfg().CDRsConns, nil, + if err := connMgr.Call(context.TODO(), config.CgrConfig().SchedulerCfg().CDRsConns, utils.CDRsV1ProcessEvent, &ArgV1ProcessEvent{ Flags: []string{utils.ConcatenatedKey(utils.MetaChargers, "false")}, // do not try to get the chargers for cdrlog @@ -447,7 +449,8 @@ func setddestinations(ub *Account, a *Action, acs Actions, _ *FilterS, extraData continue } var sts StatQueue - if err = connMgr.Call(config.CgrConfig().RalsCfg().StatSConns, nil, utils.StatSv1GetStatQueue, + if err = connMgr.Call(context.TODO(), config.CgrConfig().RalsCfg().StatSConns, + utils.StatSv1GetStatQueue, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, @@ -656,35 +659,43 @@ func cgrRPCAction(ub *Account, a *Action, acs Actions, _ *FilterS, extraData any if params, err = utils.GetRpcParams(req.Method); err != nil { return } - var client rpcclient.ClientConnector + var client birpc.ClientConnector if req.Address == utils.MetaInternal { - client = params.Object.(rpcclient.ClientConnector) - } else if client, err = rpcclient.NewRPCClient(utils.TCP, req.Address, false, "", "", "", - req.Attempts, 0, config.CgrConfig().GeneralCfg().ConnectTimeout, - config.CgrConfig().GeneralCfg().ReplyTimeout, req.Transport, - nil, false, nil); err != nil { + client = params.Object.(birpc.ClientConnector) + } else if client, err = rpcclient.NewRPCClient(context.TODO(), utils.TCP, req.Address, false, "", "", "", + req.Attempts, 0, + config.CgrConfig().GeneralCfg().MaxReconnectInterval, + utils.FibDuration, + config.CgrConfig().GeneralCfg().ConnectTimeout, + config.CgrConfig().GeneralCfg().ReplyTimeout, + req.Transport, nil, false, nil); err != nil { return } - in, out := params.InParam, params.OutParam - //utils.Logger.Info("Params: " + utils.ToJSON(req.Params)) - //p, err := utils.FromMapStringInterfaceValue(req.Params, in) - if err = mapstructure.Decode(req.Params, in); err != nil { + + // Decode's output parameter requires a pointer. + if reflect.TypeOf(params.InParam).Kind() == reflect.Pointer { + err = mapstructure.Decode(req.Params, params.InParam) + } else { + err = mapstructure.Decode(req.Params, ¶ms.InParam) + + } + if err != nil { utils.Logger.Info("<*cgr_rpc> err: " + err.Error()) return } - if in == nil { + if params.InParam == nil { utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> nil params err: req.Params: %+v params: %+v", req.Params, params)) return utils.ErrParserError } - utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> calling: %s with: %s and result %v", req.Method, utils.ToJSON(in), out)) + utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> calling: %s with: %s and result %v", req.Method, utils.ToJSON(params.InParam), params.OutParam)) if !req.Async { - err = client.Call(req.Method, in, out) - utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> result: %s err: %v", utils.ToJSON(out), err)) + err = client.Call(context.TODO(), req.Method, params.InParam, params.OutParam) + utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> result: %s err: %v", utils.ToJSON(params.OutParam), err)) return } go func() { - err := client.Call(req.Method, in, out) - utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> result: %s err: %v", utils.ToJSON(out), err)) + err := client.Call(context.TODO(), req.Method, params.InParam, params.OutParam) + utils.Logger.Info(fmt.Sprintf("<*cgr_rpc> result: %s err: %v", utils.ToJSON(params.OutParam), err)) }() return } @@ -987,7 +998,7 @@ func export(ub *Account, a *Action, acs Actions, _ *FilterS, extraData any) (err CGREvent: cgrEv, } var rply map[string]map[string]any - return connMgr.Call(config.CgrConfig().ApierCfg().EEsConns, nil, + return connMgr.Call(context.TODO(), config.CgrConfig().ApierCfg().EEsConns, utils.EeSv1ProcessEvent, args, &rply) } @@ -996,7 +1007,7 @@ func resetThreshold(ub *Account, a *Action, acs Actions, _ *FilterS, extraData a TenantID: utils.NewTenantID(a.ExtraParameters), } var rply string - return connMgr.Call(config.CgrConfig().SchedulerCfg().ThreshSConns, nil, + return connMgr.Call(context.TODO(), config.CgrConfig().SchedulerCfg().ThreshSConns, utils.ThresholdSv1ResetThreshold, args, &rply) } @@ -1005,7 +1016,7 @@ func resetStatQueue(ub *Account, a *Action, acs Actions, _ *FilterS, extraData a TenantID: utils.NewTenantID(a.ExtraParameters), } var rply string - return connMgr.Call(config.CgrConfig().SchedulerCfg().StatSConns, nil, + return connMgr.Call(context.TODO(), config.CgrConfig().SchedulerCfg().StatSConns, utils.StatSv1ResetStatQueue, args, &rply) } diff --git a/engine/actions_test.go b/engine/actions_test.go index 5db0fd271..5b96dd688 100644 --- a/engine/actions_test.go +++ b/engine/actions_test.go @@ -31,6 +31,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" @@ -2454,39 +2456,11 @@ type Attr struct { Age float64 } -func (trpcp *TestRPCParameters) Hopa(in Attr, out *float64) error { +func (trpcp *TestRPCParameters) Hopa(ctx *context.Context, in *Attr, out *float64) error { trpcp.status = utils.OK return nil } -func (trpcp *TestRPCParameters) Call(serviceMethod string, args any, reply any) error { - parts := strings.Split(serviceMethod, ".") - if len(parts) != 2 { - return utils.ErrNotImplemented - } - // get method - method := reflect.ValueOf(trpcp).MethodByName(parts[1]) - if !method.IsValid() { - return utils.ErrNotImplemented - } - - // construct the params - params := []reflect.Value{reflect.ValueOf(args).Elem(), reflect.ValueOf(reply)} - - ret := method.Call(params) - if len(ret) != 1 { - return utils.ErrServerError - } - if ret[0].Interface() == nil { - return nil - } - err, ok := ret[0].Interface().(error) - if !ok { - return utils.ErrServerError - } - return err -} - func TestCgrRpcAction(t *testing.T) { trpcp := &TestRPCParameters{} utils.RegisterRpcParams("", trpcp) @@ -2644,7 +2618,7 @@ type RPCMock struct { args *ArgV1ProcessEvent } -func (r *RPCMock) Call(method string, args any, rply any) error { +func (r *RPCMock) Call(ctx *context.Context, method string, args any, rply any) error { if method != utils.CDRsV1ProcessEvent { return rpcclient.ErrUnsupporteServiceMethod } @@ -2667,10 +2641,10 @@ func TestCdrLogAction(t *testing.T) { dfltCfg.SchedulerCfg().CDRsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs)} config.SetCgrConfig(dfltCfg) - internalChan := make(chan rpcclient.ClientConnector, 1) + internalChan := make(chan birpc.ClientConnector, 1) internalChan <- &mock - NewConnManager(dfltCfg, map[string]chan rpcclient.ClientConnector{ + NewConnManager(dfltCfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs): internalChan, }) @@ -2947,8 +2921,8 @@ func TestActionSetDDestinations(t *testing.T) { }, } ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.StatSv1GetStatQueue: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.StatSv1GetStatQueue: func(ctx *context.Context, args, reply any) error { rpl := &StatQueue{ Tenant: "cgrates", ID: "id", @@ -2971,9 +2945,9 @@ func TestActionSetDDestinations(t *testing.T) { }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg): clientconn, }) SetConnManager(connMgr) @@ -3071,20 +3045,20 @@ func TestActionPublishAccount(t *testing.T) { }() cfg.RalsCfg().ThresholdSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ThreshSConnsCfg)} cfg.RalsCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ThresholdSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { *reply.(*[]string) = []string{"*thr"} return errors.New("Can't publish!") }, - utils.StatSv1ProcessEvent: func(args, reply any) error { + utils.StatSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { *reply.(*[]string) = []string{"*stat"} return errors.New("Can't publish!") }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ThreshSConnsCfg): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg): clientConn, }) @@ -3167,8 +3141,8 @@ func TestExportAction(t *testing.T) { cfg.ApierCfg().EEsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.EEsConnsCfg)} config.SetCgrConfig(cfg) ccMock := &ccMock{ - calls: map[string]func(args, reply any) error{ - utils.EeSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args, reply any) error{ + utils.EeSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpl := &map[string]map[string]any{} *reply.(*map[string]map[string]any) = *rpl @@ -3176,9 +3150,9 @@ func TestExportAction(t *testing.T) { }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.EEsConnsCfg): clientconn, }) SetConnManager(connMgr) @@ -3263,17 +3237,17 @@ func TestResetStatQueue(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.SchedulerCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg)} ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.StatSv1ResetStatQueue: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.StatSv1ResetStatQueue: func(ctx *context.Context, args, reply any) error { rpl := "reset" *reply.(*string) = rpl return nil }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg): clientconn, }) SetConnManager(connMgr) @@ -3294,17 +3268,17 @@ func TestResetTreshold(t *testing.T) { cfg.SchedulerCfg().ThreshSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ThreshSConnsCfg)} ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ThresholdSv1ResetThreshold: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ThresholdSv1ResetThreshold: func(ctx *context.Context, args, reply any) error { rpl := "threshold_reset" *reply.(*string) = rpl return nil }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ThreshSConnsCfg): clientconn, }) SetConnManager(connMgr) @@ -3755,19 +3729,19 @@ func TestRemoveAccountActionErr(t *testing.T) { }, } cfg.DataDbCfg().RmtConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetAccountActionPlans: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetAccountActionPlans: func(ctx *context.Context, args, reply any) error { return errors.New("ActionPlans not found") }, - utils.ReplicatorSv1GetActionPlan: func(args, reply any) error { + utils.ReplicatorSv1GetActionPlan: func(ctx *context.Context, args, reply any) error { return errors.New("ActionPlan not found") }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) a := &Action{ @@ -4035,10 +4009,10 @@ func TestSetDestinationsErr(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.StatSv1GetStatQueue: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.StatSv1GetStatQueue: func(ctx *context.Context, args, reply any) error { rpl := StatQueue{ Tenant: "cgrates.org", ID: "StatsID", @@ -4070,12 +4044,12 @@ func TestSetDestinationsErr(t *testing.T) { *reply.(*StatQueue) = rpl return nil }, - utils.ReplicatorSv1SetReverseDestination: func(args, reply any) error { + utils.ReplicatorSv1SetReverseDestination: func(ctx *context.Context, args, reply any) error { return utils.ErrNotImplemented }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) @@ -4160,15 +4134,15 @@ func TestRemoveAccountActionLogg(t *testing.T) { cfg.DataDbCfg().RmtConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} cfg.DataDbCfg().RplConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetAccountActionPlans: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetAccountActionPlans: func(ctx *context.Context, args, reply any) error { rpl := []string{"PACKAGE_10_SHARED_A_5"} *reply.(*[]string) = rpl return nil }, - utils.ReplicatorSv1GetActionPlan: func(args, reply any) error { + utils.ReplicatorSv1GetActionPlan: func(ctx *context.Context, args, reply any) error { rpl := ActionPlan{ Id: "PACKAGE_10_SHARED_A_5", AccountIDs: utils.StringMap{ @@ -4178,11 +4152,11 @@ func TestRemoveAccountActionLogg(t *testing.T) { *reply.(**ActionPlan) = &rpl return nil }, - utils.ReplicatorSv1SetActionPlan: func(args, reply any) error { + utils.ReplicatorSv1SetActionPlan: func(ctx *context.Context, args, reply any) error { return utils.ErrNotFound }, }} - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) diff --git a/engine/attributes.go b/engine/attributes.go index 8c2a03ccd..5c42ad40b 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -26,6 +26,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -242,7 +243,7 @@ func (alS *AttributeService) processEvent(tnt string, args *utils.CGREvent, evNm } // V1GetAttributeForEvent returns the AttributeProfile that matches the event -func (alS *AttributeService) V1GetAttributeForEvent(args *utils.CGREvent, +func (alS *AttributeService) V1GetAttributeForEvent(ctx *context.Context, args *utils.CGREvent, attrPrfl *AttributeProfile) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) @@ -282,7 +283,7 @@ func (alS *AttributeService) V1GetAttributeForEvent(args *utils.CGREvent, } // V1ProcessEvent proccess the event and returns the result -func (alS *AttributeService) V1ProcessEvent(args *utils.CGREvent, +func (alS *AttributeService) V1ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *AttrSProcessEventReply) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) diff --git a/engine/attributes_test.go b/engine/attributes_test.go index daa3ed0f3..8153b9e63 100644 --- a/engine/attributes_test.go +++ b/engine/attributes_test.go @@ -32,9 +32,10 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestAttributesShutdown(t *testing.T) { @@ -71,7 +72,7 @@ func TestAttributesV1GetAttributeForEventNilCGREvent(t *testing.T) { reply := &AttributeProfile{} experr := fmt.Sprintf("MANDATORY_IE_MISSING: [%s]", "CGREvent") - err := alS.V1GetAttributeForEvent(nil, reply) + err := alS.V1GetAttributeForEvent(context.Background(), nil, reply) if err == nil || err.Error() != experr { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) @@ -91,7 +92,7 @@ func TestAttributesV1GetAttributeForEventProfileNotFound(t *testing.T) { reply := &AttributeProfile{} experr := utils.ErrNotFound - err := alS.V1GetAttributeForEvent(args, reply) + err := alS.V1GetAttributeForEvent(context.Background(), args, reply) if err == nil || err != experr { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) @@ -111,7 +112,7 @@ func TestAttributesV1GetAttributeForEvent2(t *testing.T) { reply := &AttributeProfile{} experr := utils.ErrNotFound - err := alS.V1GetAttributeForEvent(args, reply) + err := alS.V1GetAttributeForEvent(context.Background(), args, reply) if err == nil || err != experr { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) @@ -121,7 +122,7 @@ func TestAttributesV1GetAttributeForEvent2(t *testing.T) { func TestAttributesV1ProcessEvent(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.FilterSCfg().ResourceSConns = []string{} - conMng := NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector)) + conMng := NewConnManager(cfg, make(map[string]chan birpc.ClientConnector)) dm := NewDataManager(NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items), nil, conMng) filterS := NewFilterS(cfg, conMng, dm) if err := dm.SetAttributeProfile(&AttributeProfile{ @@ -187,15 +188,16 @@ func TestAttributesV1ProcessEvent(t *testing.T) { }, blocker: false, } - if err = alS.V1ProcessEvent(&utils.CGREvent{ - Tenant: "cgrates.org", - Event: map[string]any{ - utils.AccountField: "adrian@itsyscom.com", - }, - APIOpts: map[string]any{ - utils.OptsAttributesProcessRuns: 2, - }, - }, &rply); err != nil { + if err = alS.V1ProcessEvent(context.Background(), + &utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]any{ + utils.AccountField: "adrian@itsyscom.com", + }, + APIOpts: map[string]any{ + utils.OptsAttributesProcessRuns: 2, + }, + }, &rply); err != nil { t.Errorf("Expected <%+v>, received <%+v>", nil, err) } else if sort.Strings(rply.AlteredFields); !reflect.DeepEqual(expected, rply) { t.Errorf("Expected <%+v>, received <%+v>", utils.ToJSON(expected), utils.ToJSON(rply)) @@ -206,7 +208,7 @@ func TestAttributesV1ProcessEventErrorMetaSum(t *testing.T) { Cache.Clear(nil) cfg := config.NewDefaultCGRConfig() cfg.FilterSCfg().ResourceSConns = []string{} - conMng := NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector)) + conMng := NewConnManager(cfg, make(map[string]chan birpc.ClientConnector)) dm := NewDataManager(NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items), nil, conMng) filterS := NewFilterS(cfg, conMng, dm) @@ -230,15 +232,16 @@ func TestAttributesV1ProcessEventErrorMetaSum(t *testing.T) { alS := NewAttributeService(dm, filterS, cfg) var rply AttrSProcessEventReply expErr := "SERVER_ERROR: NotEnoughParameters" - if err = alS.V1ProcessEvent(&utils.CGREvent{ - Tenant: "cgrates.org", - Event: map[string]any{ - utils.AccountField: "adrian@itsyscom.com", - }, - APIOpts: map[string]any{ - utils.OptsAttributesProcessRuns: 2, - }, - }, &rply); err == nil || err.Error() != expErr { + if err = alS.V1ProcessEvent(context.Background(), + &utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]any{ + utils.AccountField: "adrian@itsyscom.com", + }, + APIOpts: map[string]any{ + utils.OptsAttributesProcessRuns: 2, + }, + }, &rply); err == nil || err.Error() != expErr { t.Errorf("Expected <%+v>, received <%+v>", expErr, err) } @@ -248,7 +251,7 @@ func TestAttributesV1ProcessEventErrorMetaDifference(t *testing.T) { Cache.Clear(nil) cfg := config.NewDefaultCGRConfig() cfg.FilterSCfg().ResourceSConns = []string{} - conMng := NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector)) + conMng := NewConnManager(cfg, make(map[string]chan birpc.ClientConnector)) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, nil, conMng) filterS := NewFilterS(cfg, conMng, dm) @@ -273,15 +276,16 @@ func TestAttributesV1ProcessEventErrorMetaDifference(t *testing.T) { alS := NewAttributeService(dm, filterS, cfg) var rply AttrSProcessEventReply expErr := "SERVER_ERROR: NotEnoughParameters" - if err := alS.V1ProcessEvent(&utils.CGREvent{ - Tenant: "cgrates.org", - Event: map[string]any{ - utils.AccountField: "adrian@itsyscom.com", - }, - APIOpts: map[string]any{ - utils.OptsAttributesProcessRuns: 2, - }, - }, &rply); err == nil || err.Error() != expErr { + if err := alS.V1ProcessEvent(context.Background(), + &utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]any{ + utils.AccountField: "adrian@itsyscom.com", + }, + APIOpts: map[string]any{ + utils.OptsAttributesProcessRuns: 2, + }, + }, &rply); err == nil || err.Error() != expErr { t.Errorf("Expected <%+v>, received <%+v>", expErr, err) } @@ -315,15 +319,16 @@ func TestAttributesV1ProcessEventErrorMetaValueExponent(t *testing.T) { alS := NewAttributeService(dm, filterS, cfg) var rply AttrSProcessEventReply expErr := "SERVER_ERROR: invalid arguments <[{\"Rules\":\"CGRATES.ORG\"}]> to *value_exponent" - if err := alS.V1ProcessEvent(&utils.CGREvent{ - Tenant: "cgrates.org", - Event: map[string]any{ - utils.AccountField: "adrian@itsyscom.com", - }, - APIOpts: map[string]any{ - utils.OptsAttributesProcessRuns: 2, - }, - }, &rply); err == nil || err.Error() != expErr { + if err := alS.V1ProcessEvent(context.Background(), + &utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]any{ + utils.AccountField: "adrian@itsyscom.com", + }, + APIOpts: map[string]any{ + utils.OptsAttributesProcessRuns: 2, + }, + }, &rply); err == nil || err.Error() != expErr { t.Errorf("Expected <%+v>, received <%+v>", expErr, err) } @@ -1222,7 +1227,7 @@ func TestAttributesV1ProcessEventMultipleRuns1(t *testing.T) { }, } - if err := alS.V1ProcessEvent(args, reply); err != nil { + if err := alS.V1ProcessEvent(context.Background(), args, reply); err != nil { t.Error(err) } else { sort.Strings(reply.AlteredFields) @@ -1231,7 +1236,7 @@ func TestAttributesV1ProcessEventMultipleRuns1(t *testing.T) { } } - if err := alS.V1ProcessEvent(nil, reply); err == nil { + if err := alS.V1ProcessEvent(context.Background(), nil, reply); err == nil { t.Error("expected error") } } @@ -1333,7 +1338,7 @@ func TestAttributesV1ProcessEventMultipleRuns2(t *testing.T) { }, }, } - if err := alS.V1ProcessEvent(args, reply); err != nil { + if err := alS.V1ProcessEvent(context.Background(), args, reply); err != nil { t.Error(err) } else { sort.Strings(reply.AlteredFields) @@ -1440,7 +1445,7 @@ func TestAttrSV1GetAttributeForEvent(t *testing.T) { Weight: 10, }, true) var attrPrf AttributeProfile - if err := attS.V1GetAttributeForEvent(args, &attrPrf); err != nil { + if err := attS.V1GetAttributeForEvent(context.Background(), args, &attrPrf); err != nil { t.Error(err) } @@ -1544,31 +1549,33 @@ func TestAttributesV1ProcessEventSentryPeer(t *testing.T) { blocker: false, } config.SetCgrConfig(cfg) - if err = alS.V1ProcessEvent(&utils.CGREvent{ - Tenant: "cgrates.org", - Event: map[string]any{ - utils.AccountField: "account_1001", - utils.Destination: "453904509045", - }, - APIOpts: map[string]any{ - utils.OptsAttributesProcessRuns: 2, - }, - }, &rply); err != nil { + if err = alS.V1ProcessEvent(context.Background(), + &utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]any{ + utils.AccountField: "account_1001", + utils.Destination: "453904509045", + }, + APIOpts: map[string]any{ + utils.OptsAttributesProcessRuns: 2, + }, + }, &rply); err != nil { t.Errorf("Expected <%+v>, received <%+v>", nil, err) } else if sort.Strings(rply.AlteredFields); !reflect.DeepEqual(expected, rply) { t.Errorf("Expected <%+v>, received <%+v>", utils.ToJSON(expected), utils.ToJSON(rply)) } - if err = alS.V1ProcessEvent(&utils.CGREvent{ - Tenant: "cgrates.org", - Event: map[string]any{ - utils.AccountField: "account_1001", - utils.Destination: "100", - }, - APIOpts: map[string]any{ - utils.OptsAttributesProcessRuns: 2, - }, - }, &rply); err == nil { + if err = alS.V1ProcessEvent(context.Background(), + &utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]any{ + utils.AccountField: "account_1001", + utils.Destination: "100", + }, + APIOpts: map[string]any{ + utils.OptsAttributesProcessRuns: 2, + }, + }, &rply); err == nil { t.Errorf("Expected <%+v>, received <%+v>", err, nil) } diff --git a/engine/caches.go b/engine/caches.go index d54e2758a..854ead17d 100644 --- a/engine/caches.go +++ b/engine/caches.go @@ -27,6 +27,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" @@ -112,7 +113,7 @@ func NewCacheS(cfg *config.CGRConfig, dm *DataManager, cpS *CapsStats) (c *Cache continue } val.OnEvicted = func(itmID string, value any) { - if err := connMgr.Call(cfg.CacheCfg().ReplicationConns, nil, utils.CacheSv1ReplicateRemove, + if err := connMgr.Call(context.TODO(), cfg.CacheCfg().ReplicationConns, utils.CacheSv1ReplicateRemove, &utils.ArgCacheReplicateRemove{ CacheID: k, ItemID: itmID, @@ -161,7 +162,8 @@ func (chS *CacheS) ReplicateSet(chID, itmID string, value any) (err error) { return } var reply string - return connMgr.Call(chS.cfg.CacheCfg().ReplicationConns, nil, utils.CacheSv1ReplicateSet, + return connMgr.Call(context.TODO(), chS.cfg.CacheCfg().ReplicationConns, + utils.CacheSv1ReplicateSet, &utils.ArgCacheReplicateSet{ CacheID: chID, ItemID: itmID, @@ -185,7 +187,7 @@ func (chS *CacheS) SetWithReplicate(args *utils.ArgCacheReplicateSet) (err error return } var reply string - return connMgr.Call(chS.cfg.CacheCfg().ReplicationConns, nil, + return connMgr.Call(context.TODO(), chS.cfg.CacheCfg().ReplicationConns, utils.CacheSv1ReplicateSet, args, &reply) } @@ -210,7 +212,7 @@ func (chS *CacheS) GetWithRemote(args *utils.ArgsGetCacheItemWithAPIOpts) (itm a return nil, utils.ErrNotFound } // item was not found locally, query from remote - if err = connMgr.Call(chS.cfg.CacheCfg().RemoteConns, nil, + if err = connMgr.Call(context.TODO(), chS.cfg.CacheCfg().RemoteConns, utils.CacheSv1GetItem, args, &itm); err != nil && err.Error() == utils.ErrNotFound.Error() { return nil, utils.ErrNotFound // correct the error coming as string type @@ -306,11 +308,11 @@ func (chS *CacheS) Precache() (err error) { // APIs start here // Call gives the ability of CacheS to be passed as internal RPC -func (chS *CacheS) Call(serviceMethod string, args any, reply any) error { +func (chS *CacheS) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.RPCCall(chS, serviceMethod, args, reply) } -func (chS *CacheS) V1GetItemIDs(args *utils.ArgsGetCacheItemIDsWithAPIOpts, +func (chS *CacheS) V1GetItemIDs(ctx *context.Context, args *utils.ArgsGetCacheItemIDsWithAPIOpts, reply *[]string) (err error) { itmIDs := chS.tCache.GetItemIDs(args.CacheID, args.ItemIDPrefix) if len(itmIDs) == 0 { @@ -320,14 +322,14 @@ func (chS *CacheS) V1GetItemIDs(args *utils.ArgsGetCacheItemIDsWithAPIOpts, return } -func (chS *CacheS) V1HasItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (chS *CacheS) V1HasItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *bool) (err error) { *reply = chS.tCache.HasItem(args.CacheID, args.ItemID) return } // V1GetItem returns a single item from the cache -func (chS *CacheS) V1GetItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (chS *CacheS) V1GetItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *any) (err error) { itmIface, has := chS.tCache.Get(args.CacheID, args.ItemID) if !has { @@ -338,7 +340,7 @@ func (chS *CacheS) V1GetItem(args *utils.ArgsGetCacheItemWithAPIOpts, } // V1GetItemWithRemote queries the item from remote if not found locally -func (chS *CacheS) V1GetItemWithRemote(args *utils.ArgsGetCacheItemWithAPIOpts, +func (chS *CacheS) V1GetItemWithRemote(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *any) (err error) { var itmIface any if itmIface, err = chS.GetWithRemote(args); err != nil { @@ -348,7 +350,7 @@ func (chS *CacheS) V1GetItemWithRemote(args *utils.ArgsGetCacheItemWithAPIOpts, return } -func (chS *CacheS) V1GetItemExpiryTime(args *utils.ArgsGetCacheItemWithAPIOpts, +func (chS *CacheS) V1GetItemExpiryTime(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *time.Time) (err error) { expTime, has := chS.tCache.GetItemExpiryTime(args.CacheID, args.ItemID) if !has { @@ -358,14 +360,14 @@ func (chS *CacheS) V1GetItemExpiryTime(args *utils.ArgsGetCacheItemWithAPIOpts, return } -func (chS *CacheS) V1RemoveItem(args *utils.ArgsGetCacheItemWithAPIOpts, +func (chS *CacheS) V1RemoveItem(ctx *context.Context, args *utils.ArgsGetCacheItemWithAPIOpts, reply *string) (err error) { chS.tCache.Remove(args.CacheID, args.ItemID, true, utils.NonTransactional) *reply = utils.OK return } -func (chS *CacheS) V1RemoveItems(args *utils.AttrReloadCacheWithAPIOpts, +func (chS *CacheS) V1RemoveItems(ctx *context.Context, args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { for cacheID, ids := range args.Map() { for _, id := range ids { @@ -376,21 +378,21 @@ func (chS *CacheS) V1RemoveItems(args *utils.AttrReloadCacheWithAPIOpts, return } -func (chS *CacheS) V1Clear(args *utils.AttrCacheIDsWithAPIOpts, +func (chS *CacheS) V1Clear(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, reply *string) (err error) { chS.tCache.Clear(args.CacheIDs) *reply = utils.OK return } -func (chS *CacheS) V1GetCacheStats(args *utils.AttrCacheIDsWithAPIOpts, +func (chS *CacheS) V1GetCacheStats(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, rply *map[string]*ltcache.CacheStats) (err error) { cs := chS.tCache.GetCacheStats(args.CacheIDs) *rply = cs return } -func (chS *CacheS) V1PrecacheStatus(args *utils.AttrCacheIDsWithAPIOpts, rply *map[string]string) (err error) { +func (chS *CacheS) V1PrecacheStatus(ctx *context.Context, args *utils.AttrCacheIDsWithAPIOpts, rply *map[string]string) (err error) { if len(args.CacheIDs) == 0 { args.CacheIDs = utils.CachePartitions.AsSlice() } @@ -410,13 +412,13 @@ func (chS *CacheS) V1PrecacheStatus(args *utils.AttrCacheIDsWithAPIOpts, rply *m return } -func (chS *CacheS) V1HasGroup(args *utils.ArgsGetGroupWithAPIOpts, +func (chS *CacheS) V1HasGroup(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, rply *bool) (err error) { *rply = chS.tCache.HasGroup(args.CacheID, args.GroupID) return } -func (chS *CacheS) V1GetGroupItemIDs(args *utils.ArgsGetGroupWithAPIOpts, +func (chS *CacheS) V1GetGroupItemIDs(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, rply *[]string) (err error) { if has := chS.tCache.HasGroup(args.CacheID, args.GroupID); !has { return utils.ErrNotFound @@ -425,18 +427,18 @@ func (chS *CacheS) V1GetGroupItemIDs(args *utils.ArgsGetGroupWithAPIOpts, return } -func (chS *CacheS) V1RemoveGroup(args *utils.ArgsGetGroupWithAPIOpts, +func (chS *CacheS) V1RemoveGroup(ctx *context.Context, args *utils.ArgsGetGroupWithAPIOpts, rply *string) (err error) { chS.tCache.RemoveGroup(args.CacheID, args.GroupID, true, utils.NonTransactional) *rply = utils.OK return } -func (chS *CacheS) V1ReloadCache(attrs *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { +func (chS *CacheS) V1ReloadCache(ctx *context.Context, attrs *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { return chS.cacheDataFromDB(attrs, reply, true) } -func (chS *CacheS) V1LoadCache(attrs *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { +func (chS *CacheS) V1LoadCache(ctx *context.Context, attrs *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) { return chS.cacheDataFromDB(attrs, reply, false) } @@ -479,7 +481,7 @@ func populateCacheLoadIDs(loadIDs map[string]int64, attrs map[string][]string) ( } // V1ReplicateSet receives an item via replication to store in the cache -func (chS *CacheS) V1ReplicateSet(args *utils.ArgCacheReplicateSet, reply *string) (err error) { +func (chS *CacheS) V1ReplicateSet(ctx *context.Context, args *utils.ArgCacheReplicateSet, reply *string) (err error) { if cmp, canCast := args.Value.(utils.Compiler); canCast { if err = cmp.Compile(); err != nil { return @@ -497,7 +499,7 @@ func (chS *CacheS) ReplicateRemove(chID, itmID string) (err error) { return } var reply string - return connMgr.Call(chS.cfg.CacheCfg().ReplicationConns, nil, utils.CacheSv1ReplicateRemove, + return connMgr.Call(context.TODO(), chS.cfg.CacheCfg().ReplicationConns, utils.CacheSv1ReplicateRemove, &utils.ArgCacheReplicateRemove{ CacheID: chID, ItemID: itmID, @@ -505,7 +507,7 @@ func (chS *CacheS) ReplicateRemove(chID, itmID string) (err error) { } // V1ReplicateRemove replicate an item -func (chS *CacheS) V1ReplicateRemove(args *utils.ArgCacheReplicateRemove, reply *string) (err error) { +func (chS *CacheS) V1ReplicateRemove(ctx *context.Context, args *utils.ArgCacheReplicateRemove, reply *string) (err error) { chS.tCache.Remove(args.CacheID, args.ItemID, true, utils.EmptyString) *reply = utils.OK return diff --git a/engine/caches_test.go b/engine/caches_test.go index 6a95f22ac..9a69aff17 100644 --- a/engine/caches_test.go +++ b/engine/caches_test.go @@ -24,10 +24,11 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" - "github.com/cgrates/rpcclient" ) func TestCachesReplicateRemove(t *testing.T) { @@ -40,16 +41,16 @@ func TestCachesReplicateRemove(t *testing.T) { } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReplicateRemove: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReplicateRemove: func(ctx *context.Context, args, reply any) error { *reply.(*string) = utils.OK return nil }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicationConnsCfg): clientconn, }) chS := CacheS{ @@ -79,17 +80,17 @@ func TestCacheSSetWithReplicate(t *testing.T) { } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReplicateSet: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { *reply.(*string) = "reply" return nil }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicationConnsCfg): clientconn, }) ltcache := ltcache.NewTransCache(map[string]*ltcache.CacheConfig{ @@ -141,13 +142,13 @@ func TestCacheSV1GetItemIDs(t *testing.T) { } reply := &[]string{} exp := &[]string{"itemID"} - if err := chS.V1GetItemIDs(args, reply); err != nil { + if err := chS.V1GetItemIDs(context.Background(), args, reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, exp) { t.Errorf("expected %+v,received %+v", utils.ToJSON(exp), utils.ToJSON(reply)) } tscache.Remove("cacheID", "itemID", true, utils.NonTransactional) - if err := chS.V1GetItemIDs(args, reply); err == nil || err != utils.ErrNotFound { + if err := chS.V1GetItemIDs(context.Background(), args, reply); err == nil || err != utils.ErrNotFound { t.Error(err) } } @@ -183,7 +184,7 @@ func TestCacheSV1HasItem(t *testing.T) { tCache: tscache, } reply := utils.BoolPointer(false) - if err := chS.V1HasItem(args, reply); err != nil { + if err := chS.V1HasItem(context.Background(), args, reply); err != nil { t.Error(err) } } @@ -203,16 +204,16 @@ func TestCacheSV1GetItemWithRemote(t *testing.T) { Remote: true, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1GetItem: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1GetItem: func(ctx *context.Context, args, reply any) error { return nil }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.RemoteConnsCfg): clientconn, }, ) @@ -234,7 +235,7 @@ func TestCacheSV1GetItemWithRemote(t *testing.T) { } SetConnManager(connMgr) var reply any = "str" - if err := chS.V1GetItemWithRemote(args, &reply); err != nil { + if err := chS.V1GetItemWithRemote(context.Background(), args, &reply); err != nil { t.Error(err) } } @@ -268,7 +269,7 @@ func TestCacheSV1GetItem(t *testing.T) { tCache: tscache, } var reply any - if err := chS.V1GetItem(args, &reply); err != nil { + if err := chS.V1GetItem(context.Background(), args, &reply); err != nil { t.Error(err) } else if val, cancast := reply.(string); cancast { if val != "value" { @@ -276,7 +277,7 @@ func TestCacheSV1GetItem(t *testing.T) { } } tscache.Remove("cacheID", "itemID", true, utils.NonTransactional) - if err := chS.V1GetItem(args, &reply); err == nil || err != utils.ErrNotFound { + if err := chS.V1GetItem(context.Background(), args, &reply); err == nil || err != utils.ErrNotFound { t.Error(err) } } @@ -319,7 +320,7 @@ func TestCacheSV1GetItemExpiryTime(t *testing.T) { reply := now loc, _ := time.LoadLocation("EST") exp := now.Add(30 * time.Minute).In(loc).Minute() - if err := chS.V1GetItemExpiryTime(args, &reply); err != nil { + if err := chS.V1GetItemExpiryTime(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply.Minute() != exp { t.Errorf("expected %+v,received %+v", exp, reply) @@ -356,7 +357,7 @@ func TestCacheSV1RemoveItem(t *testing.T) { tCache: tscache, } var reply string - if err := chS.V1RemoveItem(args, &reply); err != nil { + if err := chS.V1RemoveItem(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("expected %v,received %v", utils.OK, reply) @@ -418,7 +419,7 @@ func TestCacheSV1RemoveItems(t *testing.T) { reply := "error" - if err := chS.V1RemoveItems(args, &reply); err != nil { + if err := chS.V1RemoveItems(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("expected %v,received %v", utils.OK, reply) @@ -467,7 +468,7 @@ func TestCacheSV1Clear(t *testing.T) { tCache: tscache, } reply := "error" - if err := chS.V1Clear(args, &reply); err != nil { + if err := chS.V1Clear(context.Background(), args, &reply); err != nil { t.Error(err) } } @@ -501,7 +502,7 @@ func TestCacheSV1ReplicateSet(t *testing.T) { tCache: tscache, } reply := "reply" - if err := chS.V1ReplicateSet(args, &reply); err != nil { + if err := chS.V1ReplicateSet(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("expected %+v,received %+v", utils.OK, reply) @@ -567,7 +568,7 @@ func TestCacheSV1GetCacheStats(t *testing.T) { "cacheID2": {Items: 1, Groups: 0}, "cacheID3": {Items: 1, Groups: 0}, } - if err := chS.V1GetCacheStats(args, &reply); err != nil { + if err := chS.V1GetCacheStats(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, exp) { t.Errorf("expected %v,received %v", utils.ToJSON(reply), utils.ToJSON(exp)) @@ -623,13 +624,13 @@ func TestV1PrecacheStatus(t *testing.T) { exp := map[string]string{ utils.CacheFilters: utils.MetaPrecaching, } - if err := chS.V1PrecacheStatus(args, &reply); err != nil { + if err := chS.V1PrecacheStatus(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(exp, reply) { t.Errorf("expected %+v,received %+v", exp, reply) } args.CacheIDs = []string{} - if err := chS.V1PrecacheStatus(args, &reply); err == nil { + if err := chS.V1PrecacheStatus(context.Background(), args, &reply); err == nil { t.Error(err) } } @@ -663,7 +664,7 @@ func TestCacheSV1HasGroup(t *testing.T) { } var reply bool - if err := chS.V1HasGroup(args, &reply); err != nil { + if err := chS.V1HasGroup(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reply { t.Error("expected true,received false") @@ -700,7 +701,7 @@ func TestCacheSV1HasGroupItemIDs(t *testing.T) { } var reply []string exp := []string{"itemId"} - if err := chS.V1GetGroupItemIDs(args, &reply); err != nil { + if err := chS.V1GetGroupItemIDs(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(exp, reply) { t.Errorf("expected %+v,received %+v", exp, reply) @@ -737,7 +738,7 @@ func TestV1RemoveGroup(t *testing.T) { } var reply string - if err := chS.V1RemoveGroup(args, &reply); err != nil { + if err := chS.V1RemoveGroup(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("expected %v,received %v", utils.OK, reply) @@ -777,7 +778,7 @@ func TestCacheSV1ReplicateRemove(t *testing.T) { } var reply string - if err := chS.V1ReplicateRemove(args, &reply); err != nil { + if err := chS.V1ReplicateRemove(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("expected %v,received %v", utils.OK, reply) @@ -801,17 +802,17 @@ func TestNewCacheS(t *testing.T) { } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReplicateRemove: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReplicateRemove: func(ctx *context.Context, args, reply any) error { *reply.(*string) = "reply" return nil }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicationConnsCfg): clientconn, }) expCacheS := &CacheS{} @@ -913,16 +914,16 @@ func TestReplicateMultipleIDs(t *testing.T) { } Cache = NewCacheS(cfg, nil, nil) - connClient := make(chan rpcclient.ClientConnector, 1) + connClient := make(chan birpc.ClientConnector, 1) connClient <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReloadCache: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReloadCache: func(ctx *context.Context, args, reply any) error { *reply.(*string) = "reply" return nil }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): connClient, }) objType := "obj" @@ -956,17 +957,17 @@ func TestCachesGetWithRemote(t *testing.T) { db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) chS := NewCacheS(cfg, dm, nil) - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1GetItem: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1GetItem: func(ctx *context.Context, args, reply any) error { *reply.(*string) = utils.OK return utils.ErrNotFound }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.RemoteConnsCfg): clientconn, }) SetConnManager(connMgr) @@ -1015,7 +1016,7 @@ func TestV1LoadCache(t *testing.T) { } chS := NewCacheS(cfg, dm, nil) var reply string - if err := chS.V1LoadCache(attr, &reply); err != nil { + if err := chS.V1LoadCache(context.Background(), attr, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("reply should be %v", utils.OK) diff --git a/engine/cdrs.go b/engine/cdrs.go index 11a70476a..d84c876c6 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -25,6 +25,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" @@ -61,7 +62,7 @@ func (cdrS *CDRServer) cgrCdrHandler(w http.ResponseWriter, r *http.Request) { return } var ignored string - if err := cdrS.V1ProcessCDR(&CDRWithAPIOpts{CDR: cdr}, &ignored); err != nil { + if err := cdrS.V1ProcessCDR(context.TODO(), &CDRWithAPIOpts{CDR: cdr}, &ignored); err != nil { utils.Logger.Warning( fmt.Sprintf("<%s> processing CDR: %s, err: <%s>", utils.CDRs, cdr, err.Error())) @@ -82,7 +83,7 @@ func (cdrS *CDRServer) fsCdrHandler(w http.ResponseWriter, r *http.Request) { return } var ignored string - if err := cdrS.V1ProcessCDR(&CDRWithAPIOpts{CDR: cdr}, &ignored); err != nil { + if err := cdrS.V1ProcessCDR(context.TODO(), &CDRWithAPIOpts{CDR: cdr}, &ignored); err != nil { utils.Logger.Warning( fmt.Sprintf("<%s> processing CDR: %s, err: <%s>", utils.CDRs, cdr, err.Error())) @@ -276,7 +277,7 @@ func (cdrS *CDRServer) getCostFromRater(cdr *CDRWithAPIOpts) (*CallCost, error) PerformRounding: true, } if reqTypes.Has(cdr.RequestType) { // Prepaid - Cost can be recalculated in case of missing records from SM - err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().RaterConns, nil, + err = cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().RaterConns, utils.ResponderDebit, &CallDescriptorWithAPIOpts{ CallDescriptor: cd, @@ -286,7 +287,7 @@ func (cdrS *CDRServer) getCostFromRater(cdr *CDRWithAPIOpts) (*CallCost, error) cdr.RequestType == utils.MetaDynaprepaid { var reply string // execute the actionPlan configured in Scheduler - if err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().SchedulerConns, nil, + if err = cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().SchedulerConns, utils.SchedulerSv1ExecuteActionPlans, &utils.AttrsExecuteActionPlans{ ActionPlanIDs: cdrS.cgrCfg.SchedulerCfg().DynaprepaidActionPlans, AccountID: cdr.Account, Tenant: cdr.Tenant}, @@ -294,7 +295,7 @@ func (cdrS *CDRServer) getCostFromRater(cdr *CDRWithAPIOpts) (*CallCost, error) return cc, err } // execute again the Debit operation - err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().RaterConns, nil, + err = cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().RaterConns, utils.ResponderDebit, &CallDescriptorWithAPIOpts{ CallDescriptor: cd, @@ -302,7 +303,7 @@ func (cdrS *CDRServer) getCostFromRater(cdr *CDRWithAPIOpts) (*CallCost, error) }, cc) } } else { - err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().RaterConns, nil, + err = cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().RaterConns, utils.ResponderGetCost, &CallDescriptorWithAPIOpts{ CallDescriptor: cd, @@ -341,7 +342,7 @@ func (cdrS *CDRServer) refundEventCost(ec *EventCost, reqType, tor string) (rfnd return } var acnt Account - if err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().RaterConns, nil, + if err = cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().RaterConns, utils.ResponderRefundIncrements, &CallDescriptorWithAPIOpts{CallDescriptor: cd}, &acnt); err != nil { return @@ -352,7 +353,7 @@ func (cdrS *CDRServer) refundEventCost(ec *EventCost, reqType, tor string) (rfnd // chrgrSProcessEvent forks CGREventWithOpts into multiples based on matching ChargerS profiles func (cdrS *CDRServer) chrgrSProcessEvent(cgrEv *utils.CGREvent) (cgrEvs []*utils.CGREvent, err error) { var chrgrs []*ChrgSProcessEventReply - if err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().ChargerSConns, nil, + if err = cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().ChargerSConns, utils.ChargerSv1ProcessEvent, cgrEv, &chrgrs); err != nil { return @@ -378,7 +379,7 @@ func (cdrS *CDRServer) attrSProcessEvent(cgrEv *utils.CGREvent) (err error) { cgrEv.APIOpts[utils.OptsContext] = utils.FirstNonEmpty( utils.IfaceAsString(ctx), utils.MetaCDRs) - if err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().AttributeSConns, nil, + if err = cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().AttributeSConns, utils.AttributeSv1ProcessEvent, cgrEv, &rplyEv); err == nil && len(rplyEv.AlteredFields) != 0 { *cgrEv = *rplyEv.CGREvent @@ -401,7 +402,7 @@ func (cdrS *CDRServer) thdSProcessEvent(cgrEv *utils.CGREvent) (err error) { thArgs.APIOpts = make(map[string]any) } thArgs.APIOpts[utils.MetaEventType] = utils.CDR - if err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().ThresholdSConns, nil, + if err = cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().ThresholdSConns, utils.ThresholdSv1ProcessEvent, thArgs, &tIDs); err != nil && err.Error() == utils.ErrNotFound.Error() { @@ -414,7 +415,7 @@ func (cdrS *CDRServer) thdSProcessEvent(cgrEv *utils.CGREvent) (err error) { func (cdrS *CDRServer) statSProcessEvent(cgrEv *utils.CGREvent) (err error) { var reply []string statArgs := cgrEv.Clone() - if err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().StatSConns, nil, + if err = cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().StatSConns, utils.StatSv1ProcessEvent, statArgs, &reply); err != nil && err.Error() == utils.ErrNotFound.Error() { @@ -426,7 +427,7 @@ func (cdrS *CDRServer) statSProcessEvent(cgrEv *utils.CGREvent) (err error) { // eeSProcessEvent will process the event with the EEs component func (cdrS *CDRServer) eeSProcessEvent(cgrEv *CGREventWithEeIDs) (err error) { var reply map[string]map[string]any - if err = cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().EEsConns, nil, + if err = cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().EEsConns, utils.EeSv1ProcessEvent, cgrEv, &reply); err != nil && err.Error() == utils.ErrNotFound.Error() { @@ -647,8 +648,8 @@ func (cdrS *CDRServer) processEvents(evs []*utils.CGREvent, return } -// Call implements the rpcclient.ClientConnector interface -func (cdrS *CDRServer) Call(serviceMethod string, args any, reply any) error { +// Call implements the birpc.ClientConnector interface +func (cdrS *CDRServer) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { parts := strings.Split(serviceMethod, ".") if len(parts) != 2 { return rpcclient.ErrUnsupporteServiceMethod @@ -675,7 +676,7 @@ func (cdrS *CDRServer) Call(serviceMethod string, args any, reply any) error { } // V1ProcessCDR processes a CDR -func (cdrS *CDRServer) V1ProcessCDR(cdr *CDRWithAPIOpts, reply *string) (err error) { +func (cdrS *CDRServer) V1ProcessCDR(ctx *context.Context, cdr *CDRWithAPIOpts, reply *string) (err error) { if cdr.CGRID == utils.EmptyString { // Populate CGRID if not present cdr.ComputeCGRID() } @@ -768,7 +769,7 @@ func (attr *ArgV1ProcessEvent) Clone() *ArgV1ProcessEvent { } // V1ProcessEvent will process the CGREvent -func (cdrS *CDRServer) V1ProcessEvent(arg *ArgV1ProcessEvent, reply *string) (err error) { +func (cdrS *CDRServer) V1ProcessEvent(ctx *context.Context, arg *ArgV1ProcessEvent, reply *string) (err error) { if arg.CGREvent.ID == utils.EmptyString { arg.CGREvent.ID = utils.GenUUID() } @@ -881,7 +882,7 @@ func (cdrS *CDRServer) V1ProcessEvent(arg *ArgV1ProcessEvent, reply *string) (er } // V2ProcessEvent has the same logic with V1ProcessEvent except it adds the proccessed events to the reply -func (cdrS *CDRServer) V2ProcessEvent(arg *ArgV1ProcessEvent, evs *[]*utils.EventWithFlags) (err error) { +func (cdrS *CDRServer) V2ProcessEvent(ctx *context.Context, arg *ArgV1ProcessEvent, evs *[]*utils.EventWithFlags) (err error) { if arg.ID == "" { arg.ID = utils.GenUUID() } @@ -958,7 +959,7 @@ func (cdrS *CDRServer) V2ProcessEvent(arg *ArgV1ProcessEvent, evs *[]*utils.Even } // V1StoreSessionCost handles storing of the cost into session_costs table -func (cdrS *CDRServer) V1StoreSessionCost(attr *AttrCDRSStoreSMCost, reply *string) (err error) { +func (cdrS *CDRServer) V1StoreSessionCost(ctx *context.Context, attr *AttrCDRSStoreSMCost, reply *string) (err error) { if attr.Cost.CGRID == "" { return utils.NewCGRError(utils.CDRsCtx, utils.MandatoryIEMissingCaps, fmt.Sprintf("%s: CGRID", utils.MandatoryInfoMissing), @@ -991,7 +992,7 @@ func (cdrS *CDRServer) V1StoreSessionCost(attr *AttrCDRSStoreSMCost, reply *stri } // V2StoreSessionCost will store the SessionCost into session_costs table -func (cdrS *CDRServer) V2StoreSessionCost(args *ArgsV2CDRSStoreSMCost, reply *string) (err error) { +func (cdrS *CDRServer) V2StoreSessionCost(ctx *context.Context, args *ArgsV2CDRSStoreSMCost, reply *string) (err error) { if args.Cost.CGRID == "" { return utils.NewCGRError(utils.CDRsCtx, utils.MandatoryIEMissingCaps, fmt.Sprintf("%s: CGRID", utils.MandatoryInfoMissing), @@ -1029,7 +1030,7 @@ func (cdrS *CDRServer) V2StoreSessionCost(args *ArgsV2CDRSStoreSMCost, reply *st cd.RunID = args.Cost.RunID cd.Increments = roundIncrements response := new(Account) - if err := cdrS.connMgr.Call(cdrS.cgrCfg.CdrsCfg().RaterConns, nil, + if err := cdrS.connMgr.Call(context.TODO(), cdrS.cgrCfg.CdrsCfg().RaterConns, utils.ResponderRefundRounding, &CallDescriptorWithAPIOpts{CallDescriptor: cd}, response); err != nil { @@ -1071,7 +1072,7 @@ type ArgRateCDRs struct { // V1RateCDRs is used for re-/rate CDRs which are already stored within StorDB // FixMe: add RPC caching -func (cdrS *CDRServer) V1RateCDRs(arg *ArgRateCDRs, reply *string) (err error) { +func (cdrS *CDRServer) V1RateCDRs(ctx *context.Context, arg *ArgRateCDRs, reply *string) (err error) { var cdrFltr *utils.CDRsFilter if cdrFltr, err = arg.RPCCDRsFilter.AsCDRsFilter(cdrS.cgrCfg.GeneralCfg().DefaultTimezone); err != nil { return utils.NewErrServerError(err) @@ -1129,20 +1130,21 @@ func (cdrS *CDRServer) V1RateCDRs(arg *ArgRateCDRs, reply *string) (err error) { } // V1ProcessExternalCDR is used to process external CDRs -func (cdrS *CDRServer) V1ProcessExternalCDR(eCDR *ExternalCDRWithAPIOpts, reply *string) error { +func (cdrS *CDRServer) V1ProcessExternalCDR(ctx *context.Context, eCDR *ExternalCDRWithAPIOpts, reply *string) error { cdr, err := NewCDRFromExternalCDR(eCDR.ExternalCDR, cdrS.cgrCfg.GeneralCfg().DefaultTimezone) if err != nil { return err } - return cdrS.V1ProcessCDR(&CDRWithAPIOpts{ - CDR: cdr, - APIOpts: eCDR.APIOpts, - }, reply) + return cdrS.V1ProcessCDR(ctx, + &CDRWithAPIOpts{ + CDR: cdr, + APIOpts: eCDR.APIOpts, + }, reply) } // V1GetCDRs returns CDRs from DB -func (cdrS *CDRServer) V1GetCDRs(args utils.RPCCDRsFilterWithAPIOpts, cdrs *[]*CDR) error { +func (cdrS *CDRServer) V1GetCDRs(ctx *context.Context, args utils.RPCCDRsFilterWithAPIOpts, cdrs *[]*CDR) error { cdrsFltr, err := args.AsCDRsFilter(cdrS.cgrCfg.GeneralCfg().DefaultTimezone) if err != nil { if err.Error() != utils.NotFoundCaps { @@ -1158,8 +1160,8 @@ func (cdrS *CDRServer) V1GetCDRs(args utils.RPCCDRsFilterWithAPIOpts, cdrs *[]*C return nil } -// V1CountCDRs counts CDRs from DB -func (cdrS *CDRServer) V1CountCDRs(args *utils.RPCCDRsFilterWithAPIOpts, cnt *int64) error { +// V1GetCDRsCount counts CDRs from DB +func (cdrS *CDRServer) V1GetCDRsCount(ctx *context.Context, args *utils.RPCCDRsFilterWithAPIOpts, cnt *int64) error { cdrsFltr, err := args.AsCDRsFilter(cdrS.cgrCfg.GeneralCfg().DefaultTimezone) if err != nil { if err.Error() != utils.NotFoundCaps { diff --git a/engine/cdrs_test.go b/engine/cdrs_test.go index e938e10fa..d171380a1 100644 --- a/engine/cdrs_test.go +++ b/engine/cdrs_test.go @@ -28,6 +28,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" @@ -36,7 +38,7 @@ import ( type clMock func(_ string, _ any, _ any) error -func (c clMock) Call(m string, a any, r any) error { +func (c clMock) Call(ctx *context.Context, m string, a any, r any) error { return c(m, a, r) } @@ -73,9 +75,9 @@ func TestCDRSV1ProcessCDRNoTenant(t *testing.T) { } return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanClnt, }) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -106,7 +108,7 @@ func TestCDRSV1ProcessCDRNoTenant(t *testing.T) { }, } var reply string - if err := cdrs.V1ProcessCDR(cdr, &reply); err != nil { + if err := cdrs.V1ProcessCDR(context.Background(), cdr, &reply); err != nil { t.Error(err) } } @@ -129,9 +131,9 @@ func TestCDRSV1ProcessEventNoTenant(t *testing.T) { *rply = []*ChrgSProcessEventReply{} return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanClnt, }) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -160,7 +162,7 @@ func TestCDRSV1ProcessEventNoTenant(t *testing.T) { } var reply string - if err := cdrs.V1ProcessEvent(args, &reply); err != nil { + if err := cdrs.V1ProcessEvent(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("expected %v,received %v", utils.OK, reply) @@ -185,9 +187,9 @@ func TestCDRSV1V1ProcessExternalCDRNoTenant(t *testing.T) { *rply = []*ChrgSProcessEventReply{} return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanClnt, }) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -219,7 +221,7 @@ func TestCDRSV1V1ProcessExternalCDRNoTenant(t *testing.T) { } var reply string - if err := cdrs.V1ProcessExternalCDR(args, &reply); err != nil { + if err := cdrs.V1ProcessExternalCDR(context.Background(), args, &reply); err != nil { t.Error(err) } } @@ -267,7 +269,7 @@ func TestCDRV1CountCDRs(t *testing.T) { } i := int64(3) - if err := cdrS.V1CountCDRs(args, &i); err != nil { + if err := cdrS.V1GetCDRsCount(context.Background(), args, &i); err != nil { t.Error(err) } } @@ -294,7 +296,7 @@ func TestV1CountCDRsErr(t *testing.T) { }, } i := utils.Int64Pointer(23) - if err := cdrS.V1CountCDRs(args, i); err == nil { + if err := cdrS.V1GetCDRsCount(context.Background(), args, i); err == nil { t.Error(err) } } @@ -317,7 +319,7 @@ func TestV1RateCDRs(t *testing.T) { } var reply string - if err := cdrS.V1RateCDRs(arg, &reply); err == nil { + if err := cdrS.V1RateCDRs(context.Background(), arg, &reply); err == nil { t.Error(err) } @@ -325,8 +327,8 @@ func TestV1RateCDRs(t *testing.T) { func TestCDRServerThdsProcessEvent(t *testing.T) { clMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ThresholdSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpl := &[]string{"event"} @@ -335,10 +337,10 @@ func TestCDRServerThdsProcessEvent(t *testing.T) { }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- clMock cfg := config.NewDefaultCGRConfig() - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ThresholdSConnsCfg): clientconn, }) cfg.CdrsCfg().ThresholdSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ThreshSConnsCfg)} @@ -363,8 +365,8 @@ func TestCDRServerThdsProcessEvent(t *testing.T) { } func TestCDRServerStatSProcessEvent(t *testing.T) { ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.StatSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.StatSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpl := &[]string{"status"} @@ -373,10 +375,10 @@ func TestCDRServerStatSProcessEvent(t *testing.T) { }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock cfg := config.NewDefaultCGRConfig() - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg): clientconn, }) cfg.CdrsCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg)} @@ -403,8 +405,8 @@ func TestCDRServerStatSProcessEvent(t *testing.T) { func TestCDRServerEesProcessEvent(t *testing.T) { ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.EeSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.EeSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpls := &map[string]map[string]any{ "eeS": { "process": "event", @@ -416,11 +418,11 @@ func TestCDRServerEesProcessEvent(t *testing.T) { }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock cfg := config.NewDefaultCGRConfig() - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.EEsConnsCfg): clientconn, }) cfg.CdrsCfg().EEsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.EEsConnsCfg)} @@ -450,8 +452,8 @@ func TestCDRServerEesProcessEvent(t *testing.T) { func TestCDRefundEventCost(t *testing.T) { cfg := config.NewDefaultCGRConfig() ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderRefundIncrements: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderRefundIncrements: func(ctx *context.Context, args, reply any) error { return nil }, }, @@ -460,9 +462,9 @@ func TestCDRefundEventCost(t *testing.T) { CGRID: "event", RunID: "runid", } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ResponderRefundIncrements): clientconn, }) cfg.CdrsCfg().RaterConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ResponderRefundIncrements)} @@ -486,9 +488,9 @@ func TestGetCostFromRater(t *testing.T) { dm := NewDataManager(db, cfg.CacheCfg(), nil) ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ + calls: map[string]func(ctx *context.Context, args any, reply any) error{ - utils.ResponderDebit: func(args, reply any) error { + utils.ResponderDebit: func(ctx *context.Context, args, reply any) error { rpl := &CallCost{ Category: "category", Tenant: "cgrates", @@ -498,9 +500,9 @@ func TestGetCostFromRater(t *testing.T) { }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.RateSConnsCfg): clientconn, }) cdrS := &CDRServer{ @@ -534,19 +536,19 @@ func TestRefundEventCost(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.CdrsCfg().RaterConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.RateSConnsCfg)} ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderRefundIncrements: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderRefundIncrements: func(ctx *context.Context, args, reply any) error { rpl := &Account{} *reply.(*Account) = *rpl return nil }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.RateSConnsCfg): clientconn, }) cdrS := &CDRServer{ @@ -591,9 +593,9 @@ func TestCDRSV2ProcessEvent(t *testing.T) { return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanClnt, }) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -625,7 +627,7 @@ func TestCDRSV2ProcessEvent(t *testing.T) { } evs := &[]*utils.EventWithFlags{} - if err := cdrs.V2ProcessEvent(args, evs); err != nil { + if err := cdrs.V2ProcessEvent(context.Background(), args, evs); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -677,7 +679,7 @@ func TestCDRSV2ProcessEventCacheSet(t *testing.T) { &utils.CachedRPCResponse{Result: evs, Error: nil}, nil, true, utils.NonTransactional) - if err := cdrs.V2ProcessEvent(args, evs); err != nil { + if err := cdrs.V2ProcessEvent(context.Background(), args, evs); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{Result: evs, Error: nil} @@ -700,9 +702,9 @@ func TestCDRSV1ProcessEvent(t *testing.T) { return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanClnt, }) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -734,7 +736,7 @@ func TestCDRSV1ProcessEvent(t *testing.T) { } reply := utils.StringPointer("result") - if err := cdrs.V1ProcessEvent(args, reply); err != nil { + if err := cdrs.V1ProcessEvent(context.Background(), args, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -786,7 +788,7 @@ func TestCDRSV1ProcessEventCacheSet(t *testing.T) { &utils.CachedRPCResponse{Result: reply, Error: nil}, nil, true, utils.NonTransactional) - if err := cdrs.V1ProcessEvent(args, reply); err != nil { + if err := cdrs.V1ProcessEvent(context.Background(), args, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{Result: reply, Error: nil} @@ -814,10 +816,10 @@ func TestV1ProcessEvent(t *testing.T) { cfg.CdrsCfg().StoreCdrs = true db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.AttributeSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.AttributeSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpl := &AttrSProcessEventReply{ AlteredFields: []string{"*req.OfficeGroup"}, CGREvent: &utils.CGREvent{ @@ -830,7 +832,7 @@ func TestV1ProcessEvent(t *testing.T) { return nil }, - utils.ChargerSv1ProcessEvent: func(args, reply any) error { + utils.ChargerSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpl := []*ChrgSProcessEventReply{ { ChargerSProfile: "chrgs1", @@ -845,7 +847,7 @@ func TestV1ProcessEvent(t *testing.T) { *reply.(*[]*ChrgSProcessEventReply) = rpl return nil }, - utils.ResponderRefundIncrements: func(args, reply any) error { + utils.ResponderRefundIncrements: func(ctx *context.Context, args, reply any) error { rpl := &Account{ ID: "cgrates.org:1001", BalanceMap: map[string]Balances{ @@ -855,34 +857,34 @@ func TestV1ProcessEvent(t *testing.T) { *reply.(*Account) = *rpl return nil }, - utils.ResponderDebit: func(args, reply any) error { + utils.ResponderDebit: func(ctx *context.Context, args, reply any) error { rpl := &CallCost{} *reply.(*CallCost) = *rpl return nil }, - utils.ResponderGetCost: func(args, reply any) error { + utils.ResponderGetCost: func(ctx *context.Context, args, reply any) error { rpl := &CallCost{} *reply.(*CallCost) = *rpl return nil }, - utils.EeSv1ProcessEvent: func(args, reply any) error { + utils.EeSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpl := &map[string]map[string]any{} *reply.(*map[string]map[string]any) = *rpl return nil }, - utils.ThresholdSv1ProcessEvent: func(args, reply any) error { + utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpl := &[]string{} *reply.(*[]string) = *rpl return nil }, - utils.StatSv1ProcessEvent: func(args, reply any) error { + utils.StatSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpl := &[]string{} *reply.(*[]string) = *rpl return nil }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.AttributeSConnsCfg): clientconn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): clientconn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResponder): clientconn, @@ -914,7 +916,7 @@ func TestV1ProcessEvent(t *testing.T) { }, } var reply string - if err := cdrS.V1ProcessEvent(arg, &reply); err == nil { + if err := cdrS.V1ProcessEvent(context.Background(), arg, &reply); err == nil { t.Error(err) } } @@ -946,16 +948,16 @@ func TestCdrprocessEventsErrLog(t *testing.T) { cfg.CdrsCfg().EEsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaEEs)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.EeSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.EeSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { return utils.ErrPartiallyExecuted }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaEEs): clientConn, }) cdrs := &CDRServer{ @@ -1088,7 +1090,7 @@ func TestV1ProcessCDR(t *testing.T) { } reply := utils.StringPointer("reply") - if err = cdrS.V1ProcessCDR(cdr, reply); err != nil { + if err = cdrS.V1ProcessCDR(context.Background(), cdr, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -1133,7 +1135,7 @@ func TestV1ProcessCDRSet(t *testing.T) { Cache.Set(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.CDRsV1ProcessCDR, cdr.CGRID, cdr.RunID), &utils.CachedRPCResponse{Result: reply, Error: err}, nil, true, utils.NonTransactional) - if err = cdrS.V1ProcessCDR(cdr, reply); err != nil { + if err = cdrS.V1ProcessCDR(context.Background(), cdr, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -1154,9 +1156,9 @@ func TestV1StoreSessionCost(t *testing.T) { clMock := clMock(func(_ string, _, _ any) error { return nil }) - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- clMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{}) + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{}) cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) @@ -1181,7 +1183,7 @@ func TestV1StoreSessionCost(t *testing.T) { connMgr: connMgr, } reply := utils.StringPointer("reply") - if err = cdrS.V1StoreSessionCost(attr, reply); err != nil { + if err = cdrS.V1StoreSessionCost(context.Background(), attr, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -1195,7 +1197,7 @@ func TestV1StoreSessionCost(t *testing.T) { t.Errorf("expected %v,received %v", utils.ToJSON(exp), utils.ToJSON(rcv)) } attr.Cost.CGRID = utils.EmptyString - if err := cdrS.V1StoreSessionCost(attr, reply); err == nil || err.Error() != fmt.Sprintf("%s: CGRID", utils.MandatoryInfoMissing) { + if err := cdrS.V1StoreSessionCost(context.Background(), attr, reply); err == nil || err.Error() != fmt.Sprintf("%s: CGRID", utils.MandatoryInfoMissing) { t.Error(err) } } @@ -1207,9 +1209,9 @@ func TestV1StoreSessionCostSet(t *testing.T) { return nil }) - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- clMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{}) + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{}) cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) @@ -1238,7 +1240,7 @@ func TestV1StoreSessionCostSet(t *testing.T) { &utils.CachedRPCResponse{Result: reply, Error: nil}, nil, true, utils.NonTransactional) - if err = cdrS.V1StoreSessionCost(attr, reply); err != nil { + if err = cdrS.V1StoreSessionCost(context.Background(), attr, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -1255,7 +1257,7 @@ func TestV1StoreSessionCostSet(t *testing.T) { cdrS.guard = guardian.Guardian cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 0 attr.CheckDuplicate = true - if err = cdrS.V1StoreSessionCost(attr, reply); err != nil { + if err = cdrS.V1StoreSessionCost(context.Background(), attr, reply); err != nil { t.Error(err) } } @@ -1264,17 +1266,17 @@ func TestV2StoreSessionCost(t *testing.T) { Cache.Clear(nil) cfg := config.NewDefaultCGRConfig() ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderRefundRounding: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderRefundRounding: func(ctx *context.Context, args, reply any) error { rpl := &Account{} *reply.(*Account) = *rpl return nil }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.RateSConnsCfg): clientconn, }) cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 @@ -1315,7 +1317,7 @@ func TestV2StoreSessionCost(t *testing.T) { } var reply string - if err := cdrS.V2StoreSessionCost(args, &reply); err != nil { + if err := cdrS.V2StoreSessionCost(context.Background(), args, &reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{Result: utils.StringPointer("OK"), Error: nil} @@ -1330,7 +1332,7 @@ func TestV2StoreSessionCost(t *testing.T) { args = &ArgsV2CDRSStoreSMCost{ Cost: &V2SMCost{}, } - if err = cdrS.V2StoreSessionCost(args, &reply); err == nil { + if err = cdrS.V2StoreSessionCost(context.Background(), args, &reply); err == nil { t.Error(err) } } @@ -1339,17 +1341,17 @@ func TestV2StoreSessionCostSet(t *testing.T) { Cache.Clear(nil) cfg := config.NewDefaultCGRConfig() ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderRefundRounding: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderRefundRounding: func(ctx *context.Context, args, reply any) error { rpl := &Account{} *reply.(*Account) = *rpl return nil }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.RateSConnsCfg): clientconn, }) cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 @@ -1445,7 +1447,7 @@ func TestV2StoreSessionCostSet(t *testing.T) { &utils.CachedRPCResponse{Result: reply, Error: nil}, nil, true, utils.NonTransactional) - if err := cdrS.V2StoreSessionCost(args, reply); err != nil { + if err := cdrS.V2StoreSessionCost(context.Background(), args, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{Result: reply, Error: nil} @@ -1480,7 +1482,7 @@ func TestV1RateCDRSErr(t *testing.T) { } var reply string - if err := cdrS.V1RateCDRs(arg, &reply); err == nil || err != utils.ErrNotFound { + if err := cdrS.V1RateCDRs(context.Background(), arg, &reply); err == nil || err != utils.ErrNotFound { t.Error(err) } } @@ -1511,11 +1513,11 @@ func TestV1GetCDRsErr(t *testing.T) { APIOpts: map[string]any{}, } var cdrs *[]*CDR - if err := cdrS.V1GetCDRs(args, cdrs); err == nil { + if err := cdrS.V1GetCDRs(context.Background(), args, cdrs); err == nil { t.Error(utils.NewErrServerError(utils.ErrNotFound)) } args.RPCCDRsFilter.SetupTimeStart = "" - if err := cdrS.V1GetCDRs(args, cdrs); err == nil || err.Error() != fmt.Sprintf("SERVER_ERROR: %s", utils.ErrNotFound) { + if err := cdrS.V1GetCDRs(context.Background(), args, cdrs); err == nil || err.Error() != fmt.Sprintf("SERVER_ERROR: %s", utils.ErrNotFound) { t.Error(utils.NewErrServerError(utils.ErrNotFound)) } } @@ -1526,21 +1528,21 @@ func TestGetCostFromRater2(t *testing.T) { db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderDebit: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderDebit: func(ctx *context.Context, args, reply any) error { return utils.ErrAccountNotFound }, - utils.SchedulerSv1ExecuteActionPlans: func(args, reply any) error { + utils.SchedulerSv1ExecuteActionPlans: func(ctx *context.Context, args, reply any) error { rpl := "reply" *reply.(*string) = rpl return nil }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.RateSConnsCfg): clientconn, utils.ConcatenatedKey(utils.MetaInternal, utils.SchedulerConnsCfg): clientconn, }) @@ -1576,16 +1578,16 @@ func TestGetCostFromRater3(t *testing.T) { db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderGetCost: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderGetCost: func(ctx *context.Context, args, reply any) error { return nil }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.RateSConnsCfg): clientconn, }) cdrS := &CDRServer{ @@ -1622,17 +1624,17 @@ func TestV2StoreSessionCost2(t *testing.T) { db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) ccMOck := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderRefundRounding: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderRefundRounding: func(ctx *context.Context, args, reply any) error { rpl := &Account{} *reply.(*Account) = *rpl return nil }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMOck - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.RateSConnsCfg): clientconn, }) cdrS := &CDRServer{ @@ -1753,16 +1755,16 @@ func TestV2StoreSessionCost2(t *testing.T) { APIOpts: map[string]any{}, } var reply string - if err := cdrS.V2StoreSessionCost(args, &reply); err != nil { + if err := cdrS.V2StoreSessionCost(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("expected %+v,received %+v", utils.OK, reply) } - clientconn2 := make(chan rpcclient.ClientConnector, 1) + clientconn2 := make(chan birpc.ClientConnector, 1) clientconn2 <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderRefundRounding: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderRefundRounding: func(ctx *context.Context, args, reply any) error { rpl := &Account{} *reply.(*Account) = *rpl return utils.ErrNotFound @@ -1771,7 +1773,7 @@ func TestV2StoreSessionCost2(t *testing.T) { } cdrS.connMgr.rpcInternal[utils.ConcatenatedKey(utils.MetaInternal, utils.RateSConnsCfg)] = clientconn2 - if err := cdrS.V2StoreSessionCost(args, &reply); err != nil { + if err := cdrS.V2StoreSessionCost(context.Background(), args, &reply); err != nil { t.Error(err) } @@ -1818,7 +1820,7 @@ func TestV1RateCDRSSuccesful(t *testing.T) { } var reply *string - if err := cdrS.V1RateCDRs(arg, reply); err == nil { + if err := cdrS.V1RateCDRs(context.Background(), arg, reply); err == nil { t.Error(err) } } @@ -1891,10 +1893,10 @@ func TestCdrSRateCDR(t *testing.T) { Replicate: true, }, }) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderDebit: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderDebit: func(ctx *context.Context, args, reply any) error { cc := &CallCost{ Category: "generic", Tenant: "cgrates.org", @@ -1909,7 +1911,7 @@ func TestCdrSRateCDR(t *testing.T) { }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), nil) @@ -2005,10 +2007,10 @@ func TestChrgrSProcessEvent(t *testing.T) { cfg.CdrsCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - clienConn := make(chan rpcclient.ClientConnector, 1) + clienConn := make(chan birpc.ClientConnector, 1) clienConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ChargerSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ChargerSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { *reply.(*[]*ChrgSProcessEventReply) = []*ChrgSProcessEventReply{ { ChargerSProfile: "Charger1", @@ -2034,7 +2036,7 @@ func TestChrgrSProcessEvent(t *testing.T) { }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): clienConn, }) cdrS := &CDRServer{ @@ -2079,44 +2081,6 @@ func TestChrgrSProcessEvent(t *testing.T) { } } -func TestCdrSCall123(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - tmpConnMgr := connMgr - defer func() { - connMgr = tmpConnMgr - config.SetCgrConfig(config.NewDefaultCGRConfig()) - }() - db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - dm := NewDataManager(db, cfg.CacheCfg(), nil) - cdrS := &CDRServer{ - cgrCfg: cfg, - connMgr: connMgr, - dm: dm, - cdrDb: db, - } - clientConn := make(chan rpcclient.ClientConnector, 1) - clientConn <- cdrS - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{}) - config.SetCgrConfig(cfg) - SetConnManager(connMgr) - var reply string - attr := &AttrCDRSStoreSMCost{ - Cost: &SMCost{ - CGRID: "cgrid1", - RunID: "run1", - OriginID: "originid", - CostDetails: &EventCost{ - Usage: utils.DurationPointer(1 * time.Minute), - Cost: utils.Float64Pointer(32.3), - }, - }, - CheckDuplicate: false, - } - if err := cdrS.Call(utils.CDRsV1StoreSessionCost, attr, &reply); err != nil { - t.Error(err) - } -} - func TestCDRServerListenAndServe(t *testing.T) { cfg := config.NewDefaultCGRConfig() tmpConnMgr := connMgr @@ -2281,7 +2245,7 @@ func TestCDRSGetCDRs(t *testing.T) { cfg.CdrsCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- clMock(func(serviceMethod string, _, _ any) error { if serviceMethod == utils.EeSv1ProcessEvent { @@ -2300,7 +2264,7 @@ func TestCDRSGetCDRs(t *testing.T) { cgrCfg: cfg, cdrDb: db, dm: dm, - connMgr: NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr: NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaEEs): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): clientConn, @@ -2334,7 +2298,7 @@ func TestCDRSGetCDRs(t *testing.T) { }, } var reply string - if err := cdrS.V1ProcessEvent(arg, &reply); err != nil { + if err := cdrS.V1ProcessEvent(context.Background(), arg, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Expected OK") @@ -2344,7 +2308,7 @@ func TestCDRSGetCDRs(t *testing.T) { args := utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{RequestTypes: []string{utils.MetaPrepaid}}, } - if err := cdrS.V1GetCDRs(args, &cdrs); err != nil { + if err := cdrS.V1GetCDRs(context.Background(), args, &cdrs); err != nil { t.Error(err) } } @@ -2390,7 +2354,7 @@ func TestV1RateCDRsSuccesful(t *testing.T) { }, APIOpts: map[string]any{}, } - if err := cdrS.V1RateCDRs(arg, &reply); err != nil { + if err := cdrS.V1RateCDRs(context.Background(), arg, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Expected reply to be ok") diff --git a/engine/chargers.go b/engine/chargers.go index 20bc1a1c7..3f21351df 100644 --- a/engine/chargers.go +++ b/engine/chargers.go @@ -21,6 +21,7 @@ package engine import ( "fmt" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -129,7 +130,7 @@ func (cS *ChargerService) processEvent(tnt string, cgrEv *utils.CGREvent) (rply utils.IfaceAsString(ctx), utils.MetaChargers) var evReply AttrSProcessEventReply - if err = cS.connMgr.Call(cS.cfg.ChargerSCfg().AttributeSConns, nil, + if err = cS.connMgr.Call(context.TODO(), cS.cfg.ChargerSCfg().AttributeSConns, utils.AttributeSv1ProcessEvent, clonedEv, &evReply); err != nil { if err.Error() != utils.ErrNotFound.Error() { return nil, err @@ -149,7 +150,7 @@ func (cS *ChargerService) processEvent(tnt string, cgrEv *utils.CGREvent) (rply } // V1ProcessEvent will process the event received via API and return list of events forked -func (cS *ChargerService) V1ProcessEvent(args *utils.CGREvent, +func (cS *ChargerService) V1ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*ChrgSProcessEventReply) (err error) { if args == nil || args.Event == nil { @@ -171,7 +172,7 @@ func (cS *ChargerService) V1ProcessEvent(args *utils.CGREvent, } // V1GetChargersForEvent exposes the list of ordered matching ChargingProfiles for an event -func (cS *ChargerService) V1GetChargersForEvent(args *utils.CGREvent, +func (cS *ChargerService) V1GetChargersForEvent(ctx *context.Context, args *utils.CGREvent, rply *ChargerProfiles) (err error) { tnt := args.Tenant if tnt == utils.EmptyString { diff --git a/engine/chargers_test.go b/engine/chargers_test.go index 5c38e892b..0caa1a771 100644 --- a/engine/chargers_test.go +++ b/engine/chargers_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" @@ -664,7 +665,7 @@ func TestChargersV1ProcessEventMissingArgs(t *testing.T) { var reply *[]*ChrgSProcessEventReply experr := "MANDATORY_IE_MISSING: [Event]" - err := cS.V1ProcessEvent(args, reply) + err := cS.V1ProcessEvent(context.Background(), args, reply) if err == nil || err.Error() != experr { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) diff --git a/engine/connmanager.go b/engine/connmanager.go index c53b5faf0..87bcd8252 100644 --- a/engine/connmanager.go +++ b/engine/connmanager.go @@ -23,6 +23,8 @@ import ( "strings" "sync" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" @@ -30,7 +32,7 @@ import ( ) // NewConnManager returns the Connection Manager -func NewConnManager(cfg *config.CGRConfig, rpcInternal map[string]chan rpcclient.ClientConnector) (cM *ConnManager) { +func NewConnManager(cfg *config.CGRConfig, rpcInternal map[string]chan birpc.ClientConnector) (cM *ConnManager) { cM = &ConnManager{ cfg: cfg, rpcInternal: rpcInternal, @@ -47,7 +49,7 @@ func NewConnManager(cfg *config.CGRConfig, rpcInternal map[string]chan rpcclient // ConnManager handle the RPC connections type ConnManager struct { cfg *config.CGRConfig - rpcInternal map[string]chan rpcclient.ClientConnector + rpcInternal map[string]chan birpc.ClientConnector connCache *ltcache.Cache connLks map[string]*sync.Mutex // control connection initialization and caching } @@ -68,16 +70,16 @@ func (cM *ConnManager) unlkConn(connID string) { // getConn is used to retrieve a connection from cache // in case this doesn't exist create it and cache it -func (cM *ConnManager) getConn(connID string, biRPCClient rpcclient.BiRPCConector) (conn rpcclient.ClientConnector, err error) { +func (cM *ConnManager) getConn(ctx *context.Context, connID string) (conn birpc.ClientConnector, err error) { //try to get the connection from cache if x, ok := Cache.Get(utils.CacheRPCConnections, connID); ok { if x == nil { return nil, utils.ErrNotFound } - return x.(rpcclient.ClientConnector), nil + return x.(birpc.ClientConnector), nil } // in case we don't find in cache create the connection and add this in cache - var intChan chan rpcclient.ClientConnector + var intChan chan birpc.ClientConnector var isInternalRPC bool var connCfg *config.RPCConn if intChan, isInternalRPC = cM.rpcInternal[connID]; isInternalRPC { @@ -94,7 +96,7 @@ func (cM *ConnManager) getConn(connID string, biRPCClient rpcclient.BiRPCConecto } } } - if conn, err = cM.getConnWithConfig(connID, connCfg, biRPCClient, intChan, isInternalRPC); err != nil { + if conn, err = cM.getConnWithConfig(ctx, connID, connCfg, intChan, isInternalRPC); err != nil { return } err = Cache.Set(utils.CacheRPCConnections, connID, conn, nil, @@ -102,9 +104,8 @@ func (cM *ConnManager) getConn(connID string, biRPCClient rpcclient.BiRPCConecto return } -func (cM *ConnManager) getConnWithConfig(connID string, connCfg *config.RPCConn, - biRPCClient rpcclient.BiRPCConector, intChan chan rpcclient.ClientConnector, - isInternalRPC bool) (conn rpcclient.ClientConnector, err error) { +func (cM *ConnManager) getConnWithConfig(ctx *context.Context, connID string, connCfg *config.RPCConn, + intChan chan birpc.ClientConnector, isInternalRPC bool) (conn birpc.ClientConnector, err error) { if connCfg.Strategy == rpcclient.PoolParallel { rpcConnCfg := connCfg.Conns[0] // for parallel we need only the first connection codec := rpcclient.GOBrpc @@ -125,28 +126,38 @@ func (cM *ConnManager) getConnWithConfig(connID string, connCfg *config.RPCConn, err = fmt.Errorf("Unsupported transport: <%s>", rpcConnCfg.Transport) return } - if conn, err = rpcclient.NewRPCParallelClientPool(utils.TCP, rpcConnCfg.Address, rpcConnCfg.TLS, - utils.FirstNonEmpty(rpcConnCfg.ClientKey, cM.cfg.TLSCfg().ClientKey), utils.FirstNonEmpty(rpcConnCfg.ClientCertificate, cM.cfg.TLSCfg().ClientCerificate), - utils.FirstNonEmpty(rpcConnCfg.CaCertificate, cM.cfg.TLSCfg().CaCertificate), utils.FirstIntNonEmpty(rpcConnCfg.ConnectAttempts, cM.cfg.GeneralCfg().ConnectAttempts), - utils.FirstIntNonEmpty(rpcConnCfg.Reconnects, cM.cfg.GeneralCfg().Reconnects), utils.FirstDurationNonEmpty(rpcConnCfg.ConnectTimeout, cM.cfg.GeneralCfg().ConnectTimeout), - utils.FirstDurationNonEmpty(rpcConnCfg.ReplyTimeout, cM.cfg.GeneralCfg().ReplyTimeout), codec, intChan, int64(cM.cfg.GeneralCfg().MaxParallelConns), false, biRPCClient); err != nil { + if conn, err = rpcclient.NewRPCParallelClientPool(ctx, utils.TCP, rpcConnCfg.Address, rpcConnCfg.TLS, + utils.FirstNonEmpty(rpcConnCfg.ClientKey, cM.cfg.TLSCfg().ClientKey), + utils.FirstNonEmpty(rpcConnCfg.ClientCertificate, cM.cfg.TLSCfg().ClientCerificate), + utils.FirstNonEmpty(rpcConnCfg.CaCertificate, cM.cfg.TLSCfg().CaCertificate), + utils.FirstIntNonEmpty(rpcConnCfg.ConnectAttempts, cM.cfg.GeneralCfg().ConnectAttempts), + utils.FirstIntNonEmpty(rpcConnCfg.Reconnects, cM.cfg.GeneralCfg().Reconnects), + utils.FirstDurationNonEmpty(rpcConnCfg.MaxReconnectInterval, cM.cfg.GeneralCfg().MaxReconnectInterval), + utils.FibDuration, + utils.FirstDurationNonEmpty(rpcConnCfg.ConnectTimeout, cM.cfg.GeneralCfg().ConnectTimeout), + utils.FirstDurationNonEmpty(rpcConnCfg.ReplyTimeout, cM.cfg.GeneralCfg().ReplyTimeout), + codec, intChan, int64(cM.cfg.GeneralCfg().MaxParallelConns), false, ctx.Client); err != nil { return } } else { - if conn, err = NewRPCPool(connCfg.Strategy, + if conn, err = NewRPCPool(ctx, connCfg.Strategy, cM.cfg.TLSCfg().ClientKey, - cM.cfg.TLSCfg().ClientCerificate, cM.cfg.TLSCfg().CaCertificate, - cM.cfg.GeneralCfg().ConnectAttempts, cM.cfg.GeneralCfg().Reconnects, - cM.cfg.GeneralCfg().ConnectTimeout, cM.cfg.GeneralCfg().ReplyTimeout, - connCfg.Conns, intChan, false, biRPCClient, connID, cM.connCache); err != nil { + cM.cfg.TLSCfg().ClientCerificate, + cM.cfg.TLSCfg().CaCertificate, + cM.cfg.GeneralCfg().ConnectAttempts, + cM.cfg.GeneralCfg().Reconnects, + cM.cfg.GeneralCfg().MaxReconnectInterval, + cM.cfg.GeneralCfg().ConnectTimeout, + cM.cfg.GeneralCfg().ReplyTimeout, + connCfg.Conns, intChan, false, connID, cM.connCache); err != nil { return } } - if biRPCClient != nil { + if ctx.Client != nil { for _, c := range connCfg.Conns { if c.Address == rpcclient.BiRPCInternal { // register only on internal var rply string - if err = conn.Call(utils.SessionSv1RegisterInternalBiJSONConn, + if err = conn.Call(ctx, utils.SessionSv1RegisterInternalBiJSONConn, connID, &rply); err != nil { utils.Logger.Crit(fmt.Sprintf("<%s> Could not register biRPCClient, error: <%s>", utils.SessionS, err.Error())) @@ -160,20 +171,19 @@ func (cM *ConnManager) getConnWithConfig(connID string, connCfg *config.RPCConn, } // Call gets the connection calls the method on it -func (cM *ConnManager) Call(connIDs []string, biRPCClient rpcclient.BiRPCConector, - method string, arg, reply any) (err error) { +func (cM *ConnManager) Call(ctx *context.Context, connIDs []string, method string, arg, reply any) (err error) { if len(connIDs) == 0 { return utils.NewErrMandatoryIeMissing("connIDs") } - var conn rpcclient.ClientConnector + var conn birpc.ClientConnector for _, connID := range connIDs { cM.lkConn(connID) - conn, err = cM.getConn(connID, biRPCClient) + conn, err = cM.getConn(ctx, connID) cM.unlkConn(connID) if err != nil { continue } - if err = conn.Call(method, arg, reply); !rpcclient.IsNetworkError(err) { + if err = conn.Call(ctx, method, arg, reply); !rpcclient.IsNetworkError(err) { return } } @@ -189,7 +199,7 @@ func (cM *ConnManager) CallWithConnIDs(connIDs []string, subsHostIDs utils.Strin if subsHostIDs.Size() == 0 { return } - var conn rpcclient.ClientConnector + var conn birpc.ClientConnector for _, connID := range connIDs { // recreate the config with only conns that are needed connCfg := cM.cfg.RPCConns()[connID] @@ -209,10 +219,10 @@ func (cM *ConnManager) CallWithConnIDs(connIDs []string, subsHostIDs utils.Strin // skip this pool if no connection matches continue } - if conn, err = cM.getConnWithConfig(connID, newCfg, nil, nil, false); err != nil { + if conn, err = cM.getConnWithConfig(context.TODO(), connID, newCfg, nil, false); err != nil { continue } - if err = conn.Call(method, arg, reply); !rpcclient.IsNetworkError(err) { + if err = conn.Call(context.TODO(), method, arg, reply); !rpcclient.IsNetworkError(err) { return } } diff --git a/engine/connmanager_test.go b/engine/connmanager_test.go index 0b1c1379f..69e589b6c 100644 --- a/engine/connmanager_test.go +++ b/engine/connmanager_test.go @@ -23,6 +23,8 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" @@ -42,14 +44,14 @@ func TestCMgetConnNotFound(t *testing.T) { Cache.SetWithoutReplicate(utils.CacheRPCConnections, connID, nil, nil, true, utils.NonTransactional) experr := utils.ErrNotFound - rcv, err := cM.getConn(connID, nil) + rcv, err := cM.getConn(context.Background(), connID) if err == nil || err != experr { - t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) + t.Fatalf("expected: <%+v>, \nreceived: <%+v>", experr, err) } if rcv != nil { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", nil, rcv) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", nil, rcv) } } @@ -59,31 +61,36 @@ func TestCMgetConnUnsupportedBiRPC(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.RPCConns()[connID] = config.NewDfltRPCConn() - cc := make(chan rpcclient.ClientConnector, 1) + cc := make(chan birpc.ClientConnector, 1) cM := &ConnManager{ cfg: cfg, - rpcInternal: map[string]chan rpcclient.ClientConnector{ + rpcInternal: map[string]chan birpc.ClientConnector{ connID: cc, }, connCache: ltcache.NewCache(-1, 0, true, nil), } experr := rpcclient.ErrUnsupportedBiRPC - exp, err := NewRPCPool("*first", "", "", "", cfg.GeneralCfg().ConnectAttempts, - cfg.GeneralCfg().Reconnects, cfg.GeneralCfg().ConnectTimeout, - cfg.GeneralCfg().ReplyTimeout, nil, cc, true, nil, "", cM.connCache) + exp, err := NewRPCPool(context.Background(), + "*first", "", "", "", + cfg.GeneralCfg().ConnectAttempts, + cfg.GeneralCfg().Reconnects, + cfg.GeneralCfg().MaxReconnectInterval, + cfg.GeneralCfg().ConnectTimeout, + cfg.GeneralCfg().ReplyTimeout, + nil, cc, true, "", cM.connCache) if err != nil { t.Fatal(err) } - rcv, err := cM.getConn(connID, nil) + rcv, err := cM.getConn(context.Background(), connID) if err == nil || err != experr { - t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) + t.Fatalf("expected: <%+v>, \nreceived: <%+v>", experr, err) } if !reflect.DeepEqual(rcv, exp) { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv) } } @@ -99,11 +106,11 @@ func TestCMgetConnNotInternalRPC(t *testing.T) { }, } - cc := make(chan rpcclient.ClientConnector, 1) + cc := make(chan birpc.ClientConnector, 1) cM := &ConnManager{ cfg: cfg, - rpcInternal: map[string]chan rpcclient.ClientConnector{ + rpcInternal: map[string]chan birpc.ClientConnector{ "testString": cc, }, connCache: ltcache.NewCache(-1, 0, true, nil), @@ -111,22 +118,28 @@ func TestCMgetConnNotInternalRPC(t *testing.T) { cM.connCache.Set(connID, nil, nil) - exp, err := NewRPCPool("*first", cfg.TLSCfg().ClientKey, cfg.TLSCfg().ClientCerificate, - cfg.TLSCfg().CaCertificate, cfg.GeneralCfg().ConnectAttempts, - cfg.GeneralCfg().Reconnects, cfg.GeneralCfg().ConnectTimeout, - cfg.GeneralCfg().ReplyTimeout, cfg.RPCConns()[connID].Conns, cc, - true, nil, connID, cM.connCache) + exp, err := NewRPCPool(context.Background(), "*first", + cfg.TLSCfg().ClientKey, + cfg.TLSCfg().ClientCerificate, + cfg.TLSCfg().CaCertificate, + cfg.GeneralCfg().ConnectAttempts, + cfg.GeneralCfg().Reconnects, + cfg.GeneralCfg().MaxReconnectInterval, + cfg.GeneralCfg().ConnectTimeout, + cfg.GeneralCfg().ReplyTimeout, + cfg.RPCConns()[connID].Conns, + cc, true, connID, cM.connCache) if err != nil { t.Fatal(err) } - rcv, err := cM.getConn(connID, nil) + rcv, err := cM.getConn(context.Background(), connID) if err != nil { - t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) + t.Fatalf("expected: <%+v>, \nreceived: <%+v>", nil, err) } if !reflect.DeepEqual(rcv, exp) { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv) } } @@ -142,25 +155,25 @@ func TestCMgetConnWithConfigUnsupportedTransport(t *testing.T) { }, } - cc := make(chan rpcclient.ClientConnector, 1) + cc := make(chan birpc.ClientConnector, 1) cM := &ConnManager{ cfg: cfg, - rpcInternal: map[string]chan rpcclient.ClientConnector{ + rpcInternal: map[string]chan birpc.ClientConnector{ connID: cc, }, connCache: ltcache.NewCache(-1, 0, true, nil), } experr := fmt.Sprintf("Unsupported transport: <%+s>", "invalid") - rcv, err := cM.getConnWithConfig(connID, cfg.RPCConns()[connID], nil, cc, true) + rcv, err := cM.getConnWithConfig(context.Background(), connID, cfg.RPCConns()[connID], cc, true) if err == nil || err.Error() != experr { - t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) + t.Fatalf("expected: <%+v>, \nreceived: <%+v>", experr, err) } if rcv != nil { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", nil, rcv) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", nil, rcv) } } @@ -176,11 +189,11 @@ func TestCMgetConnWithConfigUnsupportedCodec(t *testing.T) { }, } - cc := make(chan rpcclient.ClientConnector, 1) + cc := make(chan birpc.ClientConnector, 1) cM := &ConnManager{ cfg: cfg, - rpcInternal: map[string]chan rpcclient.ClientConnector{ + rpcInternal: map[string]chan birpc.ClientConnector{ connID: cc, }, connCache: ltcache.NewCache(-1, 0, true, nil), @@ -188,14 +201,14 @@ func TestCMgetConnWithConfigUnsupportedCodec(t *testing.T) { experr := rpcclient.ErrUnsupportedCodec var exp *rpcclient.RPCParallelClientPool - rcv, err := cM.getConnWithConfig(connID, cfg.RPCConns()[connID], nil, cc, true) + rcv, err := cM.getConnWithConfig(context.Background(), connID, cfg.RPCConns()[connID], cc, true) if err == nil || err != experr { - t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) + t.Fatalf("expected: <%+v>, \nreceived: <%+v>", experr, err) } if !reflect.DeepEqual(rcv, exp) { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv) } } @@ -211,11 +224,11 @@ func TestCMgetConnWithConfigEmptyTransport(t *testing.T) { }, } - cc := make(chan rpcclient.ClientConnector, 1) + cc := make(chan birpc.ClientConnector, 1) cM := &ConnManager{ cfg: cfg, - rpcInternal: map[string]chan rpcclient.ClientConnector{ + rpcInternal: map[string]chan birpc.ClientConnector{ connID: cc, }, connCache: ltcache.NewCache(-1, 0, true, nil), @@ -223,10 +236,10 @@ func TestCMgetConnWithConfigEmptyTransport(t *testing.T) { cM.connCache.Set(connID, nil, nil) - rcv, err := cM.getConnWithConfig(connID, cfg.RPCConns()[connID], nil, cc, true) + rcv, err := cM.getConnWithConfig(context.Background(), connID, cfg.RPCConns()[connID], cc, true) if err != nil { - t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) + t.Fatalf("expected: <%+v>, \nreceived: <%+v>", nil, err) } if _, cancast := rcv.(*rpcclient.RPCParallelClientPool); !cancast { @@ -235,124 +248,13 @@ func TestCMgetConnWithConfigEmptyTransport(t *testing.T) { } type BiRPCConnectorMock struct { - calls map[string]func(rpcclient.ClientConnector, string, any, any) error + calls map[string]func(birpc.ClientConnector, string, any, any) error } -func (bRCM *BiRPCConnectorMock) Call(serviceMethod string, args any, reply any) (err error) { +func (bRCM *BiRPCConnectorMock) Call(ctx *context.Context, serviceMethod string, args any, reply any) (err error) { return nil } -func (bRCM *BiRPCConnectorMock) CallBiRPC(cc rpcclient.ClientConnector, method string, args any, reply any) error { - if call, has := bRCM.calls[method]; !has { - return rpcclient.ErrUnsupporteServiceMethod - } else { - return call(cc, method, args, reply) - } -} - -func (bRCM *BiRPCConnectorMock) Handlers() map[string]any { - return nil -} - -func TestCMgetConnWithConfigCallBiRPCNilErr(t *testing.T) { - connID := "connID" - cfg := config.NewDefaultCGRConfig() - cfg.RPCConns()[connID] = config.NewDfltRPCConn() - cfg.RPCConns()[connID].Conns = []*config.RemoteHost{ - { - ID: connID, - Address: rpcclient.BiRPCInternal, - Transport: rpcclient.BiRPCJSON, - }, - } - - cc := make(chan rpcclient.ClientConnector, 1) - birpc := &BiRPCConnectorMock{ - calls: map[string]func(rpcclient.ClientConnector, string, any, any) error{ - utils.SessionSv1RegisterInternalBiJSONConn: func(cc rpcclient.ClientConnector, s string, i1, i2 any) error { - return nil - }, - }, - } - cc <- birpc - - cM := &ConnManager{ - cfg: cfg, - rpcInternal: map[string]chan rpcclient.ClientConnector{ - connID: cc, - }, - connCache: ltcache.NewCache(-1, 0, true, nil), - } - - exp, err := NewRPCPool("*first", cfg.TLSCfg().ClientKey, cfg.TLSCfg().ClientCerificate, - cfg.TLSCfg().CaCertificate, cfg.GeneralCfg().ConnectAttempts, - cfg.GeneralCfg().Reconnects, cfg.GeneralCfg().ConnectTimeout, - cfg.GeneralCfg().ReplyTimeout, cfg.RPCConns()[connID].Conns, cc, - false, birpc, connID, cM.connCache) - if err != nil { - t.Fatal(err) - } - rcv, err := cM.getConnWithConfig(connID, cfg.RPCConns()[connID], birpc, cc, true) - - if err != nil { - t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) - } - - if !reflect.DeepEqual(rcv, exp) { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv) - } -} - -func TestCMgetConnWithConfigCallBiRPCErr(t *testing.T) { - connID := "connID" - cfg := config.NewDefaultCGRConfig() - cfg.RPCConns()[connID] = config.NewDfltRPCConn() - cfg.RPCConns()[connID].Conns = []*config.RemoteHost{ - { - ID: connID, - Address: rpcclient.BiRPCInternal, - Transport: rpcclient.BiRPCJSON, - }, - } - - cc := make(chan rpcclient.ClientConnector, 1) - birpc := &BiRPCConnectorMock{ - calls: map[string]func(rpcclient.ClientConnector, string, any, any) error{ - "wrong method": func(cc rpcclient.ClientConnector, s string, i1, i2 any) error { - return nil - }, - }, - } - cc <- birpc - - cM := &ConnManager{ - cfg: cfg, - rpcInternal: map[string]chan rpcclient.ClientConnector{ - connID: cc, - }, - connCache: ltcache.NewCache(-1, 0, true, nil), - } - - exp, err := NewRPCPool("*first", cfg.TLSCfg().ClientKey, cfg.TLSCfg().ClientCerificate, - cfg.TLSCfg().CaCertificate, cfg.GeneralCfg().ConnectAttempts, - cfg.GeneralCfg().Reconnects, cfg.GeneralCfg().ConnectTimeout, - cfg.GeneralCfg().ReplyTimeout, cfg.RPCConns()[connID].Conns, cc, - false, birpc, connID, cM.connCache) - if err != nil { - t.Fatal(err) - } - experr := rpcclient.ErrUnsupporteServiceMethod - rcv, err := cM.getConnWithConfig(connID, cfg.RPCConns()[connID], birpc, cc, true) - - if err == nil || err != experr { - t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) - } - - if !reflect.DeepEqual(rcv, exp) { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv) - } -} - func TestCMgetConnWithConfigInternalRPCCodec(t *testing.T) { connID := "connID" cfg := config.NewDefaultCGRConfig() @@ -364,20 +266,20 @@ func TestCMgetConnWithConfigInternalRPCCodec(t *testing.T) { }, } - cc := make(chan rpcclient.ClientConnector, 1) + cc := make(chan birpc.ClientConnector, 1) cM := &ConnManager{ cfg: cfg, - rpcInternal: map[string]chan rpcclient.ClientConnector{ + rpcInternal: map[string]chan birpc.ClientConnector{ connID: cc, }, connCache: ltcache.NewCache(-1, 0, true, nil), } - rcv, err := cM.getConnWithConfig(connID, cfg.RPCConns()[connID], nil, cc, true) + rcv, err := cM.getConnWithConfig(context.Background(), connID, cfg.RPCConns()[connID], cc, true) if err != nil { - t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) + t.Fatalf("expected: <%+v>, \nreceived: <%+v>", nil, err) } if _, cancast := rcv.(*rpcclient.RPCParallelClientPool); !cancast { @@ -396,21 +298,21 @@ func TestCMgetConnWithConfigInternalBiRPCCodecUnsupported(t *testing.T) { }, } - cc := make(chan rpcclient.ClientConnector, 1) + cc := make(chan birpc.ClientConnector, 1) cM := &ConnManager{ cfg: cfg, - rpcInternal: map[string]chan rpcclient.ClientConnector{ + rpcInternal: map[string]chan birpc.ClientConnector{ connID: cc, }, connCache: ltcache.NewCache(-1, 0, true, nil), } experr := rpcclient.ErrUnsupportedCodec - rcv, err := cM.getConnWithConfig(connID, cfg.RPCConns()[connID], nil, cc, true) + rcv, err := cM.getConnWithConfig(context.Background(), connID, cfg.RPCConns()[connID], cc, true) if err == nil || err != experr { - t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) + t.Fatalf("expected: <%+v>, \nreceived: <%+v>", experr, err) } if _, cancast := rcv.(*rpcclient.RPCParallelClientPool); !cancast { @@ -431,10 +333,10 @@ func TestCMCallErrgetConn(t *testing.T) { Cache.SetWithoutReplicate(utils.CacheRPCConnections, connID, nil, nil, true, utils.NonTransactional) experr := utils.ErrNotFound - err := cM.Call([]string{connID}, nil, "", "", "") + err := cM.Call(context.Background(), []string{connID}, "", "", "") if err == nil || err != experr { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } } @@ -451,7 +353,7 @@ func TestCMCallWithConnIDsNoSubsHostIDs(t *testing.T) { err := cM.CallWithConnIDs([]string{connID}, subsHostIDs, "", "", "") if err != nil { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", nil, err) } } @@ -471,7 +373,7 @@ func TestCMCallWithConnIDsNoConnIDs(t *testing.T) { err := cM.CallWithConnIDs([]string{}, subsHostIDs, "", "", "") if err == nil || err.Error() != experr { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } } @@ -496,7 +398,7 @@ func TestCMCallWithConnIDsNoConns(t *testing.T) { err := cM.CallWithConnIDs([]string{connID}, subsHostIDs, "", "", "") if err != nil { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", nil, err) } } @@ -523,7 +425,7 @@ func TestCMCallWithConnIDsInternallyDCed(t *testing.T) { err := cM.CallWithConnIDs([]string{connID}, subsHostIDs, "", "", "") if err == nil || err != experr { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", nil, err) } } @@ -540,8 +442,8 @@ func TestCMCallWithConnIDs2(t *testing.T) { } ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - "testMethod": func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + "testMethod": func(ctx *context.Context, args, reply any) error { return utils.ErrExists }, }, @@ -562,7 +464,7 @@ func TestCMCallWithConnIDs2(t *testing.T) { err := cM.CallWithConnIDs([]string{poolID}, subsHostIDs, "testMethod", "", "") if err == nil || err != experr { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } } @@ -585,11 +487,11 @@ func TestCMReload(t *testing.T) { rcv2 := Cache.GetItemIDs(utils.CacheRPCConnections, utils.EmptyString) if !reflect.DeepEqual(rcv1, exp) { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv1) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv1) } if !reflect.DeepEqual(rcv2, exp) { - t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", exp, rcv2) + t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, rcv2) } } diff --git a/engine/datamanager.go b/engine/datamanager.go index 66634e99d..390391d17 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -19,11 +19,11 @@ along with this program. If not, see package engine import ( - "context" "fmt" "strings" "github.com/cgrates/baningo" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" @@ -354,7 +354,7 @@ func (dm *DataManager) GetDestination(key string, cacheRead, cacheWrite bool, tr dest, err = dm.dataDB.GetDestinationDrv(key, transactionID) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaDestinations]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetDestination, &utils.StringWithAPIOpts{ Arg: key, Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, @@ -482,7 +482,7 @@ func (dm *DataManager) GetReverseDestination(prefix string, ids, err = dm.dataDB.GetReverseDestinationDrv(prefix, transactionID) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaReverseDestinations]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetReverseDestination, &utils.StringWithAPIOpts{ Arg: prefix, Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, @@ -569,7 +569,7 @@ func (dm *DataManager) GetAccount(id string) (acc *Account, err error) { itm.Remote { splt := utils.SplitConcatenatedKey(id) tenant := utils.FirstNonEmpty(splt[0], config.CgrConfig().GeneralCfg().DefaultTenant) - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetAccount, &utils.StringWithAPIOpts{ Arg: id, Tenant: tenant, @@ -652,7 +652,7 @@ func (dm *DataManager) GetFilter(tenant, id string, cacheRead, cacheWrite bool, fltr, err = dm.DataDB().GetFilterDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaFilters]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetFilter, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetFilter, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID, utils.EmptyString, @@ -780,7 +780,7 @@ func (dm *DataManager) GetThreshold(tenant, id string, th, err = dm.dataDB.GetThresholdDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaThresholds]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetThreshold, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID, utils.EmptyString, @@ -868,7 +868,7 @@ func (dm *DataManager) GetThresholdProfile(tenant, id string, cacheRead, cacheWr th, err = dm.dataDB.GetThresholdProfileDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaThresholdProfiles]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetThresholdProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, @@ -1016,7 +1016,7 @@ func (dm *DataManager) GetStatQueue(tenant, id string, sq, err = dm.dataDB.GetStatQueueDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaStatQueues]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetStatQueue, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetStatQueue, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID, utils.EmptyString, @@ -1120,7 +1120,7 @@ func (dm *DataManager) GetStatQueueProfile(tenant, id string, cacheRead, cacheWr sqp, err = dm.dataDB.GetStatQueueProfileDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaStatQueueProfiles]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetStatQueueProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, @@ -1298,7 +1298,7 @@ func (dm *DataManager) GetTiming(id string, skipCache bool, t, err = dm.dataDB.GetTimingDrv(id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaTimings]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetTiming, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetTiming, &utils.StringWithAPIOpts{ Arg: id, Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, @@ -1390,7 +1390,7 @@ func (dm *DataManager) GetResource(tenant, id string, cacheRead, cacheWrite bool rs, err = dm.dataDB.GetResourceDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaResources]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetResource, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, @@ -1480,7 +1480,7 @@ func (dm *DataManager) GetResourceProfile(tenant, id string, cacheRead, cacheWri rp, err = dm.dataDB.GetResourceProfileDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaResourceProfile]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetResourceProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID, utils.EmptyString, @@ -1625,7 +1625,7 @@ func (dm *DataManager) GetActionTriggers(id string, skipCache bool, attrs, err = dm.dataDB.GetActionTriggersDrv(id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaActionTriggers]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetActionTriggers, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetActionTriggers, &utils.StringWithAPIOpts{ Arg: id, Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, @@ -1729,7 +1729,7 @@ func (dm *DataManager) GetSharedGroup(key string, skipCache bool, sg, err = dm.DataDB().GetSharedGroupDrv(key) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaSharedGroups]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetSharedGroup, &utils.StringWithAPIOpts{ Arg: key, Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, @@ -1827,7 +1827,7 @@ func (dm *DataManager) GetActions(key string, skipCache bool, transactionID stri as, err = dm.DataDB().GetActionsDrv(key) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaActions]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetActions, &utils.StringWithAPIOpts{ Arg: key, Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, @@ -1927,7 +1927,7 @@ func (dm *DataManager) GetActionPlan(key string, cacheRead, cacheWrite bool, tra ats, err = dm.dataDB.GetActionPlanDrv(key) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaActionPlans]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetActionPlan, &utils.StringWithAPIOpts{ Arg: key, Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, @@ -2010,7 +2010,7 @@ func (dm *DataManager) GetAllActionPlans() (ats map[string]*ActionPlan, err erro } ats, err = dm.dataDB.GetAllActionPlansDrv() if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaActionPlans]; ((err == nil && len(ats) == 0) || err == utils.ErrNotFound) && itm.Remote { - err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetAllActionPlans, &utils.StringWithAPIOpts{ Arg: utils.EmptyString, @@ -2063,7 +2063,7 @@ func (dm *DataManager) GetAccountActionPlans(acntID string, cacheRead, cacheWrit apIDs, err = dm.dataDB.GetAccountActionPlansDrv(acntID) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaAccountActionPlans]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetAccountActionPlans, &utils.StringWithAPIOpts{ Arg: acntID, @@ -2198,7 +2198,7 @@ func (dm *DataManager) GetRatingPlan(key string, skipCache bool, rp, err = dm.DataDB().GetRatingPlanDrv(key) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRatingPlans]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetRatingPlan, &utils.StringWithAPIOpts{ Arg: key, @@ -2290,7 +2290,7 @@ func (dm *DataManager) GetRatingProfile(key string, skipCache bool, rpf, err = dm.DataDB().GetRatingProfileDrv(key) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRatingProfiles]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetRatingProfile, &utils.StringWithAPIOpts{ Arg: key, @@ -2388,7 +2388,7 @@ func (dm *DataManager) GetRouteProfile(tenant, id string, cacheRead, cacheWrite rpp, err = dm.dataDB.GetRouteProfileDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRouteProfiles]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetRouteProfile, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetRouteProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID, utils.EmptyString, @@ -2521,7 +2521,7 @@ func (dm *DataManager) GetAttributeProfile(tenant, id string, cacheRead, cacheWr } else { if attrPrfl, err = dm.dataDB.GetAttributeProfileDrv(tenant, id); err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaAttributeProfiles]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, @@ -2659,7 +2659,7 @@ func (dm *DataManager) GetChargerProfile(tenant, id string, cacheRead, cacheWrit cpp, err = dm.dataDB.GetChargerProfileDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaChargerProfiles]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetChargerProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, @@ -2786,7 +2786,7 @@ func (dm *DataManager) GetDispatcherProfile(tenant, id string, cacheRead, cacheW dpp, err = dm.dataDB.GetDispatcherProfileDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaDispatcherProfiles]; err == utils.ErrDSPProfileNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetDispatcherProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, @@ -2919,7 +2919,7 @@ func (dm *DataManager) GetDispatcherHost(tenant, id string, cacheRead, cacheWrit dH, err = dm.dataDB.GetDispatcherHostDrv(tenant, id) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaDispatcherHosts]; err == utils.ErrDSPHostNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetDispatcherHost, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, @@ -3006,7 +3006,7 @@ func (dm *DataManager) GetItemLoadIDs(itemIDPrefix string, cacheWrite bool) (loa loadIDs, err = dm.DataDB().GetItemLoadIDsDrv(itemIDPrefix) if err != nil { if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaLoadIDs]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetItemLoadIDs, &utils.StringWithAPIOpts{ Arg: itemIDPrefix, @@ -3101,7 +3101,7 @@ func (dm *DataManager) GetIndexes(idxItmType, tntCtx, idxKey string, } if indexes, err = dm.DataDB().GetIndexesDrv(idxItmType, tntCtx, idxKey); err != nil { if itm := config.CgrConfig().DataDbCfg().Items[idxItmType]; err == utils.ErrNotFound && itm.Remote { - if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, + if err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetIndexes, &utils.GetIndexesArg{ IdxItmType: idxItmType, @@ -3245,7 +3245,7 @@ func (dm *DataManager) checkFilters(tenant string, ids []string) (err error) { // in case we can not find it localy try to find it in the remote DB if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaFilters]; err == utils.ErrNotFound && itm.Remote { var fltr *Filter - err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil, utils.ReplicatorSv1GetFilter, + err = dm.connMgr.Call(context.TODO(), config.CgrConfig().DataDbCfg().RmtConns, utils.ReplicatorSv1GetFilter, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: tenant, ID: id}, APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID, utils.EmptyString, diff --git a/engine/datamanager_test.go b/engine/datamanager_test.go index b5e0e111b..ff4b19679 100644 --- a/engine/datamanager_test.go +++ b/engine/datamanager_test.go @@ -24,6 +24,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/rpcclient" @@ -50,10 +52,10 @@ func TestDmGetDestinationRemote(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetDestination: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetDestination: func(ctx *context.Context, args, reply any) error { rpl := &Destination{ Id: "nat", Prefixes: []string{"0257", "0256", "0723"}, } @@ -63,7 +65,7 @@ func TestDmGetDestinationRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) exp := &Destination{ @@ -101,10 +103,10 @@ func TestDmGetAccountRemote(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetAccount: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetAccount: func(ctx *context.Context, args, reply any) error { rpl := &Account{ ID: "cgrates.org:exp", UpdateTime: time.Now(), @@ -115,7 +117,7 @@ func TestDmGetAccountRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) exp := &Account{ @@ -154,10 +156,10 @@ func TestDmGetFilterRemote(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetFilter: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetFilter: func(ctx *context.Context, args, reply any) error { rpl := &Filter{ Tenant: "cgrates.org", ID: "Filter1", @@ -179,7 +181,7 @@ func TestDmGetFilterRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) @@ -230,10 +232,10 @@ func TestDMGetThresholdRemote(t *testing.T) { Replicate: true, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetThreshold: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetThreshold: func(ctx *context.Context, args, reply any) error { rpl := &Threshold{ Tenant: "cgrates.org", ID: "THD_ACNT_1001", @@ -242,14 +244,14 @@ func TestDMGetThresholdRemote(t *testing.T) { *reply.(**Threshold) = rpl return nil }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't Replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -299,19 +301,19 @@ func TestDMGetThresholdRemoteErr(t *testing.T) { Replicate: true, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetThreshold: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetThreshold: func(ctx *context.Context, args, reply any) error { return utils.ErrNotFound }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't Replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -347,10 +349,10 @@ func TestDMGetThresholdProfileRemote(t *testing.T) { Replicate: true, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetThresholdProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetThresholdProfile: func(ctx *context.Context, args, reply any) error { rpl := &ThresholdProfile{ Tenant: "cgrates.org", ID: "ID", @@ -358,14 +360,14 @@ func TestDMGetThresholdProfileRemote(t *testing.T) { *reply.(**ThresholdProfile) = rpl return nil }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't Replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -409,19 +411,19 @@ func TestDMGetThresholdProfileRemoteErr(t *testing.T) { Replicate: true, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetThresholdProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetThresholdProfile: func(ctx *context.Context, args, reply any) error { return utils.ErrNotFound }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't Replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -461,10 +463,10 @@ func TestDMGetStatQueue(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetStatQueue: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetStatQueue: func(ctx *context.Context, args, reply any) error { rpl := &StatQueue{ Tenant: "cgrates.org", ID: "StatsID", @@ -478,7 +480,7 @@ func TestDMGetStatQueue(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -560,10 +562,10 @@ func TestDMSetAccount(t *testing.T) { DestinationIDs: utils.NewStringMap("RET"), Weight: 20}, }}, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetAccount: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetAccount: func(ctx *context.Context, args, reply any) error { accApiOpts, cancast := args.(AccountWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -575,7 +577,7 @@ func TestDMSetAccount(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -630,10 +632,10 @@ func TestDMRemoveAccount(t *testing.T) { t.Error(err) } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1RemoveAccount: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1RemoveAccount: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -644,7 +646,7 @@ func TestDMRemoveAccount(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -694,10 +696,10 @@ func TestDmSetFilter(t *testing.T) { }, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetFilter: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetFilter: func(ctx *context.Context, args, reply any) error { fltr, cancast := args.(FilterWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -708,7 +710,7 @@ func TestDmSetFilter(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -749,10 +751,10 @@ func TestDMSetThreshold(t *testing.T) { ID: "THD_ACNT_1001", Hits: 0, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetThreshold: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetThreshold: func(ctx *context.Context, args, reply any) error { thS, cancast := args.(ThresholdWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -763,7 +765,7 @@ func TestDMSetThreshold(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -805,10 +807,10 @@ func TestDmRemoveThreshold(t *testing.T) { ID: "THD_ACNT_1001", Hits: 0, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1RemoveThreshold: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1RemoveThreshold: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -819,7 +821,7 @@ func TestDmRemoveThreshold(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -854,10 +856,10 @@ func TestDMReverseDestinationRemote(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetReverseDestination: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetReverseDestination: func(ctx *context.Context, args, reply any) error { dest, cancast := args.(Destination) if !cancast { return utils.ErrNotConvertible @@ -868,7 +870,7 @@ func TestDMReverseDestinationRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -910,10 +912,10 @@ func TestDMStatQueueRemote(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetStatQueue: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetStatQueue: func(ctx *context.Context, args, reply any) error { sqApiOpts, cancast := args.(StatQueueWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -921,7 +923,7 @@ func TestDMStatQueueRemote(t *testing.T) { dm.dataDB.SetStatQueueDrv(nil, sqApiOpts.StatQueue) return nil }, - utils.ReplicatorSv1RemoveStatQueue: func(args, reply any) error { + utils.ReplicatorSv1RemoveStatQueue: func(ctx *context.Context, args, reply any) error { tntIDApiOpts, cancast := args.(utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -932,7 +934,7 @@ func TestDMStatQueueRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -984,10 +986,10 @@ func TestDmTimingR(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetTiming: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetTiming: func(ctx *context.Context, args, reply any) error { tpTimingApiOpts, cancast := args.(utils.TPTimingWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -995,7 +997,7 @@ func TestDmTimingR(t *testing.T) { dm.DataDB().SetTimingDrv(tpTimingApiOpts.TPTiming) return nil }, - utils.ReplicatorSv1RemoveTiming: func(args, reply any) error { + utils.ReplicatorSv1RemoveTiming: func(ctx *context.Context, args, reply any) error { id, cancast := args.(string) if !cancast { return utils.ErrNotConvertible @@ -1006,7 +1008,7 @@ func TestDmTimingR(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1054,10 +1056,10 @@ func TestDMSetActionTriggers(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetActionTriggers: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetActionTriggers: func(ctx *context.Context, args, reply any) error { setActTrgAOpts, cancast := args.(SetActionTriggersArgWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1065,7 +1067,7 @@ func TestDMSetActionTriggers(t *testing.T) { dm.DataDB().SetActionTriggersDrv(setActTrgAOpts.Key, setActTrgAOpts.Attrs) return nil }, - utils.ReplicatorSv1RemoveActionTriggers: func(args, reply any) error { + utils.ReplicatorSv1RemoveActionTriggers: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1076,7 +1078,7 @@ func TestDMSetActionTriggers(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1131,10 +1133,10 @@ func TestDMResourceProfileRemote(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetResourceProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetResourceProfile: func(ctx *context.Context, args, reply any) error { rscPrflApiOpts, cancast := args.(ResourceProfileWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1142,7 +1144,7 @@ func TestDMResourceProfileRemote(t *testing.T) { dm.DataDB().SetResourceProfileDrv(rscPrflApiOpts.ResourceProfile) return nil }, - utils.ReplicatorSv1SetResource: func(args, reply any) error { + utils.ReplicatorSv1SetResource: func(ctx *context.Context, args, reply any) error { rscApiOpts, cancast := args.(ResourceWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1150,7 +1152,7 @@ func TestDMResourceProfileRemote(t *testing.T) { dm.DataDB().SetResourceDrv(rscApiOpts.Resource) return nil }, - utils.ReplicatorSv1RemoveResourceProfile: func(args, reply any) error { + utils.ReplicatorSv1RemoveResourceProfile: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1161,7 +1163,7 @@ func TestDMResourceProfileRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1221,10 +1223,10 @@ func TestDmSharedGroup(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetSharedGroup: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetSharedGroup: func(ctx *context.Context, args, reply any) error { shGrpApiOpts, cancast := args.(SharedGroupWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1232,7 +1234,7 @@ func TestDmSharedGroup(t *testing.T) { dm.dataDB.SetSharedGroupDrv(shGrpApiOpts.SharedGroup) return nil }, - utils.ReplicatorSv1RemoveSharedGroup: func(args, reply any) error { + utils.ReplicatorSv1RemoveSharedGroup: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1243,7 +1245,7 @@ func TestDmSharedGroup(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1300,10 +1302,10 @@ func TestDMThresholdProfile(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetThresholdProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetThresholdProfile: func(ctx *context.Context, args, reply any) error { thPApiOpts, cancast := args.(ThresholdProfileWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1311,7 +1313,7 @@ func TestDMThresholdProfile(t *testing.T) { dm.DataDB().SetThresholdProfileDrv(thPApiOpts.ThresholdProfile) return nil }, - utils.ReplicatorSv1SetThreshold: func(args, reply any) error { + utils.ReplicatorSv1SetThreshold: func(ctx *context.Context, args, reply any) error { thApiOpts, cancast := args.(ThresholdWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1319,7 +1321,7 @@ func TestDMThresholdProfile(t *testing.T) { dm.DataDB().SetThresholdDrv(thApiOpts.Threshold) return nil }, - utils.ReplicatorSv1RemoveThresholdProfile: func(args, reply any) error { + utils.ReplicatorSv1RemoveThresholdProfile: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1330,7 +1332,7 @@ func TestDMThresholdProfile(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1380,15 +1382,15 @@ func TestDMRemoveThresholdProfileErr(t *testing.T) { } cfg.DataDbCfg().RmtConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetThresholdProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetThresholdProfile: func(ctx *context.Context, args, reply any) error { return fmt.Errorf("Can't Replicate") }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1439,10 +1441,10 @@ func TestDmDispatcherHost(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetDispatcherHost: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetDispatcherHost: func(ctx *context.Context, args, reply any) error { dspApiOpts, cancast := args.(DispatcherHostWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1450,7 +1452,7 @@ func TestDmDispatcherHost(t *testing.T) { dm.DataDB().SetDispatcherHostDrv(dspApiOpts.DispatcherHost) return nil }, - utils.ReplicatorSv1RemoveDispatcherHost: func(args, reply any) error { + utils.ReplicatorSv1RemoveDispatcherHost: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1461,7 +1463,7 @@ func TestDmDispatcherHost(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1512,19 +1514,19 @@ func TestGetDispatcherHostErr(t *testing.T) { Replicate: true, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetDispatcherHost: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetDispatcherHost: func(ctx *context.Context, args, reply any) error { return utils.ErrDSPHostNotFound }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't Replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -1572,10 +1574,10 @@ func TestChargerProfileRemote(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetDispatcherHost: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetDispatcherHost: func(ctx *context.Context, args, reply any) error { chrgPrflApiOpts, cancast := args.(ChargerProfileWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1583,7 +1585,7 @@ func TestChargerProfileRemote(t *testing.T) { dm.DataDB().SetChargerProfileDrv(chrgPrflApiOpts.ChargerProfile) return nil }, - utils.ReplicatorSv1RemoveChargerProfile: func(args, reply any) error { + utils.ReplicatorSv1RemoveChargerProfile: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1594,7 +1596,7 @@ func TestChargerProfileRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1647,10 +1649,10 @@ func TestDispatcherProfileRemote(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetDispatcherProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetDispatcherProfile: func(ctx *context.Context, args, reply any) error { dspApiOpts, cancast := args.(DispatcherProfileWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1658,7 +1660,7 @@ func TestDispatcherProfileRemote(t *testing.T) { dm.DataDB().SetDispatcherProfileDrv(dspApiOpts.DispatcherProfile) return nil }, - utils.ReplicatorSv1RemoveDispatcherProfile: func(args, reply any) error { + utils.ReplicatorSv1RemoveDispatcherProfile: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1669,7 +1671,7 @@ func TestDispatcherProfileRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1719,10 +1721,10 @@ func TestRouteProfileRemote(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetRouteProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetRouteProfile: func(ctx *context.Context, args, reply any) error { routeApiOpts, cancast := args.(RouteProfileWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1730,7 +1732,7 @@ func TestRouteProfileRemote(t *testing.T) { dm.DataDB().SetRouteProfileDrv(routeApiOpts.RouteProfile) return nil }, - utils.ReplicatorSv1RemoveRouteProfile: func(args, reply any) error { + utils.ReplicatorSv1RemoveRouteProfile: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1741,7 +1743,7 @@ func TestRouteProfileRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1788,10 +1790,10 @@ func TestRatingPlanRemote(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetRatingPlan: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetRatingPlan: func(ctx *context.Context, args, reply any) error { rPnApiOpts, cancast := args.(RatingPlanWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1799,7 +1801,7 @@ func TestRatingPlanRemote(t *testing.T) { dm.DataDB().SetRatingPlanDrv(rPnApiOpts.RatingPlan) return nil }, - utils.ReplicatorSv1RemoveRatingPlan: func(args, reply any) error { + utils.ReplicatorSv1RemoveRatingPlan: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1810,7 +1812,7 @@ func TestRatingPlanRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -1879,10 +1881,10 @@ func TestGetResourceRemote(t *testing.T) { }, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetResource: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetResource: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(*utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1891,13 +1893,13 @@ func TestGetResourceRemote(t *testing.T) { *reply.(**Resource) = rS return nil }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't Replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -1948,10 +1950,10 @@ func TestGetResourceProfileRemote(t *testing.T) { Weight: 20, ThresholdIDs: []string{"Val1"}, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetResourceProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetResourceProfile: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(*utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -1963,7 +1965,7 @@ func TestGetResourceProfileRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2004,10 +2006,10 @@ func TestGetActionTriggers(t *testing.T) { ID: "Test", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetActionTriggers: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetActionTriggers: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(*utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2016,14 +2018,14 @@ func TestGetActionTriggers(t *testing.T) { *reply.(*ActionTriggers) = aT return nil }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't Replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -2072,19 +2074,19 @@ func TestGetActionTriggersErr(t *testing.T) { ID: "Test", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetActionTriggers: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetActionTriggers: func(ctx *context.Context, args, reply any) error { return utils.ErrNotFound }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't Replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr1 := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr1 := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -2146,10 +2148,10 @@ func TestGetSharedGroupRemote(t *testing.T) { "string2": false, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetSharedGroup: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetSharedGroup: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(*utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2161,7 +2163,7 @@ func TestGetSharedGroupRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2201,10 +2203,10 @@ func TestGetStatQueueProfileRemote(t *testing.T) { FilterIDs: []string{"FLTR_ID"}, Weight: 10, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetStatQueueProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetStatQueueProfile: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(*utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2216,7 +2218,7 @@ func TestGetStatQueueProfileRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2264,10 +2266,10 @@ func TestStatQueueProfileRemote(t *testing.T) { FilterIDs: []string{"FLTR_ID"}, Weight: 10, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetStatQueueProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetStatQueueProfile: func(ctx *context.Context, args, reply any) error { sqPApiOpts, cancast := args.(StatQueueProfileWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2275,7 +2277,7 @@ func TestStatQueueProfileRemote(t *testing.T) { dm.DataDB().SetStatQueueProfileDrv(sqPApiOpts.StatQueueProfile) return nil }, - utils.ReplicatorSv1SetStatQueue: func(args, reply any) error { + utils.ReplicatorSv1SetStatQueue: func(ctx *context.Context, args, reply any) error { sqApiOpts, cancast := args.(StatQueueWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2286,7 +2288,7 @@ func TestStatQueueProfileRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2322,10 +2324,10 @@ func TestDMActionsRemote(t *testing.T) { Remote: true, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetActions: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetActions: func(ctx *context.Context, args, reply any) error { sArgApiOpts, cancast := args.(SetActionsArgsWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2333,7 +2335,7 @@ func TestDMActionsRemote(t *testing.T) { dm.DataDB().SetActionsDrv(sArgApiOpts.Key, sArgApiOpts.Acs) return nil }, - utils.ReplicatorSv1GetActions: func(args, reply any) error { + utils.ReplicatorSv1GetActions: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2341,7 +2343,7 @@ func TestDMActionsRemote(t *testing.T) { dm.DataDB().GetActionsDrv(strApiOpts.Arg) return nil }, - utils.ReplicatorSv1RemoveActions: func(args, reply any) error { + utils.ReplicatorSv1RemoveActions: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2355,7 +2357,7 @@ func TestDMActionsRemote(t *testing.T) { ActionType: utils.MetaTopUp, ExpirationString: utils.MetaUnlimited}} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2408,10 +2410,10 @@ func TestGetDispatcherHost(t *testing.T) { Transport: utils.MetaJSON, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetDispatcherHost: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetDispatcherHost: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(*utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2423,7 +2425,7 @@ func TestGetDispatcherHost(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2463,10 +2465,10 @@ func TestGetReverseDestinationRemote(t *testing.T) { }, } ids := []string{"dest1", "dest2"} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetReverseDestination: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetReverseDestination: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(*utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2478,7 +2480,7 @@ func TestGetReverseDestinationRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2490,15 +2492,15 @@ func TestGetReverseDestinationRemote(t *testing.T) { t.Errorf("expected %v,received %v", utils.ToJSON(ids), utils.ToJSON(val)) } Cache = NewCacheS(cfg, dm, nil) - clientConn2 := make(chan rpcclient.ClientConnector, 1) + clientConn2 := make(chan birpc.ClientConnector, 1) clientConn2 <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReplicateSet: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't replicate") }, }, } - connMgr2 := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr2 := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn2, }) SetConnManager(connMgr2) @@ -2541,10 +2543,10 @@ func TestDMRemoveDestination(t *testing.T) { dest := &Destination{ Id: "nat", Prefixes: []string{"0257", "0256", "0723"}, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1RemoveDestination: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1RemoveDestination: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2552,7 +2554,7 @@ func TestDMRemoveDestination(t *testing.T) { dm.DataDB().RemoveDestinationDrv(strApiOpts.Arg, utils.NonTransactional) return nil }, - utils.ReplicatorSv1GetReverseDestination: func(args, reply any) error { + utils.ReplicatorSv1GetReverseDestination: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2563,7 +2565,7 @@ func TestDMRemoveDestination(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2577,15 +2579,15 @@ func TestDMRemoveDestination(t *testing.T) { t.Error(err) } Cache = NewCacheS(cfg, dm, nil) - clientConn2 := make(chan rpcclient.ClientConnector, 1) + clientConn2 := make(chan birpc.ClientConnector, 1) clientConn2 <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReplicateRemove: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReplicateRemove: func(ctx *context.Context, args, reply any) error { return errors.New("Can't replicate") }, }, } - connMgr2 := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr2 := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn2, }) SetConnManager(connMgr2) @@ -2622,10 +2624,10 @@ func TestDMRemoveFilter(t *testing.T) { Remote: true, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1RemoveFilter: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1RemoveFilter: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2633,13 +2635,13 @@ func TestDMRemoveFilter(t *testing.T) { dm.dataDB.RemoveFilterDrv(tntApiOpts.TenantID.Tenant, tntApiOpts.TenantID.ID) return nil }, - utils.ReplicatorSv1GetIndexes: func(args, reply any) error { + utils.ReplicatorSv1GetIndexes: func(ctx *context.Context, args, reply any) error { return nil }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2712,10 +2714,10 @@ func TestRemoveStatQueueProfile(t *testing.T) { FilterIDs: []string{"FLTR_ST_Resource1", "*string:~*req.Account:1001"}, Weight: 50, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1RemoveStatQueueProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1RemoveStatQueueProfile: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2723,14 +2725,14 @@ func TestRemoveStatQueueProfile(t *testing.T) { dm.DataDB().RemStatQueueProfileDrv(tntApiOpts.Tenant, tntApiOpts.ID) return nil }, - utils.ReplicatorSv1GetIndexes: func(args, reply any) error { + utils.ReplicatorSv1GetIndexes: func(ctx *context.Context, args, reply any) error { return errors.New("Can't replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2788,10 +2790,10 @@ func TestDMGetTimingRemote(t *testing.T) { EndTime: "00:00:01", } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetTiming: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetTiming: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(*utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2803,7 +2805,7 @@ func TestDMGetTimingRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2813,15 +2815,15 @@ func TestDMGetTimingRemote(t *testing.T) { t.Error(err) } Cache = NewCacheS(cfg, dm, nil) - clientConn2 := make(chan rpcclient.ClientConnector, 1) + clientConn2 := make(chan birpc.ClientConnector, 1) clientConn2 <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReplicateSet: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't replicate") }, }, } - connMgr2 := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn2}) + connMgr2 := NewConnManager(cfg, map[string]chan birpc.ClientConnector{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn2}) SetConnManager(connMgr2) if _, err := dm.GetTiming(tp.ID, true, utils.NonTransactional); err == nil || err.Error() != "Can't replicate" { t.Error(err) @@ -2861,10 +2863,10 @@ func TestDmGetActions(t *testing.T) { ActionType: utils.MetaTopUpReset, ExpirationString: utils.MetaUnlimited}, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetActions: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetActions: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(*utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2876,7 +2878,7 @@ func TestDmGetActions(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2909,10 +2911,10 @@ func TestDMSetLoadIDs(t *testing.T) { RouteID: "route", }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetLoadIDs: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetLoadIDs: func(ctx *context.Context, args, reply any) error { ldApiOpts, cancast := args.(*utils.LoadIDsWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2923,7 +2925,7 @@ func TestDMSetLoadIDs(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -2974,10 +2976,10 @@ func TestGetItemLoadIDsRemote(t *testing.T) { "load1": 23, "load2": 22, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetItemLoadIDs: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetItemLoadIDs: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(*utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -2989,7 +2991,7 @@ func TestGetItemLoadIDsRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -3007,13 +3009,13 @@ func TestGetItemLoadIDsRemote(t *testing.T) { } Cache = NewCacheS(cfg, dm, nil) - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReplicateSet: func(args, reply any) error { return errors.New("Can't replicate") }, + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't replicate") }, }, } - connMgr2 := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr2 := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientconn, }) SetConnManager(connMgr2) @@ -3049,18 +3051,18 @@ func TestDMItemLoadIDsRemoteErr(t *testing.T) { "load1": 23, "load2": 22, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetItemLoadIDs: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetItemLoadIDs: func(ctx *context.Context, args, reply any) error { *reply.(*map[string]int64) = ld return utils.ErrNotFound }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { return errors.New("Can't replicate") }, + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) @@ -3118,10 +3120,10 @@ func TestActionPlanRemote(t *testing.T) { }, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetActionPlan: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetActionPlan: func(ctx *context.Context, args, reply any) error { setActPlnOpts, cancast := args.(*SetActionPlanArgWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -3129,7 +3131,7 @@ func TestActionPlanRemote(t *testing.T) { dm.dataDB.SetActionPlanDrv(setActPlnOpts.Key, setActPlnOpts.Ats) return nil }, - utils.ReplicatorSv1RemoveActionPlan: func(args, reply any) error { + utils.ReplicatorSv1RemoveActionPlan: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(*utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -3137,7 +3139,7 @@ func TestActionPlanRemote(t *testing.T) { dm.DataDB().RemoveActionPlanDrv(strApiOpts.Arg) return nil }, - utils.ReplicatorSv1GetAllActionPlans: func(args, reply any) error { + utils.ReplicatorSv1GetAllActionPlans: func(ctx *context.Context, args, reply any) error { *reply.(*map[string]*ActionPlan) = map[string]*ActionPlan{ "act_key": actPln, @@ -3147,7 +3149,7 @@ func TestActionPlanRemote(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -3193,10 +3195,10 @@ func TestAccountActionPlansRemote(t *testing.T) { }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetAccountActionPlans: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetAccountActionPlans: func(ctx *context.Context, args, reply any) error { setActPlnOpts, cancast := args.(*SetActionPlanArgWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -3204,14 +3206,14 @@ func TestAccountActionPlansRemote(t *testing.T) { dm.dataDB.SetActionPlanDrv(setActPlnOpts.Key, setActPlnOpts.Ats) return nil }, - utils.ReplicatorSv1RemAccountActionPlans: func(args, reply any) error { + utils.ReplicatorSv1RemAccountActionPlans: func(ctx *context.Context, args, reply any) error { return nil }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -3476,10 +3478,10 @@ func TestDMRatingProfile(t *testing.T) { }}, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetRatingProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetRatingProfile: func(ctx *context.Context, args, reply any) error { rtPrfApiOpts, cancast := args.(*RatingProfileWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -3487,7 +3489,7 @@ func TestDMRatingProfile(t *testing.T) { dm.dataDB.SetRatingProfileDrv(rtPrfApiOpts.RatingProfile) return nil }, - utils.ReplicatorSv1RemoveRatingProfile: func(args, reply any) error { + utils.ReplicatorSv1RemoveRatingProfile: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(*utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -3495,7 +3497,7 @@ func TestDMRatingProfile(t *testing.T) { dm.DataDB().RemoveRatingProfileDrv(strApiOpts.Arg) return nil }, - utils.ReplicatorSv1GetRatingProfile: func(args, reply any) error { + utils.ReplicatorSv1GetRatingProfile: func(ctx *context.Context, args, reply any) error { strApiOpts, cancast := args.(*utils.StringWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -3507,7 +3509,7 @@ func TestDMRatingProfile(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -3628,21 +3630,21 @@ func TestDMGetRatingPlan(t *testing.T) { Ratings: map[string]*RIRate{"Ratings": {ConnectFee: 0.7}}, Timings: map[string]*RITiming{"Timings": {Months: utils.Months{4}}}, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetRatingPlan: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetRatingPlan: func(ctx *context.Context, args, reply any) error { *reply.(**RatingPlan) = rpL return nil }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't replicate ") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -3691,21 +3693,21 @@ func TestDMChargerProfile(t *testing.T) { AttributeIDs: []string{"ATTR_1"}, Weight: 20, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetChargerProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetChargerProfile: func(ctx *context.Context, args, reply any) error { *reply.(**ChargerProfile) = chP return nil }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't replicate ") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -3763,21 +3765,21 @@ func TestDMDispatcherProfile(t *testing.T) { }, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetDispatcherProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetDispatcherProfile: func(ctx *context.Context, args, reply any) error { *reply.(**DispatcherProfile) = dPP return nil }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't replicate ") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -4121,18 +4123,18 @@ func TestCacheDataFromDBErr(t *testing.T) { cfg.CacheCfg().Partitions[utils.CacheThresholdProfiles].Replicate = true cfg.CacheCfg().ReplicationConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetThresholdProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetThresholdProfile: func(ctx *context.Context, args, reply any) error { return errors.New("Another Error") }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return fmt.Errorf("New Error") }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -4189,20 +4191,20 @@ func TestDMGetRouteProfile(t *testing.T) { }, Weight: 10, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetRouteProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetRouteProfile: func(ctx *context.Context, args, reply any) error { *reply.(**RouteProfile) = rpL return nil }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't Replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -4242,19 +4244,19 @@ func TestDMGetRouteProfileErr(t *testing.T) { Replicate: true, }, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetRouteProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetRouteProfile: func(ctx *context.Context, args, reply any) error { return utils.ErrNotFound }, - utils.CacheSv1ReplicateSet: func(args, reply any) error { + utils.CacheSv1ReplicateSet: func(ctx *context.Context, args, reply any) error { return errors.New("Can't Replicate") }, }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientConn, }) @@ -4407,14 +4409,14 @@ func TestDMAttributeProfile(t *testing.T) { }, Weight: 20.0, } - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetAttributeProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetAttributeProfile: func(ctx *context.Context, args, reply any) error { *reply.(**AttributeProfile) = attrPrf return nil }, - utils.ReplicatorSv1SetAttributeProfile: func(args, reply any) error { + utils.ReplicatorSv1SetAttributeProfile: func(ctx *context.Context, args, reply any) error { attrPrfApiOpts, cancast := args.(*AttributeProfileWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -4422,7 +4424,7 @@ func TestDMAttributeProfile(t *testing.T) { dm.DataDB().SetAttributeProfileDrv(attrPrfApiOpts.AttributeProfile) return nil }, - utils.ReplicatorSv1RemoveAttributeProfile: func(args, reply any) error { + utils.ReplicatorSv1RemoveAttributeProfile: func(ctx *context.Context, args, reply any) error { tntApiOpts, cancast := args.(*utils.TenantIDWithAPIOpts) if !cancast { return utils.ErrNotConvertible @@ -4433,7 +4435,7 @@ func TestDMAttributeProfile(t *testing.T) { }, } db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -4584,10 +4586,10 @@ func TestDmIndexes(t *testing.T) { }, } cfg.DataDbCfg().RplConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetIndexes: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetIndexes: func(ctx *context.Context, args, reply any) error { setcastIndxArg, cancast := args.(*utils.SetIndexesArg) if !cancast { return utils.ErrNotConvertible @@ -4595,7 +4597,7 @@ func TestDmIndexes(t *testing.T) { dm.DataDB().SetIndexesDrv(setcastIndxArg.IdxItmType, setcastIndxArg.TntCtx, setcastIndxArg.Indexes, true, utils.NonTransactional) return nil }, - utils.ReplicatorSv1RemoveIndexes: func(args, reply any) error { + utils.ReplicatorSv1RemoveIndexes: func(ctx *context.Context, args, reply any) error { gIdxArg, cancast := args.(*utils.GetIndexesArg) if !cancast { return utils.ErrNotConvertible @@ -4605,7 +4607,7 @@ func TestDmIndexes(t *testing.T) { }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -4644,10 +4646,10 @@ func TestDmCheckFilters(t *testing.T) { }, } cfg.DataDbCfg().RmtConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetFilter: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetFilter: func(ctx *context.Context, args, reply any) error { fltr := &Filter{ ID: "FLTR_1", Tenant: "cgrates.org", @@ -4664,7 +4666,7 @@ func TestDmCheckFilters(t *testing.T) { }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -4686,15 +4688,15 @@ func TestRemoveFilterIndexes(t *testing.T) { }, } cfg.DataDbCfg().RmtConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetIndexes: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetIndexes: func(ctx *context.Context, args, reply any) error { return utils.ErrNotImplemented }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -4741,15 +4743,15 @@ func TestGetDispatcherProfileErr(t *testing.T) { } cfg.DataDbCfg().RmtConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1GetDispatcherProfile: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1GetDispatcherProfile: func(ctx *context.Context, args, reply any) error { return utils.ErrDSPProfileNotFound }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): clientConn, }) dm := NewDataManager(db, cfg.CacheCfg(), connMgr) @@ -4890,7 +4892,7 @@ func TestDmCheckFiltersRmt(t *testing.T) { cfg.DataDbCfg().Items[utils.MetaFilters].Remote = true cfg.DataDbCfg().RmtConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- clMock(func(serviceMethod string, _, _ any) error { if serviceMethod == utils.ReplicatorSv1GetFilter { @@ -4898,7 +4900,7 @@ func TestDmCheckFiltersRmt(t *testing.T) { } return utils.ErrNotFound }) - dm := NewDataManager(db, cfg.CacheCfg(), NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + dm := NewDataManager(db, cfg.CacheCfg(), NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicatorSv1): clientConn, })) dm.SetFilter(&Filter{ diff --git a/engine/destinations_test.go b/engine/destinations_test.go index 005f0467b..36e2404ee 100644 --- a/engine/destinations_test.go +++ b/engine/destinations_test.go @@ -5,9 +5,10 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" "github.com/nyaruka/phonenumbers" ) @@ -191,16 +192,16 @@ func TestDMSetDestinationSucces(t *testing.T) { cfg.DataDbCfg().RplCache = "cache" db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetDestination: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetDestination: func(ctx *context.Context, args, reply any) error { *reply.(*string) = "reply" return nil }, }, } - connMngr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicationConnsCfg): clientConn, }) @@ -227,16 +228,16 @@ func TestDMSetAccountSucces(t *testing.T) { Replicate: true, }, }*/ - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetAccount: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetAccount: func(ctx *context.Context, args, reply any) error { *reply.(*string) = "reply" return nil }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicationConnsCfg): clientConn, }) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -271,16 +272,16 @@ func TestDMSetReverseDestination(t *testing.T) { cfg := config.NewDefaultCGRConfig() db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ReplicatorSv1SetReverseDestination: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ReplicatorSv1SetReverseDestination: func(ctx *context.Context, args, reply any) error { *reply.(*string) = "reply" return nil }, }, } - connMngr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.ReplicationConnsCfg): clientConn, }) diff --git a/engine/dispatcherprfl.go b/engine/dispatcherprfl.go index bf55cb959..d9bb9a261 100644 --- a/engine/dispatcherprfl.go +++ b/engine/dispatcherprfl.go @@ -22,9 +22,10 @@ import ( "math/rand" "sort" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) type DispatcherHostProfile struct { @@ -133,7 +134,7 @@ func (dps DispatcherProfiles) Sort() { type DispatcherHost struct { Tenant string *config.RemoteHost - rpcConn rpcclient.ClientConnector + rpcConn birpc.ClientConnector } // DispatcherHostWithOpts is used in replicatorV1 for dispatcher @@ -148,21 +149,26 @@ func (dH *DispatcherHost) TenantID() string { } // Call will build and cache the connection if it is not defined yet then will execute the method on conn -func (dH *DispatcherHost) Call(serviceMethod string, args any, reply any) (err error) { +func (dH *DispatcherHost) Call(ctx *context.Context, serviceMethod string, args any, reply any) (err error) { if dH.rpcConn == nil { // connect the rpcConn cfg := config.CgrConfig() - if dH.rpcConn, err = NewRPCConnection(dH.RemoteHost, + if dH.rpcConn, err = NewRPCConnection(ctx, + dH.RemoteHost, cfg.TLSCfg().ClientKey, - cfg.TLSCfg().ClientCerificate, cfg.TLSCfg().CaCertificate, - cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects, - cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout, - IntRPC.GetInternalChanel(), false, nil, + cfg.TLSCfg().ClientCerificate, + cfg.TLSCfg().CaCertificate, + cfg.GeneralCfg().ConnectAttempts, + cfg.GeneralCfg().Reconnects, + cfg.GeneralCfg().MaxReconnectInterval, + cfg.GeneralCfg().ConnectTimeout, + cfg.GeneralCfg().ReplyTimeout, + IntRPC.GetInternalChanel(), false, utils.EmptyString, utils.EmptyString, nil); err != nil { return } } - return dH.rpcConn.Call(serviceMethod, args, reply) + return dH.rpcConn.Call(ctx, serviceMethod, args, reply) } type DispatcherHostIDs []string diff --git a/engine/dispatcherprfl_test.go b/engine/dispatcherprfl_test.go index 238a98d38..497e149e5 100644 --- a/engine/dispatcherprfl_test.go +++ b/engine/dispatcherprfl_test.go @@ -21,6 +21,7 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -230,7 +231,7 @@ type testRPCHost struct { reply any } -func (v *testRPCHost) Call(serviceMethod string, args any, reply any) error { +func (v *testRPCHost) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { v.serviceMethod = serviceMethod v.args = args v.reply = reply @@ -247,7 +248,7 @@ func TestDispatcherHostCall(t *testing.T) { } var reply string dspHost.rpcConn = tRPC - if err := dspHost.Call(utils.AttributeSv1Ping, &utils.CGREvent{}, &reply); err != nil { + if err := dspHost.Call(context.Background(), utils.AttributeSv1Ping, &utils.CGREvent{}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(*etRPC, *tRPC) { t.Errorf("Expected: %s , received: %s", utils.ToJSON(etRPC), utils.ToJSON(tRPC)) @@ -334,7 +335,7 @@ func TestDispatcherHostCallErr(t *testing.T) { }, } var reply string - if err := dH.Call(utils.AttributeSv1Ping, &utils.CGREvent{}, &reply); err == nil || err.Error() != "dial tcp: missing address" { + if err := dH.Call(context.Background(), utils.AttributeSv1Ping, &utils.CGREvent{}, &reply); err == nil || err.Error() != "dial tcp: missing address" { t.Error(err) } } diff --git a/engine/dynamicdp.go b/engine/dynamicdp.go index 6b49854bf..2ce3947c6 100644 --- a/engine/dynamicdp.go +++ b/engine/dynamicdp.go @@ -23,6 +23,7 @@ import ( "github.com/nyaruka/phonenumbers" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -91,7 +92,7 @@ func (dDP *dynamicDP) fieldAsInterface(fldPath []string) (val any, err error) { // fieldNameType (~*accounts), accountID(1001) and queried part (BalanceMap.*monetary[0].Value) var account Account - if err = connMgr.Call(dDP.apiConns, nil, utils.APIerSv2GetAccount, + if err = connMgr.Call(context.TODO(), dDP.apiConns, utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: dDP.tenant, Account: fldPath[1]}, &account); err != nil { return } @@ -101,7 +102,7 @@ func (dDP *dynamicDP) fieldAsInterface(fldPath []string) (val any, err error) { case utils.MetaResources: // sample of fieldName : ~*resources.ResourceID.Field var reply ResourceWithConfig - if err := connMgr.Call(dDP.resConns, nil, utils.ResourceSv1GetResourceWithConfig, + if err := connMgr.Call(context.TODO(), dDP.resConns, utils.ResourceSv1GetResourceWithConfig, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: dDP.tenant, ID: fldPath[1]}}, &reply); err != nil { return nil, err } @@ -112,7 +113,7 @@ func (dDP *dynamicDP) fieldAsInterface(fldPath []string) (val any, err error) { // sample of fieldName : ~*stats.StatID.*acd var statValues map[string]float64 - if err := connMgr.Call(dDP.stsConns, nil, utils.StatSv1GetQueueFloatMetrics, + if err := connMgr.Call(context.TODO(), dDP.stsConns, utils.StatSv1GetQueueFloatMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: dDP.tenant, ID: fldPath[1]}}, &statValues); err != nil { return nil, err diff --git a/engine/dynamicdp_test.go b/engine/dynamicdp_test.go index 792ce6eff..1ecbc9ef4 100644 --- a/engine/dynamicdp_test.go +++ b/engine/dynamicdp_test.go @@ -25,9 +25,10 @@ import ( "strings" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" "github.com/nyaruka/phonenumbers" ) @@ -35,10 +36,10 @@ func TestDynamicDpFieldAsInterface(t *testing.T) { cfg := config.NewDefaultCGRConfig() ms := utils.MapStorage{} dDp := newDynamicDP([]string{}, []string{utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg)}, []string{}, "cgrates.org", ms) - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.StatSv1GetQueueFloatMetrics: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.StatSv1GetQueueFloatMetrics: func(ctx *context.Context, args, reply any) error { rpl := &map[string]float64{ "stat1": 31, } @@ -47,7 +48,7 @@ func TestDynamicDpFieldAsInterface(t *testing.T) { }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg): clientconn, }) SetConnManager(connMgr) diff --git a/engine/filters.go b/engine/filters.go index 72978cf85..3783b1582 100644 --- a/engine/filters.go +++ b/engine/filters.go @@ -26,6 +26,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -494,7 +495,9 @@ func (fltr *FilterRule) passTimings(dDP utils.DataProvider) (bool, error) { return false, err } var tm utils.TPTiming - if err = connMgr.Call(config.CgrConfig().FilterSCfg().ApierSConns, nil, utils.APIerSv1GetTiming, &utils.ArgsGetTimingID{ID: valTmID}, &tm); err != nil { + if err = connMgr.Call(context.TODO(), config.CgrConfig().FilterSCfg().ApierSConns, + utils.APIerSv1GetTiming, + &utils.ArgsGetTimingID{ID: valTmID}, &tm); err != nil { continue } ritm := &RITiming{ @@ -523,7 +526,9 @@ func (fltr *FilterRule) passDestinations(dDP utils.DataProvider) (bool, error) { } for _, p := range utils.SplitPrefix(dst, MIN_PREFIX_MATCH) { var destIDs []string - if err = connMgr.Call(config.CgrConfig().FilterSCfg().ApierSConns, nil, utils.APIerSv1GetReverseDestination, &p, &destIDs); err != nil { + if err = connMgr.Call(context.TODO(), config.CgrConfig().FilterSCfg().ApierSConns, + utils.APIerSv1GetReverseDestination, + &p, &destIDs); err != nil { continue } for _, dID := range destIDs { diff --git a/engine/filters_test.go b/engine/filters_test.go index d06db2a34..371f86c5e 100644 --- a/engine/filters_test.go +++ b/engine/filters_test.go @@ -28,9 +28,10 @@ import ( "time" "github.com/cgrates/baningo" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestFilterPassString(t *testing.T) { @@ -1952,10 +1953,10 @@ func TestFiltersPassTimingsCallSuccessful(t *testing.T) { config.SetCgrConfig(cfg) Cache.Clear(nil) - client := make(chan rpcclient.ClientConnector, 1) + client := make(chan birpc.ClientConnector, 1) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.APIerSv1GetTiming: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.APIerSv1GetTiming: func(ctx *context.Context, args, reply any) error { exp := &utils.TPTiming{ ID: "MIDNIGHT", Years: utils.Years{2020, 2018}, @@ -1972,7 +1973,7 @@ func TestFiltersPassTimingsCallSuccessful(t *testing.T) { } client <- ccM - NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier): client, }) @@ -2091,10 +2092,10 @@ func TestFiltersPassDestinationsCallSuccessSameDest(t *testing.T) { config.SetCgrConfig(cfg) Cache.Clear(nil) - client := make(chan rpcclient.ClientConnector, 1) + client := make(chan birpc.ClientConnector, 1) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.APIerSv1GetReverseDestination: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.APIerSv1GetReverseDestination: func(ctx *context.Context, args, reply any) error { rply := []string{"1002"} *reply.(*[]string) = rply return nil @@ -2103,7 +2104,7 @@ func TestFiltersPassDestinationsCallSuccessSameDest(t *testing.T) { } client <- ccM - NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier): client, }) @@ -2140,10 +2141,10 @@ func TestFiltersPassDestinationsCallSuccessParseErr(t *testing.T) { config.SetCgrConfig(cfg) Cache.Clear(nil) - client := make(chan rpcclient.ClientConnector, 1) + client := make(chan birpc.ClientConnector, 1) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.APIerSv1GetReverseDestination: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.APIerSv1GetReverseDestination: func(ctx *context.Context, args, reply any) error { rply := []string{"1002"} *reply.(*[]string) = rply return nil @@ -2152,7 +2153,7 @@ func TestFiltersPassDestinationsCallSuccessParseErr(t *testing.T) { } client <- ccM - NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier): client, }) @@ -2291,8 +2292,8 @@ func TestFilterGreaterThanOnObjectDP(t *testing.T) { cfg.FilterSCfg().ResourceSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} dm := NewDataManager(NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items), cfg.CacheCfg(), nil) mockConn := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResourceSv1GetResourceWithConfig: func(args any, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResourceSv1GetResourceWithConfig: func(ctx *context.Context, args any, reply any) error { *(reply.(*ResourceWithConfig)) = ResourceWithConfig{ Resource: &Resource{}, } @@ -2300,9 +2301,9 @@ func TestFilterGreaterThanOnObjectDP(t *testing.T) { }, }, } - mockChan := make(chan rpcclient.ClientConnector, 1) + mockChan := make(chan birpc.ClientConnector, 1) mockChan <- mockConn - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): mockChan, }) flts := NewFilterS(cfg, connMgr, dm) @@ -2600,10 +2601,10 @@ func TestFilterPassTiming(t *testing.T) { config.SetCgrConfig(cfg) Cache.Clear(nil) - client := make(chan rpcclient.ClientConnector, 1) + client := make(chan birpc.ClientConnector, 1) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.APIerSv1GetTiming: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.APIerSv1GetTiming: func(ctx *context.Context, args, reply any) error { exp := &utils.TPTiming{ ID: "MIDNIGHT", Years: utils.Years{2023}, @@ -2620,7 +2621,7 @@ func TestFilterPassTiming(t *testing.T) { } client <- ccM - NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier): client, }) diff --git a/engine/lib_test.go b/engine/lib_test.go index 30dbcdfd9..dbd8c4895 100644 --- a/engine/lib_test.go +++ b/engine/lib_test.go @@ -21,9 +21,9 @@ package engine import ( "errors" "flag" - "net/rpc" - "net/rpc/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -35,12 +35,12 @@ var ( dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/engine/libengine.go b/engine/libengine.go index 8cb9fa8e2..925b1af8c 100644 --- a/engine/libengine.go +++ b/engine/libengine.go @@ -19,10 +19,15 @@ along with this program. If not, see package engine import ( + "errors" "fmt" + "reflect" "strings" "time" + "unicode" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" @@ -30,12 +35,12 @@ import ( ) // NewRPCPool returns a new pool of connection with the given configuration -func NewRPCPool(dispatchStrategy string, keyPath, certPath, caPath string, connAttempts, reconnects int, - connectTimeout, replyTimeout time.Duration, rpcConnCfgs []*config.RemoteHost, - internalConnChan chan rpcclient.ClientConnector, lazyConnect bool, - biRPCClient rpcclient.BiRPCConector, poolID string, connCache *ltcache.Cache) (rpcPool *rpcclient.RPCPool, err error) { - var rpcClient rpcclient.ClientConnector - var atLestOneConnected bool // If one connected we don't longer return errors +func NewRPCPool(ctx *context.Context, dispatchStrategy string, keyPath, certPath, caPath string, connAttempts, reconnects int, + maxReconnectInterval, connectTimeout, replyTimeout time.Duration, rpcConnCfgs []*config.RemoteHost, + internalConnChan chan birpc.ClientConnector, lazyConnect bool, + poolID string, connCache *ltcache.Cache) (rpcPool *rpcclient.RPCPool, err error) { + var rpcClient birpc.ClientConnector + var atLeastOneConnected bool // If one connected we don't longer return errors rpcPool = rpcclient.NewRPCPool(dispatchStrategy, replyTimeout) for _, rpcConnCfg := range rpcConnCfgs { if rpcConnCfg.Address == utils.EmptyString { @@ -44,17 +49,17 @@ func NewRPCPool(dispatchStrategy string, keyPath, certPath, caPath string, connA err = rpcclient.ErrDisconnected continue } - if rpcClient, err = NewRPCConnection(rpcConnCfg, keyPath, certPath, caPath, connAttempts, reconnects, - connectTimeout, replyTimeout, internalConnChan, lazyConnect, biRPCClient, - poolID, rpcConnCfg.ID, connCache); err == rpcclient.ErrUnsupportedCodec { + if rpcClient, err = NewRPCConnection(ctx, rpcConnCfg, keyPath, certPath, caPath, connAttempts, reconnects, + maxReconnectInterval, connectTimeout, replyTimeout, internalConnChan, lazyConnect, poolID, rpcConnCfg.ID, + connCache); err == rpcclient.ErrUnsupportedCodec { return nil, fmt.Errorf("Unsupported transport: <%s>", rpcConnCfg.Transport) } if err == nil { - atLestOneConnected = true + atLeastOneConnected = true } rpcPool.AddClient(rpcClient) } - if atLestOneConnected { + if atLeastOneConnected { err = nil } return @@ -62,25 +67,42 @@ func NewRPCPool(dispatchStrategy string, keyPath, certPath, caPath string, connA // NewRPCConnection creates a new connection based on the RemoteHost structure // connCache is used to cache the connection with ID -func NewRPCConnection(cfg *config.RemoteHost, keyPath, certPath, caPath string, connAttempts, reconnects int, - connectTimeout, replyTimeout time.Duration, internalConnChan chan rpcclient.ClientConnector, lazyConnect bool, - biRPCClient rpcclient.BiRPCConector, poolID, connID string, connCache *ltcache.Cache) (client rpcclient.ClientConnector, err error) { +func NewRPCConnection(ctx *context.Context, cfg *config.RemoteHost, keyPath, certPath, caPath string, connAttempts, reconnects int, + maxReconnectInterval, connectTimeout, replyTimeout time.Duration, internalConnChan chan birpc.ClientConnector, lazyConnect bool, + poolID, connID string, connCache *ltcache.Cache) (client birpc.ClientConnector, err error) { var id string if connID != utils.EmptyString { id = poolID + utils.ConcatenatedKeySep + connID if x, ok := connCache.Get(id); ok && x != nil { - return x.(rpcclient.ClientConnector), nil + return x.(birpc.ClientConnector), nil } } if cfg.Address == rpcclient.InternalRPC || cfg.Address == rpcclient.BiRPCInternal { - client, err = rpcclient.NewRPCClient("", "", cfg.TLS, utils.FirstNonEmpty(cfg.ClientKey, keyPath), utils.FirstNonEmpty(cfg.ClientCertificate, certPath), utils.FirstNonEmpty(cfg.CaCertificate, caPath), utils.FirstIntNonEmpty(cfg.ConnectAttempts, connAttempts), - utils.FirstIntNonEmpty(cfg.Reconnects, reconnects), utils.FirstDurationNonEmpty(cfg.ConnectTimeout, connectTimeout), utils.FirstDurationNonEmpty(cfg.ReplyTimeout, replyTimeout), cfg.Address, internalConnChan, lazyConnect, biRPCClient) - } else { - client, err = rpcclient.NewRPCClient(utils.TCP, cfg.Address, cfg.TLS, utils.FirstNonEmpty(cfg.ClientKey, keyPath), utils.FirstNonEmpty(cfg.ClientCertificate, certPath), utils.FirstNonEmpty(cfg.CaCertificate, caPath), + client, err = rpcclient.NewRPCClient(ctx, "", "", cfg.TLS, + utils.FirstNonEmpty(cfg.ClientKey, keyPath), + utils.FirstNonEmpty(cfg.ClientCertificate, certPath), + utils.FirstNonEmpty(cfg.CaCertificate, caPath), utils.FirstIntNonEmpty(cfg.ConnectAttempts, connAttempts), - utils.FirstIntNonEmpty(cfg.Reconnects, reconnects), utils.FirstDurationNonEmpty(cfg.ConnectTimeout, connectTimeout), utils.FirstDurationNonEmpty(cfg.ReplyTimeout, replyTimeout), - utils.FirstNonEmpty(cfg.Transport, rpcclient.GOBrpc), nil, lazyConnect, biRPCClient) + utils.FirstIntNonEmpty(cfg.Reconnects, reconnects), + utils.FirstDurationNonEmpty(cfg.MaxReconnectInterval, maxReconnectInterval), + utils.FibDuration, + utils.FirstDurationNonEmpty(cfg.ConnectTimeout, connectTimeout), + utils.FirstDurationNonEmpty(cfg.ReplyTimeout, replyTimeout), + cfg.Address, internalConnChan, lazyConnect, ctx.Client) + } else { + client, err = rpcclient.NewRPCClient(ctx, utils.TCP, cfg.Address, cfg.TLS, + utils.FirstNonEmpty(cfg.ClientKey, keyPath), + utils.FirstNonEmpty(cfg.ClientCertificate, certPath), + utils.FirstNonEmpty(cfg.CaCertificate, caPath), + utils.FirstIntNonEmpty(cfg.ConnectAttempts, connAttempts), + utils.FirstIntNonEmpty(cfg.Reconnects, reconnects), + utils.FirstDurationNonEmpty(cfg.MaxReconnectInterval, maxReconnectInterval), + utils.FibDuration, + utils.FirstDurationNonEmpty(cfg.ConnectTimeout, connectTimeout), + utils.FirstDurationNonEmpty(cfg.ReplyTimeout, replyTimeout), + utils.FirstNonEmpty(cfg.Transport, rpcclient.GOBrpc), + nil, lazyConnect, ctx.Client) } if connID != utils.EmptyString && err == nil { @@ -101,10 +123,11 @@ func NewRPCClientSet() (s RPCClientSet) { type RPCClientSet map[string]*rpcclient.RPCClient // AddInternalRPCClient creates and adds to the set a new rpc client using the provided configuration -func (s RPCClientSet) AddInternalRPCClient(name string, connChan chan rpcclient.ClientConnector) { - rpc, err := rpcclient.NewRPCClient(utils.EmptyString, utils.EmptyString, false, +func (s RPCClientSet) AddInternalRPCClient(name string, connChan chan birpc.ClientConnector) { + rpc, err := rpcclient.NewRPCClient(context.TODO(), utils.EmptyString, utils.EmptyString, false, utils.EmptyString, utils.EmptyString, utils.EmptyString, config.CgrConfig().GeneralCfg().ConnectAttempts, config.CgrConfig().GeneralCfg().Reconnects, + config.CgrConfig().GeneralCfg().MaxReconnectInterval, utils.FibDuration, config.CgrConfig().GeneralCfg().ConnectTimeout, config.CgrConfig().GeneralCfg().ReplyTimeout, rpcclient.InternalRPC, connChan, true, nil) if err != nil { @@ -115,14 +138,14 @@ func (s RPCClientSet) AddInternalRPCClient(name string, connChan chan rpcclient. } // GetInternalChanel is used when RPCClientSet is passed as internal connection for RPCPool -func (s RPCClientSet) GetInternalChanel() chan rpcclient.ClientConnector { - connChan := make(chan rpcclient.ClientConnector, 1) +func (s RPCClientSet) GetInternalChanel() chan birpc.ClientConnector { + connChan := make(chan birpc.ClientConnector, 1) connChan <- s return connChan } -// Call the implementation of the rpcclient.ClientConnector interface -func (s RPCClientSet) Call(method string, args any, reply any) error { +// Call the implementation of the birpc.ClientConnector interface +func (s RPCClientSet) Call(ctx *context.Context, method string, args any, reply any) error { methodSplit := strings.Split(method, ".") if len(methodSplit) != 2 { return rpcclient.ErrUnsupporteServiceMethod @@ -131,7 +154,7 @@ func (s RPCClientSet) Call(method string, args any, reply any) error { if !has { return rpcclient.ErrUnsupporteServiceMethod } - return conn.Call(method, args, reply) + return conn.Call(ctx, method, args, reply) } // func (s RPCClientSet) ReconnectInternals(subsystems ...string) (err error) { @@ -141,3 +164,160 @@ func (s RPCClientSet) Call(method string, args any, reply any) error { // } // } // } + +func NewService(val any) (_ IntService, err error) { + return NewServiceWithName(val, utils.EmptyString, false) +} + +func NewServiceWithName(val any, name string, useName bool) (_ IntService, err error) { + var srv *birpc.Service + if srv, err = birpc.NewService(val, name, useName); err != nil { + return + } + srv.Methods["Ping"] = pingM + s := IntService{srv.Name: srv} + for m, v := range srv.Methods { + m = strings.TrimPrefix(m, "BiRPC") + if len(m) < 2 || unicode.ToLower(rune(m[0])) != 'v' { + continue + } + + key := srv.Name + if unicode.IsLower(rune(key[len(key)-1])) { + key += "V" + } else { + key += "v" + } + key += string(m[1]) + srv2, has := s[key] + if !has { + srv2 = new(birpc.Service) + *srv2 = *srv + srv2.Name = key + RegisterPingMethod(srv2.Methods) + s[key] = srv2 + } + srv2.Methods[m[2:]] = v + } + return s, nil +} + +// func NewDispatcherService(val any) (_ IntService, err error) { +// var srv *birpc.Service +// if srv, err = birpc.NewService(val, utils.EmptyString, false); err != nil { +// return +// } +// srv.Methods["Ping"] = pingM +// s := IntService{srv.Name: srv} +// for m, v := range srv.Methods { +// key := srv.Name +// switch { +// case strings.HasPrefix(m, utils.AttributeS): +// m = strings.TrimPrefix(m, utils.AttributeS) +// key = utils.AttributeS +// case strings.HasPrefix(m, utils.CacheS): +// m = strings.TrimPrefix(m, utils.CacheS) +// key = utils.CacheS +// case strings.HasPrefix(m, utils.CDRs): +// m = strings.TrimPrefix(m, utils.CDRs) +// key = utils.CDRs +// case strings.HasPrefix(m, utils.ChargerS): +// m = strings.TrimPrefix(m, utils.ChargerS) +// key = utils.ChargerS +// case strings.HasPrefix(m, utils.ConfigS): +// m = strings.TrimPrefix(m, utils.ConfigS) +// key = utils.ConfigS +// case strings.HasPrefix(m, utils.CoreS): +// m = strings.TrimPrefix(m, utils.CoreS) +// key = utils.CoreS +// case strings.HasPrefix(m, utils.DispatcherS): +// m = strings.TrimPrefix(m, utils.DispatcherS) +// key = utils.DispatcherS +// case strings.HasPrefix(m, utils.EeS): +// m = strings.TrimPrefix(m, utils.EeS) +// key = utils.EeS +// case strings.HasPrefix(m, utils.GuardianS): +// m = strings.TrimPrefix(m, utils.GuardianS) +// key = utils.GuardianS +// case strings.HasPrefix(m, utils.RALs): +// m = strings.TrimPrefix(m, utils.RALs) +// key = utils.RALs +// case strings.HasPrefix(m, utils.ReplicatorS): +// m = strings.TrimPrefix(m, utils.ReplicatorS) +// key = utils.ReplicatorS +// case strings.HasPrefix(m, utils.ResourceS): +// m = strings.TrimPrefix(m, utils.ResourceS) +// key = utils.ResourceS +// case strings.HasPrefix(m, utils.Responder): +// m = strings.TrimPrefix(m, utils.Responder) +// key = utils.Responder +// case strings.HasPrefix(m, utils.RouteS): +// m = strings.TrimPrefix(m, utils.RouteS) +// key = utils.RouteS +// case strings.HasPrefix(m, utils.SchedulerS): +// m = strings.TrimPrefix(m, utils.SchedulerS) +// key = utils.SchedulerS +// case strings.HasPrefix(m, utils.SessionS): +// m = strings.TrimPrefix(m, utils.SessionS) +// key = utils.SessionS +// case strings.HasPrefix(m, utils.StatService): +// m = strings.TrimPrefix(m, utils.StatService) +// key = utils.StatService +// case strings.HasPrefix(m, utils.ThresholdS): +// m = strings.TrimPrefix(m, utils.ThresholdS) +// key = utils.ThresholdS +// } +// if (len(m) < 2 || unicode.ToLower(rune(m[0])) != 'v') && +// key != utils.Responder { +// continue +// } +// if key != utils.Responder { +// if unicode.IsLower(rune(key[len(key)-1])) { +// key += "V" +// } else { +// key += "v" +// } +// key += string(m[1]) +// m = m[2:] +// } +// srv2, has := s[key] +// if !has { +// srv2 = new(birpc.Service) +// *srv2 = *srv +// srv2.Name = key +// RegisterPingMethod(srv2.Methods) +// s[key] = srv2 +// } +// srv2.Methods[m] = v +// } +// return s, nil +// } + +type IntService map[string]*birpc.Service + +func (s IntService) Call(ctx *context.Context, serviceMethod string, args, reply any) error { + service, has := s[strings.Split(serviceMethod, utils.NestingSep)[0]] + if !has { + return errors.New("rpc: can't find service " + serviceMethod) + } + return service.Call(ctx, serviceMethod, args, reply) +} + +func ping(_ any, _ *context.Context, _ *utils.CGREvent, reply *string) error { + *reply = utils.Pong + return nil +} + +var pingM = &birpc.MethodType{ + Method: reflect.Method{ + Name: "Ping", + Type: reflect.TypeOf(ping), + Func: reflect.ValueOf(ping), + }, + ArgType: reflect.TypeOf(new(utils.CGREvent)), + ReplyType: reflect.TypeOf(new(string)), +} + +func RegisterPingMethod(methodMap map[string]*birpc.MethodType) { + methodMap["Ping"] = pingM +} diff --git a/engine/libengine_test.go b/engine/libengine_test.go index e40800994..fe38ff445 100644 --- a/engine/libengine_test.go +++ b/engine/libengine_test.go @@ -27,6 +27,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" @@ -40,7 +42,7 @@ func TestLibengineNewRPCPoolNoAddress(t *testing.T) { }() connID := "connID" - intChan := make(chan rpcclient.ClientConnector) + intChan := make(chan birpc.ClientConnector) defaultCfg := config.NewDefaultCGRConfig() defaultCfg.RPCConns()[connID] = config.NewDfltRPCConn() defaultCfg.RPCConns()[connID].Conns = []*config.RemoteHost{ @@ -53,9 +55,12 @@ func TestLibengineNewRPCPoolNoAddress(t *testing.T) { exp := &rpcclient.RPCPool{} experr := rpcclient.ErrDisconnected - rcv, err := NewRPCPool("", "", "", "", defaultCfg.GeneralCfg().ConnectAttempts, - defaultCfg.GeneralCfg().Reconnects, defaultCfg.GeneralCfg().ConnectTimeout, - 0, defaultCfg.RPCConns()[connID].Conns, intChan, false, nil, connID, connCache) + rcv, err := NewRPCPool(context.Background(), "", "", "", "", + defaultCfg.GeneralCfg().ConnectAttempts, + defaultCfg.GeneralCfg().Reconnects, + defaultCfg.GeneralCfg().MaxReconnectInterval, + defaultCfg.GeneralCfg().ConnectTimeout, + 0, defaultCfg.RPCConns()[connID].Conns, intChan, false, connID, connCache) if err == nil || err != experr { t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) @@ -75,30 +80,38 @@ func TestLibengineNewRPCConnection(t *testing.T) { }() cfg := &config.RemoteHost{ - ID: "a4f3f", - Address: "localhost:6012", - Transport: "*json", - ConnectAttempts: 2, - Reconnects: 5, - ConnectTimeout: 2 * time.Minute, - ReplyTimeout: 3 * time.Minute, - TLS: true, - ClientKey: "key1", + ID: "a4f3f", + Address: "localhost:6012", + Transport: "*json", + ConnectAttempts: 2, + Reconnects: 5, + MaxReconnectInterval: 5 * time.Minute, + ConnectTimeout: 2 * time.Minute, + ReplyTimeout: 3 * time.Minute, + TLS: true, + ClientKey: "key1", } expectedErr1 := "dial tcp [::1]:6012: connect: connection refused" expectedErr2 := "dial tcp 127.0.0.1:6012: connect: connection refused" cM := NewConnManager(config.NewDefaultCGRConfig(), nil) - exp, err := rpcclient.NewRPCClient(utils.TCP, cfg.Address, cfg.TLS, cfg.ClientKey, cM.cfg.TLSCfg().ClientCerificate, - cM.cfg.TLSCfg().CaCertificate, cfg.ConnectAttempts, cfg.Reconnects, cfg.ConnectTimeout, cfg.ReplyTimeout, - cfg.Transport, nil, false, nil) + exp, err := rpcclient.NewRPCClient(context.Background(), utils.TCP, cfg.Address, cfg.TLS, cfg.ClientKey, + cM.cfg.TLSCfg().ClientCerificate, cM.cfg.TLSCfg().CaCertificate, cfg.ConnectAttempts, cfg.Reconnects, + cfg.MaxReconnectInterval, utils.FibDuration, cfg.ConnectTimeout, cfg.ReplyTimeout, cfg.Transport, nil, false, nil) if err.Error() != expectedErr1 && err.Error() != expectedErr2 { t.Errorf("Expected %v or %v \n but received \n %v", expectedErr1, expectedErr2, err) } - conn, err := NewRPCConnection(cfg, cM.cfg.TLSCfg().ClientKey, cM.cfg.TLSCfg().ClientCerificate, cM.cfg.TLSCfg().CaCertificate, - cM.cfg.GeneralCfg().ConnectAttempts, cM.cfg.GeneralCfg().Reconnects, cM.cfg.GeneralCfg().ConnectTimeout, cM.cfg.GeneralCfg().ReplyTimeout, - nil, false, nil, "*localhost", "a4f3f", new(ltcache.Cache)) + conn, err := NewRPCConnection(context.Background(), cfg, + cM.cfg.TLSCfg().ClientKey, + cM.cfg.TLSCfg().ClientCerificate, + cM.cfg.TLSCfg().CaCertificate, + cM.cfg.GeneralCfg().ConnectAttempts, + cM.cfg.GeneralCfg().Reconnects, + cM.cfg.GeneralCfg().MaxReconnectInterval, + cM.cfg.GeneralCfg().ConnectTimeout, + cM.cfg.GeneralCfg().ReplyTimeout, + nil, false, "*localhost", "a4f3f", new(ltcache.Cache)) if err.Error() != expectedErr1 && err.Error() != expectedErr2 { t.Errorf("Expected %v or %v \n but received \n %v", expectedErr1, expectedErr2, err) } @@ -124,10 +137,10 @@ func TestLibengineNewRPCConnectionInternal(t *testing.T) { TLS: true, ClientKey: "key1", } - cM := NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan rpcclient.ClientConnector)) - exp, err := rpcclient.NewRPCClient("", "", cfg.TLS, cfg.ClientKey, cM.cfg.TLSCfg().ClientCerificate, - cM.cfg.TLSCfg().ClientCerificate, cfg.ConnectAttempts, cfg.Reconnects, cfg.ConnectTimeout, cfg.ReplyTimeout, - rpcclient.InternalRPC, cM.rpcInternal["a4f3f"], false, nil) + cM := NewConnManager(config.NewDefaultCGRConfig(), make(map[string]chan birpc.ClientConnector)) + exp, err := rpcclient.NewRPCClient(context.Background(), "", "", cfg.TLS, cfg.ClientKey, cM.cfg.TLSCfg().ClientCerificate, + cM.cfg.TLSCfg().ClientCerificate, cfg.ConnectAttempts, cfg.Reconnects, cfg.MaxReconnectInterval, utils.FibDuration, + cfg.ConnectTimeout, cfg.ReplyTimeout, rpcclient.InternalRPC, cM.rpcInternal["a4f3f"], false, nil) // We only want to check if the client loaded with the correct config, // therefore connection is not mandatory @@ -135,9 +148,16 @@ func TestLibengineNewRPCConnectionInternal(t *testing.T) { t.Error(err) } - conn, err := NewRPCConnection(cfg, cM.cfg.TLSCfg().ClientKey, cM.cfg.TLSCfg().ClientCerificate, cM.cfg.TLSCfg().CaCertificate, - cM.cfg.GeneralCfg().ConnectAttempts, cM.cfg.GeneralCfg().Reconnects, cM.cfg.GeneralCfg().ConnectTimeout, cM.cfg.GeneralCfg().ReplyTimeout, - cM.rpcInternal["a4f3f"], false, nil, "*internal", "a4f3f", new(ltcache.Cache)) + conn, err := NewRPCConnection(context.Background(), cfg, + cM.cfg.TLSCfg().ClientKey, + cM.cfg.TLSCfg().ClientCerificate, + cM.cfg.TLSCfg().CaCertificate, + cM.cfg.GeneralCfg().ConnectAttempts, + cM.cfg.GeneralCfg().Reconnects, + cM.cfg.GeneralCfg().MaxReconnectInterval, + cM.cfg.GeneralCfg().ConnectTimeout, + cM.cfg.GeneralCfg().ReplyTimeout, + cM.rpcInternal["a4f3f"], false, "*internal", "a4f3f", new(ltcache.Cache)) if err != rpcclient.ErrInternallyDisconnected { t.Error(err) @@ -153,7 +173,7 @@ func TestLibengineNewRPCPoolUnsupportedTransport(t *testing.T) { }() connID := "connID" - intChan := make(chan rpcclient.ClientConnector) + intChan := make(chan birpc.ClientConnector) defaultCfg := config.NewDefaultCGRConfig() defaultCfg.RPCConns()[connID] = config.NewDfltRPCConn() defaultCfg.RPCConns()[connID].Conns = []*config.RemoteHost{ @@ -168,9 +188,13 @@ func TestLibengineNewRPCPoolUnsupportedTransport(t *testing.T) { var exp *rpcclient.RPCPool experr := fmt.Sprintf("Unsupported transport: <%s>", defaultCfg.RPCConns()[connID].Conns[0].Transport) - rcv, err := NewRPCPool("", "", "", "", defaultCfg.GeneralCfg().ConnectAttempts, - defaultCfg.GeneralCfg().Reconnects, defaultCfg.GeneralCfg().ConnectTimeout, - 0, defaultCfg.RPCConns()[connID].Conns, intChan, false, nil, connID, connCache) + rcv, err := NewRPCPool(context.Background(), "", "", "", "", + defaultCfg.GeneralCfg().ConnectAttempts, + defaultCfg.GeneralCfg().Reconnects, + defaultCfg.GeneralCfg().MaxReconnectInterval, + defaultCfg.GeneralCfg().ConnectTimeout, + 0, defaultCfg.RPCConns()[connID].Conns, + intChan, false, connID, connCache) if err == nil || err.Error() != experr { t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) @@ -193,11 +217,12 @@ func TestLibengineNewRPCClientSet(t *testing.T) { func TestLibengineAddInternalRPCClientSuccess(t *testing.T) { s := RPCClientSet{} name := "testName" - connChan := make(chan rpcclient.ClientConnector) + connChan := make(chan birpc.ClientConnector) - expClient, err := rpcclient.NewRPCClient(utils.EmptyString, utils.EmptyString, false, + expClient, err := rpcclient.NewRPCClient(context.Background(), utils.EmptyString, utils.EmptyString, false, utils.EmptyString, utils.EmptyString, utils.EmptyString, config.CgrConfig().GeneralCfg().ConnectAttempts, config.CgrConfig().GeneralCfg().Reconnects, + config.CgrConfig().GeneralCfg().MaxReconnectInterval, utils.FibDuration, config.CgrConfig().GeneralCfg().ConnectTimeout, config.CgrConfig().GeneralCfg().ReplyTimeout, rpcclient.InternalRPC, connChan, true, nil) @@ -247,7 +272,7 @@ func TestLibengineCallInvalidMethod(t *testing.T) { reply := "testReply" experr := rpcclient.ErrUnsupporteServiceMethod - err := s.Call(method, args, reply) + err := s.Call(context.Background(), method, args, reply) if err == nil || err != experr { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) @@ -255,10 +280,11 @@ func TestLibengineCallInvalidMethod(t *testing.T) { } func TestLibengineCallMethodNotFound(t *testing.T) { - connChan := make(chan rpcclient.ClientConnector) - client, err := rpcclient.NewRPCClient(utils.EmptyString, utils.EmptyString, false, + connChan := make(chan birpc.ClientConnector) + client, err := rpcclient.NewRPCClient(context.Background(), utils.EmptyString, utils.EmptyString, false, utils.EmptyString, utils.EmptyString, utils.EmptyString, config.CgrConfig().GeneralCfg().ConnectAttempts, config.CgrConfig().GeneralCfg().Reconnects, + config.CgrConfig().GeneralCfg().MaxReconnectInterval, utils.FibDuration, config.CgrConfig().GeneralCfg().ConnectTimeout, config.CgrConfig().GeneralCfg().ReplyTimeout, rpcclient.InternalRPC, connChan, true, nil) @@ -274,7 +300,7 @@ func TestLibengineCallMethodNotFound(t *testing.T) { reply := "testReply" experr := rpcclient.ErrUnsupporteServiceMethod - err = s.Call(method, args, reply) + err = s.Call(context.Background(), method, args, reply) if err == nil || err != experr { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) @@ -282,10 +308,11 @@ func TestLibengineCallMethodNotFound(t *testing.T) { } func TestLibengineCallNilArgument(t *testing.T) { - connChan := make(chan rpcclient.ClientConnector) - client, err := rpcclient.NewRPCClient(utils.EmptyString, utils.EmptyString, false, + connChan := make(chan birpc.ClientConnector) + client, err := rpcclient.NewRPCClient(context.Background(), utils.EmptyString, utils.EmptyString, false, utils.EmptyString, utils.EmptyString, utils.EmptyString, config.CgrConfig().GeneralCfg().ConnectAttempts, config.CgrConfig().GeneralCfg().Reconnects, + config.CgrConfig().GeneralCfg().MaxReconnectInterval, utils.FibDuration, config.CgrConfig().GeneralCfg().ConnectTimeout, config.CgrConfig().GeneralCfg().ReplyTimeout, rpcclient.InternalRPC, connChan, true, nil) @@ -302,7 +329,7 @@ func TestLibengineCallNilArgument(t *testing.T) { experr := fmt.Sprintf("nil rpc in argument method: %s in: %v out: %v", method, args, reply) - err = s.Call(method, args, reply) + err = s.Call(context.Background(), method, args, reply) if err == nil || err.Error() != experr { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) diff --git a/engine/libtest.go b/engine/libtest.go index 5a85a7fd5..f99910e8a 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -23,13 +23,13 @@ import ( "context" "fmt" "io" - "net/rpc/jsonrpc" "os" "os/exec" "path" "strings" "time" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" diff --git a/engine/remoterepl.go b/engine/remoterepl.go index 816a05efc..d2e17ef74 100644 --- a/engine/remoterepl.go +++ b/engine/remoterepl.go @@ -19,6 +19,7 @@ along with this program. If not, see package engine import ( + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" ) @@ -38,7 +39,7 @@ func replicate(connMgr *ConnManager, connIDs []string, filtered bool, objType, o var reply string if !filtered { // is not partial so send to all defined connections - return utils.CastRPCErr(connMgr.Call(connIDs, nil, method, args, &reply)) + return utils.CastRPCErr(connMgr.Call(context.TODO(), connIDs, method, args, &reply)) } // is partial so get all the replicationHosts from cache based on object Type and ID // alp_cgrates.org:ATTR1 @@ -60,7 +61,7 @@ func replicateMultipleIDs(connMgr *ConnManager, connIDs []string, filtered bool, var reply string if !filtered { // is not partial so send to all defined connections - return utils.CastRPCErr(connMgr.Call(connIDs, nil, method, args, &reply)) + return utils.CastRPCErr(connMgr.Call(context.TODO(), connIDs, method, args, &reply)) } // is partial so get all the replicationHosts from cache based on object Type and ID // combine all hosts in a single set so if we receive a get with one ID in list diff --git a/engine/resources.go b/engine/resources.go index fe840d1b6..48bbd2067 100644 --- a/engine/resources.go +++ b/engine/resources.go @@ -26,6 +26,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" @@ -542,7 +543,7 @@ func (rS *ResourceService) processThresholds(rs Resources, opts map[string]any) APIOpts: opts, } var tIDs []string - if err := rS.connMgr.Call(rS.cgrcfg.ResourceSCfg().ThresholdSConns, nil, + if err := rS.connMgr.Call(context.TODO(), rS.cgrcfg.ResourceSCfg().ThresholdSConns, utils.ThresholdSv1ProcessEvent, thEv, &tIDs); err != nil && (len(thIDs) != 0 || err.Error() != utils.ErrNotFound.Error()) { utils.Logger.Warning( @@ -670,8 +671,8 @@ func (rS *ResourceService) matchingResourcesForEvent(tnt string, ev *utils.CGREv return } -// V1ResourcesForEvent returns active resource configs matching the event -func (rS *ResourceService) V1ResourcesForEvent(args *utils.CGREvent, reply *Resources) (err error) { +// V1GetResourcesForEvent returns active resource configs matching the event +func (rS *ResourceService) V1GetResourcesForEvent(ctx *context.Context, args *utils.CGREvent, reply *Resources) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.Event) } @@ -721,7 +722,7 @@ func (rS *ResourceService) V1ResourcesForEvent(args *utils.CGREvent, reply *Reso } // V1AuthorizeResources queries service to find if an Usage is allowed -func (rS *ResourceService) V1AuthorizeResources(args *utils.CGREvent, reply *string) (err error) { +func (rS *ResourceService) V1AuthorizeResources(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.Event) } @@ -788,7 +789,7 @@ func (rS *ResourceService) V1AuthorizeResources(args *utils.CGREvent, reply *str } // V1AllocateResources is called when a resource requires allocation -func (rS *ResourceService) V1AllocateResources(args *utils.CGREvent, reply *string) (err error) { +func (rS *ResourceService) V1AllocateResources(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.Event) } @@ -859,7 +860,7 @@ func (rS *ResourceService) V1AllocateResources(args *utils.CGREvent, reply *stri } // V1ReleaseResources is called when we need to clear an allocation -func (rS *ResourceService) V1ReleaseResources(args *utils.CGREvent, reply *string) (err error) { +func (rS *ResourceService) V1ReleaseResources(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.Event) } @@ -923,7 +924,7 @@ func (rS *ResourceService) V1ReleaseResources(args *utils.CGREvent, reply *strin } // V1GetResource returns a resource configuration -func (rS *ResourceService) V1GetResource(arg *utils.TenantIDWithAPIOpts, reply *Resource) error { +func (rS *ResourceService) V1GetResource(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *Resource) error { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -951,7 +952,7 @@ type ResourceWithConfig struct { Config *ResourceProfile } -func (rS *ResourceService) V1GetResourceWithConfig(arg *utils.TenantIDWithAPIOpts, reply *ResourceWithConfig) (err error) { +func (rS *ResourceService) V1GetResourceWithConfig(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *ResourceWithConfig) (err error) { if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/engine/responder.go b/engine/responder.go index 3b527e17f..923055c8e 100644 --- a/engine/responder.go +++ b/engine/responder.go @@ -25,6 +25,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" @@ -66,7 +67,7 @@ func (rs *Responder) usageAllowed(tor string, reqUsage time.Duration) (allowed b /* RPC method that provides the external RPC interface for getting the rating information. */ -func (rs *Responder) GetCost(arg *CallDescriptorWithAPIOpts, reply *CallCost) (err error) { +func (rs *Responder) GetCost(ctx *context.Context, arg *CallDescriptorWithAPIOpts, reply *CallCost) (err error) { // RPC caching if arg.CgrID != utils.EmptyString && config.CgrConfig().CacheCfg().Partitions[utils.CacheRPCResponses].Limit != 0 { cacheKey := utils.ConcatenatedKey(utils.ResponderGetCost, arg.CgrID) @@ -114,7 +115,7 @@ func (rs *Responder) GetCost(arg *CallDescriptorWithAPIOpts, reply *CallCost) (e // GetCostOnRatingPlans is used by RouteS to calculate the cost // Receive a list of RatingPlans and pick the first without error -func (rs *Responder) GetCostOnRatingPlans(arg *utils.GetCostOnRatingPlansArgs, reply *map[string]any) (err error) { +func (rs *Responder) GetCostOnRatingPlans(ctx *context.Context, arg *utils.GetCostOnRatingPlansArgs, reply *map[string]any) (err error) { tnt := arg.Tenant if tnt == utils.EmptyString { tnt = config.CgrConfig().GeneralCfg().DefaultTenant @@ -170,7 +171,7 @@ func (rs *Responder) GetCostOnRatingPlans(arg *utils.GetCostOnRatingPlansArgs, r return } -func (rs *Responder) Debit(arg *CallDescriptorWithAPIOpts, reply *CallCost) (err error) { +func (rs *Responder) Debit(ctx *context.Context, arg *CallDescriptorWithAPIOpts, reply *CallCost) (err error) { // RPC caching if arg.Tenant == utils.EmptyString { arg.Tenant = config.CgrConfig().GeneralCfg().DefaultTenant @@ -211,7 +212,7 @@ func (rs *Responder) Debit(arg *CallDescriptorWithAPIOpts, reply *CallCost) (err return } -func (rs *Responder) MaxDebit(arg *CallDescriptorWithAPIOpts, reply *CallCost) (err error) { +func (rs *Responder) MaxDebit(ctx *context.Context, arg *CallDescriptorWithAPIOpts, reply *CallCost) (err error) { // RPC caching if arg.Tenant == utils.EmptyString { arg.Tenant = config.CgrConfig().GeneralCfg().DefaultTenant @@ -251,7 +252,7 @@ func (rs *Responder) MaxDebit(arg *CallDescriptorWithAPIOpts, reply *CallCost) ( return } -func (rs *Responder) RefundIncrements(arg *CallDescriptorWithAPIOpts, reply *Account) (err error) { +func (rs *Responder) RefundIncrements(ctx *context.Context, arg *CallDescriptorWithAPIOpts, reply *Account) (err error) { // RPC caching if arg.Tenant == utils.EmptyString { arg.Tenant = config.CgrConfig().GeneralCfg().DefaultTenant @@ -292,7 +293,7 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptorWithAPIOpts, reply *Acc return } -func (rs *Responder) RefundRounding(arg *CallDescriptorWithAPIOpts, reply *Account) (err error) { +func (rs *Responder) RefundRounding(ctx *context.Context, arg *CallDescriptorWithAPIOpts, reply *Account) (err error) { // RPC caching if arg.Tenant == utils.EmptyString { arg.Tenant = config.CgrConfig().GeneralCfg().DefaultTenant @@ -330,7 +331,7 @@ func (rs *Responder) RefundRounding(arg *CallDescriptorWithAPIOpts, reply *Accou return } -func (rs *Responder) GetMaxSessionTime(arg *CallDescriptorWithAPIOpts, reply *time.Duration) (err error) { +func (rs *Responder) GetMaxSessionTime(ctx *context.Context, arg *CallDescriptorWithAPIOpts, reply *time.Duration) (err error) { if arg.Tenant == utils.EmptyString { arg.Tenant = config.CgrConfig().GeneralCfg().DefaultTenant } @@ -344,7 +345,7 @@ func (rs *Responder) GetMaxSessionTime(arg *CallDescriptorWithAPIOpts, reply *ti return } -func (rs *Responder) GetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnAccountsArgs, +func (rs *Responder) GetMaxSessionTimeOnAccounts(ctx *context.Context, arg *utils.GetMaxSessionTimeOnAccountsArgs, reply *map[string]any) (err error) { var maxDur time.Duration tnt := arg.Tenant @@ -378,7 +379,7 @@ func (rs *Responder) GetMaxSessionTimeOnAccounts(arg *utils.GetMaxSessionTimeOnA return } -func (rs *Responder) Shutdown(arg *utils.TenantWithAPIOpts, reply *string) (err error) { +func (rs *Responder) Shutdown(ctx *context.Context, arg *utils.TenantWithAPIOpts, reply *string) (err error) { dm.DataDB().Close() cdrStorage.Close() defer rs.ShdChan.CloseOnce() @@ -387,12 +388,12 @@ func (rs *Responder) Shutdown(arg *utils.TenantWithAPIOpts, reply *string) (err } // Ping used to detreminate if component is active -func (chSv1 *Responder) Ping(ign *utils.CGREvent, reply *string) error { +func (chSv1 *Responder) Ping(ctx *context.Context, ign *utils.CGREvent, reply *string) error { *reply = utils.Pong return nil } -func (rs *Responder) Call(serviceMethod string, args any, reply any) error { +func (rs *Responder) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { parts := strings.Split(serviceMethod, ".") if len(parts) != 2 { return utils.ErrNotImplemented diff --git a/engine/responder_test.go b/engine/responder_test.go index 61fc87143..f6b5b4b7f 100644 --- a/engine/responder_test.go +++ b/engine/responder_test.go @@ -27,9 +27,9 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) var rsponder = &Responder{MaxComputedUsage: config.CgrConfig().RalsCfg().MaxComputedUsage} @@ -170,7 +170,7 @@ func TestResponderGetCostMaxUsageANY(t *testing.T) { }, } var cc CallCost - if err := rsponder.GetCost(cd, &cc); err == nil || + if err := rsponder.GetCost(context.Background(), cd, &cc); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -197,7 +197,7 @@ func TestResponderGetCostMaxUsageVOICE(t *testing.T) { }, } var cc CallCost - if err := rsponder.GetCost(cd, &cc); err == nil || + if err := rsponder.GetCost(context.Background(), cd, &cc); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -224,7 +224,7 @@ func TestResponderDebitMaxUsageANY(t *testing.T) { }, } var cc CallCost - if err := rsponder.Debit(cd, &cc); err == nil || + if err := rsponder.Debit(context.Background(), cd, &cc); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -251,7 +251,7 @@ func TestResponderDebitMaxUsageVOICE(t *testing.T) { }, } var cc CallCost - if err := rsponder.Debit(cd, &cc); err == nil || + if err := rsponder.Debit(context.Background(), cd, &cc); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -278,7 +278,7 @@ func TestResponderMaxDebitMaxUsageANY(t *testing.T) { }, } var cc CallCost - if err := rsponder.MaxDebit(cd, &cc); err == nil || + if err := rsponder.MaxDebit(context.Background(), cd, &cc); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -305,7 +305,7 @@ func TestResponderMaxDebitMaxUsageVOICE(t *testing.T) { }, } var cc CallCost - if err := rsponder.MaxDebit(cd, &cc); err == nil || + if err := rsponder.MaxDebit(context.Background(), cd, &cc); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -332,7 +332,7 @@ func TestResponderRefundIncrementsMaxUsageANY(t *testing.T) { }, } var acc Account - if err := rsponder.RefundIncrements(cd, &acc); err == nil || + if err := rsponder.RefundIncrements(context.Background(), cd, &acc); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -359,7 +359,7 @@ func TestResponderRefundIncrementsMaxUsageVOICE(t *testing.T) { }, } var acc Account - if err := rsponder.RefundIncrements(cd, &acc); err == nil || + if err := rsponder.RefundIncrements(context.Background(), cd, &acc); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -386,7 +386,7 @@ func TestResponderRefundRoundingMaxUsageANY(t *testing.T) { }, } var reply Account - if err := rsponder.RefundRounding(cd, &reply); err == nil || + if err := rsponder.RefundRounding(context.Background(), cd, &reply); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -413,7 +413,7 @@ func TestResponderRefundRoundingMaxUsageVOICE(t *testing.T) { }, } var reply Account - if err := rsponder.RefundRounding(cd, &reply); err == nil || + if err := rsponder.RefundRounding(context.Background(), cd, &reply); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -440,7 +440,7 @@ func TestResponderGetMaxSessionTimeMaxUsageANY(t *testing.T) { }, } var reply time.Duration - if err := rsponder.GetMaxSessionTime(cd, &reply); err == nil || + if err := rsponder.GetMaxSessionTime(context.Background(), cd, &reply); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -467,7 +467,7 @@ func TestResponderGetMaxSessionTimeMaxUsageVOICE(t *testing.T) { }, } var reply time.Duration - if err := rsponder.GetMaxSessionTime(cd, &reply); err == nil || + if err := rsponder.GetMaxSessionTime(context.Background(), cd, &reply); err == nil || err.Error() != utils.ErrMaxUsageExceeded.Error() { t.Errorf("Expected %+v, received : %+v", utils.ErrMaxUsageExceeded, err) } @@ -510,7 +510,7 @@ func TestResponderGetCost(t *testing.T) { Destination: "uk", } - if err = rs.GetCost(arg, reply); err != nil { + if err = rs.GetCost(context.Background(), arg, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -569,7 +569,7 @@ func TestResponderGetCostSet(t *testing.T) { &utils.CachedRPCResponse{Result: reply, Error: nil}, nil, true, utils.NonTransactional) - if err = rs.GetCost(arg, reply); err != nil { + if err = rs.GetCost(context.Background(), arg, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -630,7 +630,7 @@ func TestResponderDebit(t *testing.T) { Account: "acount", Destination: "uk", } - if err := rs.Debit(arg, reply); err == nil || err != utils.ErrAccountNotFound { + if err := rs.Debit(context.Background(), arg, reply); err == nil || err != utils.ErrAccountNotFound { t.Errorf("expected %+v ,received %+v", utils.ErrAccountNotFound, err) } } @@ -659,7 +659,7 @@ func TestGetCostOnRatingPlansErr(t *testing.T) { dm: dm, }, } - if err := rs.GetCostOnRatingPlans(arg, reply); err == nil || err != utils.ErrUnauthorizedDestination { + if err := rs.GetCostOnRatingPlans(context.Background(), arg, reply); err == nil || err != utils.ErrUnauthorizedDestination { t.Errorf("expected %+v ,received %+v", utils.ErrUnauthorizedDestination, err) } } @@ -728,7 +728,7 @@ func TestResponderDebitSet(t *testing.T) { &utils.CachedRPCResponse{Result: reply, Error: nil}, nil, true, utils.NonTransactional) - if err := rs.Debit(arg, reply); err != nil { + if err := rs.Debit(context.Background(), arg, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{Result: reply, Error: nil} @@ -785,7 +785,7 @@ func TestResponderMaxDebit(t *testing.T) { Account: "acount", Destination: "uk", } - if err := rs.MaxDebit(arg, reply); err == nil || err != utils.ErrAccountNotFound { + if err := rs.MaxDebit(context.Background(), arg, reply); err == nil || err != utils.ErrAccountNotFound { t.Errorf("expected %+v ,received %+v", utils.ErrAccountNotFound, err) } exp := &utils.CachedRPCResponse{ @@ -847,7 +847,7 @@ func TestResponderMaxDebitSet(t *testing.T) { Cache.Set(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.ResponderMaxDebit, arg.CgrID), &utils.CachedRPCResponse{Result: reply, Error: nil}, nil, true, utils.NonTransactional) - if err := rs.MaxDebit(arg, reply); err != nil { + if err := rs.MaxDebit(context.Background(), arg, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -908,7 +908,7 @@ func TestResponderRefundIncrements(t *testing.T) { UpdateTime: time.Date(2021, 12, 1, 12, 0, 0, 0, time.UTC), executingTriggers: false, } - if err := rs.RefundIncrements(arg, reply); err != nil { + if err := rs.RefundIncrements(context.Background(), arg, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -975,7 +975,7 @@ func TestResponderRefundIncrementsSet(t *testing.T) { Result: reply, Error: nil, }, nil, true, utils.NonTransactional) - if err := rs.RefundIncrements(arg, reply); err != nil { + if err := rs.RefundIncrements(context.Background(), arg, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -1038,7 +1038,7 @@ func TestResponderRefundRounding(t *testing.T) { UpdateTime: time.Date(2021, 12, 1, 12, 0, 0, 0, time.UTC), executingTriggers: false, } - if err := rs.RefundRounding(arg, reply); err != nil { + if err := rs.RefundRounding(context.Background(), arg, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -1104,7 +1104,7 @@ func TestResponderRefundRoundingSet(t *testing.T) { &utils.CachedRPCResponse{Result: reply, Error: err}, nil, true, utils.NonTransactional) - if err := rs.RefundRounding(arg, reply); err != nil { + if err := rs.RefundRounding(context.Background(), arg, reply); err != nil { t.Error(err) } exp := &utils.CachedRPCResponse{ @@ -1154,7 +1154,7 @@ func TestGetMaxSessionTimeOnAccountsErr(t *testing.T) { }, } expLog := ` ignoring cost for account: ` - if err := rs.GetMaxSessionTimeOnAccounts(arg, reply); err == nil || err != utils.ErrAccountNotFound { + if err := rs.GetMaxSessionTimeOnAccounts(context.Background(), arg, reply); err == nil || err != utils.ErrAccountNotFound { t.Error(err) } if rcvLog := buf.String(); !strings.Contains(rcvLog, expLog) { @@ -1163,50 +1163,6 @@ func TestGetMaxSessionTimeOnAccountsErr(t *testing.T) { } -func TestResponderCall(t *testing.T) { - tmpConn := connMgr - tmp := Cache - defer func() { - Cache = tmp - connMgr = tmpConn - }() - Cache.Clear(nil) - cfg := config.NewDefaultCGRConfig() - cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 - db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - dm := NewDataManager(db, cfg.CacheCfg(), nil) - Cache = NewCacheS(cfg, dm, nil) - config.SetCgrConfig(cfg) - rs := &Responder{ - Timezone: "UTC", - FilterS: &FilterS{ - cfg: cfg, - dm: dm, - }, - MaxComputedUsage: map[string]time.Duration{}, - } - clientConn := make(chan rpcclient.ClientConnector, 1) - clientConn <- rs - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{}) - config.SetCgrConfig(cfg) - SetConnManager(connMgr) - var reply CallCost - attr := &CallDescriptorWithAPIOpts{ - CallDescriptor: &CallDescriptor{ - Category: "call", - Tenant: "cgrates.org", - Subject: "dan", - ToR: utils.MetaAny, - Account: "dan", - Destination: "+4917621621391", - DurationIndex: 9, - }, - } - if err := rs.Call(utils.ResponderGetCost, attr, &reply); err != nil { - t.Error(err) - } -} - func TestGetMaxSessionTime(t *testing.T) { tmpdm := dm cfg := config.NewDefaultCGRConfig() @@ -1250,7 +1206,7 @@ func TestGetMaxSessionTime(t *testing.T) { }, } var reply time.Duration - if err := rsponder.GetMaxSessionTime(cd, &reply); err == nil || err != utils.ErrAccountNotFound { + if err := rsponder.GetMaxSessionTime(context.Background(), cd, &reply); err == nil || err != utils.ErrAccountNotFound { t.Errorf("Expected %+v, received :", err) } } @@ -1286,7 +1242,7 @@ func TestResponderShutDown(t *testing.T) { }, } var reply string - if err := rs.Shutdown(arg, &reply); err != nil { + if err := rs.Shutdown(context.Background(), arg, &reply); err != nil { t.Error(err) } else if reply != "Done!" { t.Errorf("Expected Done!,Received %v", reply) @@ -1378,7 +1334,7 @@ func TestResponderDebitDebit(t *testing.T) { }) var reply CallCost SetDataStorage(dm) - if err := rsponder.Debit(cd, &reply); err != nil { + if err := rsponder.Debit(context.Background(), cd, &reply); err != nil { t.Error(err) } else if reply.Cost != 1.5 { t.Errorf("expected Cost to be 1.5, got %v", reply.Cost) @@ -1468,7 +1424,7 @@ func TestResponderGetCostOnRatingPlans(t *testing.T) { utils.RatingPlanID: "RP1", } SetDataStorage(dm) - if err := rsponder.GetCostOnRatingPlans(arg, &reply); err != nil { + if err := rsponder.GetCostOnRatingPlans(context.Background(), arg, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, exp) { t.Errorf("expected %v, got %v", exp, reply) diff --git a/engine/routes.go b/engine/routes.go index 414350a83..bb84b7fbe 100644 --- a/engine/routes.go +++ b/engine/routes.go @@ -26,6 +26,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -224,7 +225,7 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent, var acntCost map[string]any var initialUsage time.Duration if len(acntIDs) != 0 { - if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().RALsConns, nil, utils.ResponderGetMaxSessionTimeOnAccounts, + if err := rpS.connMgr.Call(context.TODO(), rpS.cgrcfg.RouteSCfg().RALsConns, utils.ResponderGetMaxSessionTimeOnAccounts, &utils.GetMaxSessionTimeOnAccountsArgs{ Tenant: ev.Tenant, Subject: subj, @@ -258,7 +259,7 @@ func (rpS *RouteService) costForEvent(ev *utils.CGREvent, if accountMaxUsage == 0 || accountMaxUsage < initialUsage { var rpCost map[string]any - if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().RALsConns, nil, utils.ResponderGetCostOnRatingPlans, + if err := rpS.connMgr.Call(context.TODO(), rpS.cgrcfg.RouteSCfg().RALsConns, utils.ResponderGetCostOnRatingPlans, &utils.GetCostOnRatingPlansArgs{ Tenant: ev.Tenant, Account: acnt, @@ -286,7 +287,7 @@ func (rpS *RouteService) statMetrics(statIDs []string, tenant string) (stsMetric if len(rpS.cgrcfg.RouteSCfg().StatSConns) != 0 { for _, statID := range statIDs { var metrics map[string]float64 - if err = rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().StatSConns, nil, utils.StatSv1GetQueueFloatMetrics, + if err = rpS.connMgr.Call(context.TODO(), rpS.cgrcfg.RouteSCfg().StatSConns, utils.StatSv1GetQueueFloatMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: statID}}, &metrics); err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning( @@ -317,8 +318,8 @@ func (rpS *RouteService) statMetricsForLoadDistribution(statIDs []string, tenant // check if we get an ID in the following form (StatID:MetricID) statWithMetric := strings.Split(statID, utils.InInFieldSep) var metrics map[string]float64 - if err = rpS.connMgr.Call( - rpS.cgrcfg.RouteSCfg().StatSConns, nil, + if err = rpS.connMgr.Call(context.TODO(), + rpS.cgrcfg.RouteSCfg().StatSConns, utils.StatSv1GetQueueFloatMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{ @@ -360,7 +361,7 @@ func (rpS *RouteService) resourceUsage(resIDs []string, tenant string) (tUsage f if len(rpS.cgrcfg.RouteSCfg().ResourceSConns) != 0 { for _, resID := range resIDs { var res Resource - if err = rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().ResourceSConns, nil, utils.ResourceSv1GetResource, + if err = rpS.connMgr.Call(context.TODO(), rpS.cgrcfg.RouteSCfg().ResourceSConns, utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: resID}}, &res); err != nil && err.Error() != utils.ErrNotFound.Error() { utils.Logger.Warning( fmt.Sprintf("<%s> error: %s getting resource for ID : %s", utils.RouteS, err.Error(), resID)) @@ -557,7 +558,7 @@ type optsGetRoutes struct { } // V1GetRoutes returns the list of valid routes -func (rpS *RouteService) V1GetRoutes(args *utils.CGREvent, reply *SortedRoutesList) (err error) { +func (rpS *RouteService) V1GetRoutes(ctx *context.Context, args *utils.CGREvent, reply *SortedRoutesList) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) } @@ -575,10 +576,12 @@ func (rpS *RouteService) V1GetRoutes(args *utils.CGREvent, reply *SortedRoutesLi args.APIOpts = make(map[string]any) } args.APIOpts[utils.MetaSubsys] = utils.MetaRoutes - context := utils.GetStringOpts(args, rpS.cgrcfg.RouteSCfg().Opts.Context, utils.OptsContext) - args.APIOpts[utils.OptsContext] = utils.FirstNonEmpty(context, utils.MetaRoutes) + args.APIOpts[utils.OptsContext] = utils.FirstNonEmpty( + utils.GetStringOpts(args, rpS.cgrcfg.RouteSCfg().Opts.Context, utils.OptsContext), + utils.MetaRoutes, + ) var rplyEv AttrSProcessEventReply - if err := rpS.connMgr.Call(rpS.cgrcfg.RouteSCfg().AttributeSConns, nil, + if err := rpS.connMgr.Call(context.TODO(), rpS.cgrcfg.RouteSCfg().AttributeSConns, utils.AttributeSv1ProcessEvent, args, &rplyEv); err == nil && len(rplyEv.AlteredFields) != 0 { args = rplyEv.CGREvent } else if err.Error() != utils.ErrNotFound.Error() { @@ -597,7 +600,7 @@ func (rpS *RouteService) V1GetRoutes(args *utils.CGREvent, reply *SortedRoutesLi } // V1GetRouteProfilesForEvent returns the list of valid route profiles -func (rpS *RouteService) V1GetRouteProfilesForEvent(args *utils.CGREvent, reply *[]*RouteProfile) (err error) { +func (rpS *RouteService) V1GetRouteProfilesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*RouteProfile) (err error) { if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } else if args.Event == nil { @@ -736,9 +739,9 @@ func (rpS *RouteService) sortedRoutesForEvent(tnt string, args *utils.CGREvent) } // V1GetRoutesList returns the list of valid routes -func (rpS *RouteService) V1GetRoutesList(args *utils.CGREvent, reply *[]string) (err error) { +func (rpS *RouteService) V1GetRoutesList(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) { sR := new(SortedRoutesList) - if err = rpS.V1GetRoutes(args, sR); err != nil { + if err = rpS.V1GetRoutes(ctx, args, sR); err != nil { return } *reply = sR.RoutesWithParams() diff --git a/engine/routes_test.go b/engine/routes_test.go index e12eaf301..2d6b50bdf 100644 --- a/engine/routes_test.go +++ b/engine/routes_test.go @@ -29,8 +29,9 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" - "github.com/cgrates/rpcclient" "github.com/cgrates/cgrates/utils" ) @@ -859,8 +860,8 @@ func TestRouteServiceStatMetrics(t *testing.T) { }() testMock := &ccMock{ - calls: map[string]func(args, reply any) error{ - utils.StatSv1GetQueueFloatMetrics: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args, reply any) error{ + utils.StatSv1GetQueueFloatMetrics: func(ctx *context.Context, args, reply any) error { rpl := map[string]float64{ "metric1": 21.11, } @@ -875,9 +876,9 @@ func TestRouteServiceStatMetrics(t *testing.T) { cfg.RouteSCfg().StringIndexedFields = nil cfg.RouteSCfg().PrefixIndexedFields = nil cfg.RouteSCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)} - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- testMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): clientconn, }) rpS := NewRouteService(dmSPP, &FilterS{dm: dmSPP, cfg: cfg, connMgr: nil}, cfg, connMgr) @@ -901,8 +902,8 @@ func TestRouteServiceStatMetricsLog(t *testing.T) { log.SetOutput(os.Stderr) }() testMock := &ccMock{ - calls: map[string]func(args, reply any) error{ - utils.StatSv1GetQueueFloatMetrics: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args, reply any) error{ + utils.StatSv1GetQueueFloatMetrics: func(ctx *context.Context, args, reply any) error { return errors.New("Error") }, }, @@ -911,9 +912,9 @@ func TestRouteServiceStatMetricsLog(t *testing.T) { data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dmSPP := NewDataManager(data, config.CgrConfig().CacheCfg(), nil) cfg.RouteSCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)} - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- testMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): clientconn, }) rpS := NewRouteService(dmSPP, &FilterS{dm: dmSPP, cfg: cfg, connMgr: nil}, cfg, connMgr) @@ -1009,7 +1010,7 @@ func TestRouteServiceV1GetRouteProfilesForEvent(t *testing.T) { Weight: 0, }, } - if err := rpS.V1GetRouteProfilesForEvent(args, (*[]*RouteProfile)(testRoutesPrfs)); err == nil || err != utils.ErrNotFound { + if err := rpS.V1GetRouteProfilesForEvent(context.Background(), args, (*[]*RouteProfile)(testRoutesPrfs)); err == nil || err != utils.ErrNotFound { t.Error(err) } } @@ -1020,8 +1021,8 @@ func TestRouteServiceV1GetRoutes(t *testing.T) { }() ccMock := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.AttributeSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.AttributeSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rpl := &AttrSProcessEventReply{ AlteredFields: []string{"testcase"}, CGREvent: testRoutesArgs[1], @@ -1037,9 +1038,9 @@ func TestRouteServiceV1GetRoutes(t *testing.T) { cfg.RouteSCfg().StringIndexedFields = nil cfg.RouteSCfg().PrefixIndexedFields = nil cfg.RouteSCfg().AttributeSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): clientConn, }) rpS := NewRouteService(dmSPP, &FilterS{dm: dmSPP, cfg: cfg, connMgr: nil}, cfg, connMgr) @@ -1053,7 +1054,7 @@ func TestRouteServiceV1GetRoutes(t *testing.T) { } expErr := fmt.Sprintf("MANDATORY_IE_MISSING: [%v]", utils.CGREventString) var reply SortedRoutesList - if err := rpS.V1GetRoutes(nil, &reply); err == nil || err.Error() != expErr { + if err := rpS.V1GetRoutes(context.Background(), nil, &reply); err == nil || err.Error() != expErr { t.Errorf("Expected <%v>,Received <%v>", expErr, err.Error()) } expS := SortedRoutesList{ @@ -1067,7 +1068,7 @@ func TestRouteServiceV1GetRoutes(t *testing.T) { }, }, }} - if err = rpS.V1GetRoutes(args, &reply); err != nil { + if err = rpS.V1GetRoutes(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply[0].ProfileID, expS[0].ProfileID) { t.Errorf("Expected %v,Received %v", utils.ToJSON(expS), utils.ToJSON(reply)) @@ -1359,17 +1360,17 @@ func TestReaSortRoutes(t *testing.T) { utils.Logger.SetLogLevel(0) log.SetOutput(os.Stderr) }() - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderGetMaxSessionTimeOnAccounts: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderGetMaxSessionTimeOnAccounts: func(ctx *context.Context, args, reply any) error { rpl := map[string]any{ utils.CapMaxUsage: 3 * time.Minute, } *reply.(*map[string]any) = rpl return nil }, - utils.StatSv1GetQueueFloatMetrics: func(args, reply any) error { + utils.StatSv1GetQueueFloatMetrics: func(ctx *context.Context, args, reply any) error { rpl := map[string]float64{ "metric": 22.0, "metric3": 32.2, @@ -1379,7 +1380,7 @@ func TestReaSortRoutes(t *testing.T) { }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): clientConn, }) @@ -1524,17 +1525,17 @@ func TestLoadDistributionSorterSortRoutes(t *testing.T) { cfg.RouteSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} cfg.RouteSCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)} cfg.GeneralCfg().DefaultTimezone = "UTC" - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderGetMaxSessionTimeOnAccounts: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderGetMaxSessionTimeOnAccounts: func(ctx *context.Context, args, reply any) error { rpl := map[string]any{ utils.CapMaxUsage: 3 * time.Minute, } *reply.(*map[string]any) = rpl return nil }, - utils.StatSv1GetQueueFloatMetrics: func(args, reply any) error { + utils.StatSv1GetQueueFloatMetrics: func(ctx *context.Context, args, reply any) error { rpl := map[string]float64{ "metric": 22.0, "metric3": 32.2, @@ -1544,7 +1545,7 @@ func TestLoadDistributionSorterSortRoutes(t *testing.T) { }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): clientConn, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): clientConn, }) @@ -1634,8 +1635,8 @@ func TestRouteServicePopulateSortingData(t *testing.T) { Cache.Clear(nil) ccMock := &ccMock{ - calls: map[string]func(args, reply any) error{ - utils.ResponderGetMaxSessionTimeOnAccounts: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args, reply any) error{ + utils.ResponderGetMaxSessionTimeOnAccounts: func(ctx *context.Context, args, reply any) error { rpl := map[string]any{ utils.CapMaxUsage: 1 * time.Second, utils.Cost: 0, @@ -1643,7 +1644,7 @@ func TestRouteServicePopulateSortingData(t *testing.T) { *reply.(*map[string]any) = rpl return nil }, - utils.ResponderGetCostOnRatingPlans: func(args, reply any) error { + utils.ResponderGetCostOnRatingPlans: func(ctx *context.Context, args, reply any) error { rpl := map[string]any{ utils.CapMaxUsage: 5 * time.Second, utils.Cost: 0, @@ -1651,7 +1652,7 @@ func TestRouteServicePopulateSortingData(t *testing.T) { *reply.(*map[string]any) = rpl return nil }, - utils.StatSv1GetQueueFloatMetrics: func(args, reply any) error { + utils.StatSv1GetQueueFloatMetrics: func(ctx *context.Context, args, reply any) error { rpl := &map[string]float64{ "metric1": 12, "stat": 2.1, @@ -1659,7 +1660,7 @@ func TestRouteServicePopulateSortingData(t *testing.T) { *reply.(*map[string]float64) = *rpl return nil }, - utils.ResourceSv1GetResource: func(args, reply any) error { + utils.ResourceSv1GetResource: func(ctx *context.Context, args, reply any) error { rpl := &Resource{ Usages: map[string]*ResourceUsage{ "test_usage1": { @@ -1684,9 +1685,9 @@ func TestRouteServicePopulateSortingData(t *testing.T) { cfg.RouteSCfg().ResourceSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.ResourceSConnsCfg)} cfg.RouteSCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg)} cfg.RouteSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.RALsConnsCfg)} - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMock - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.RALsConnsCfg): clientconn, utils.ConcatenatedKey(utils.MetaInternal, utils.StatSConnsCfg): clientconn, utils.ConcatenatedKey(utils.MetaInternal, utils.ResourceSConnsCfg): clientconn}) @@ -1796,15 +1797,15 @@ func TestRSStatMetricsLogg(t *testing.T) { cfg.RouteSCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.StatSv1GetQueueFloatMetrics: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.StatSv1GetQueueFloatMetrics: func(ctx *context.Context, args, reply any) error { return errors.New("Can't get StatMetrics") }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): clientConn, }) statIds := []string{"STATS_VENDOR_1:*sum#1"} @@ -1831,15 +1832,15 @@ func TestRSStatMetricsForLoadDistributionLogg(t *testing.T) { cfg.RouteSCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.StatSv1GetQueueFloatMetrics: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.StatSv1GetQueueFloatMetrics: func(ctx *context.Context, args, reply any) error { return errors.New("Can't get StatMetrics") }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): clientConn, }) statIds := []string{"STATS_VENDOR_1:*sum#1"} @@ -1865,15 +1866,15 @@ func TestResourceUsage(t *testing.T) { }() cfg.RouteSCfg().ResourceSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} resIds := []string{"RL1"} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResourceSv1GetResource: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResourceSv1GetResource: func(ctx *context.Context, args, reply any) error { return errors.New("Can't get Resources") }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): clientConn, }) rps := NewRouteService(dm, nil, cfg, connMgr) @@ -1942,15 +1943,15 @@ func TestRSPopulateSortingDataResourceErr(t *testing.T) { config.SetCgrConfig(config.NewDefaultCGRConfig()) }() cfg.RouteSCfg().ResourceSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResourceSv1GetResource: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResourceSv1GetResource: func(ctx *context.Context, args, reply any) error { return errors.New("No Resources") }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): clientConn, }) rps := NewRouteService(dm, nil, cfg, connMgr) @@ -2002,15 +2003,15 @@ func TestPopulateSortingDataStatsErr(t *testing.T) { config.SetCgrConfig(config.NewDefaultCGRConfig()) }() cfg.RouteSCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.StatSv1GetQueueFloatMetrics: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.StatSv1GetQueueFloatMetrics: func(ctx *context.Context, args, reply any) error { return errors.New("No Stats") }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): clientConn, }) ev := &utils.CGREvent{ @@ -2056,10 +2057,10 @@ func TestPopulateSortingDataAccsErr(t *testing.T) { config.SetCgrConfig(config.NewDefaultCGRConfig()) }() cfg.RouteSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderGetMaxSessionTimeOnAccounts: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderGetMaxSessionTimeOnAccounts: func(ctx *context.Context, args, reply any) error { rpl := map[string]any{ utils.CapMaxUsage: 50 * time.Second, utils.Cost: 12.12, @@ -2069,7 +2070,7 @@ func TestPopulateSortingDataAccsErr(t *testing.T) { }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): clientConn, }) ev := &utils.CGREvent{ @@ -2118,20 +2119,20 @@ func TestPopulateSortingDataAccs2(t *testing.T) { config.SetCgrConfig(config.NewDefaultCGRConfig()) }() cfg.RouteSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderGetMaxSessionTimeOnAccounts: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderGetMaxSessionTimeOnAccounts: func(ctx *context.Context, args, reply any) error { rpl := map[string]any{} *reply.(*map[string]any) = rpl return nil }, - utils.ResponderGetCostOnRatingPlans: func(args, reply any) error { + utils.ResponderGetCostOnRatingPlans: func(ctx *context.Context, args, reply any) error { return nil }, }, } - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): clientConn, }) ev := &utils.CGREvent{ @@ -2177,7 +2178,7 @@ func TestV1GetRoutesList(t *testing.T) { dmSPP := NewDataManager(data, config.CgrConfig().CacheCfg(), nil) rpS := NewRouteService(dmSPP, &FilterS{dm: dmSPP, cfg: cfg, connMgr: nil}, cfg, connMgr) var reply []string - if err := rpS.V1GetRoutesList(testRoutesArgs[0], &reply); err == nil || err != utils.ErrNotFound { + if err := rpS.V1GetRoutesList(context.Background(), testRoutesArgs[0], &reply); err == nil || err != utils.ErrNotFound { t.Error(err) } @@ -2236,7 +2237,7 @@ func TestRoutesV1GetRoutes(t *testing.T) { }, } - if err := rpS.V1GetRouteProfilesForEvent(args, &reply); err != nil { + if err := rpS.V1GetRouteProfilesForEvent(context.Background(), args, &reply); err != nil { t.Error(err) } @@ -2287,7 +2288,7 @@ func TestRoutesV1GetRoutesList(t *testing.T) { }, Weight: 10, }, true) - if err := rpS.V1GetRoutesList(testRoutesArgs[0], &reply); err != nil { + if err := rpS.V1GetRoutesList(context.Background(), testRoutesArgs[0], &reply); err != nil { t.Error(err) } sort.Slice(reply, func(i, j int) bool { @@ -2305,7 +2306,7 @@ func TestRouteServiceV1GetRoutesErr(t *testing.T) { cfg.RouteSCfg().AttributeSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(db, cfg.CacheCfg(), nil) - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) clientConn <- clMock(func(serviceMethod string, _, _ any) error { if serviceMethod == utils.AttributeSv1ProcessEvent { @@ -2313,7 +2314,7 @@ func TestRouteServiceV1GetRoutesErr(t *testing.T) { } return utils.ErrNotImplemented }) - rpS := NewRouteService(dm, NewFilterS(cfg, nil, dm), cfg, NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + rpS := NewRouteService(dm, NewFilterS(cfg, nil, dm), cfg, NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): clientConn, })) @@ -2356,7 +2357,7 @@ func TestRouteServiceV1GetRoutesErr(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - if err := rpS.V1GetRoutes(tc.args, &tc.reply); err == nil { + if err := rpS.V1GetRoutes(context.Background(), tc.args, &tc.reply); err == nil { t.Errorf("expected error, received nil") } }) @@ -2365,23 +2366,23 @@ func TestRouteServiceV1GetRoutesErr(t *testing.T) { func TestRouteServiceSortRoutesQos(t *testing.T) { cfg := config.NewDefaultCGRConfig() - clientConn := make(chan rpcclient.ClientConnector, 1) + clientConn := make(chan birpc.ClientConnector, 1) rsp := &Responder{} tmpDm := dm defer func() { SetDataStorage(tmpDm) }() clientConn <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ResponderGetMaxSessionTimeOnAccounts: func(args, reply any) error { - return rsp.GetMaxSessionTimeOnAccounts(args.(*utils.GetMaxSessionTimeOnAccountsArgs), reply.(*map[string]any)) + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ResponderGetMaxSessionTimeOnAccounts: func(ctx *context.Context, args, reply any) error { + return rsp.GetMaxSessionTimeOnAccounts(ctx, args.(*utils.GetMaxSessionTimeOnAccountsArgs), reply.(*map[string]any)) }, }, } cfg.RouteSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} dm := NewDataManager(NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items), cfg.CacheCfg(), nil) SetDataStorage(dm) - rs := NewRouteService(dm, NewFilterS(cfg, nil, dm), cfg, NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + rs := NewRouteService(dm, NewFilterS(cfg, nil, dm), cfg, NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): clientConn, })) if err := dm.SetAccount(&Account{ @@ -2439,7 +2440,7 @@ func TestRouteServiceSortRoutesQos(t *testing.T) { utils.Tenant: "cgrates.org", utils.RequestType: utils.MetaPrepaid}, } - if err := rs.V1GetRoutes(cgrEv, &reply); err == nil { + if err := rs.V1GetRoutes(context.Background(), cgrEv, &reply); err == nil { t.Error(err) } } diff --git a/engine/stats.go b/engine/stats.go index 2e80ce9ea..7784feccf 100644 --- a/engine/stats.go +++ b/engine/stats.go @@ -24,6 +24,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" @@ -240,9 +241,9 @@ func (sS *StatService) matchingStatQueuesForEvent(tnt string, statsIDs []string, return } -// Call implements rpcclient.ClientConnector interface for internal RPC +// Call implements birpc.ClientConnector interface for internal RPC // here for cases when passing StatsService as rpccclient.RpcClientConnection -func (sS *StatService) Call(serviceMethod string, args any, reply any) error { +func (sS *StatService) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { return utils.RPCCall(sS, serviceMethod, args, reply) } @@ -305,7 +306,7 @@ func (sS *StatService) processThresholds(sQs StatQueues, opts map[string]any) (e thEv.Event[metricID] = metric.GetValue(sS.cgrcfg.GeneralCfg().RoundingDecimals) } var tIDs []string - if err := sS.connMgr.Call(sS.cgrcfg.StatSCfg().ThresholdSConns, nil, + if err := sS.connMgr.Call(context.TODO(), sS.cgrcfg.StatSCfg().ThresholdSConns, utils.ThresholdSv1ProcessEvent, thEv, &tIDs); err != nil && (len(thIDs) != 0 || err.Error() != utils.ErrNotFound.Error()) { utils.Logger.Warning( @@ -362,7 +363,7 @@ func (sS *StatService) processEvent(tnt string, args *utils.CGREvent) (statQueue } // V1ProcessEvent implements StatV1 method for processing an Event -func (sS *StatService) V1ProcessEvent(args *utils.CGREvent, reply *[]string) (err error) { +func (sS *StatService) V1ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) } @@ -384,7 +385,7 @@ func (sS *StatService) V1ProcessEvent(args *utils.CGREvent, reply *[]string) (er } // V1GetStatQueuesForEvent implements StatV1 method for processing an Event -func (sS *StatService) V1GetStatQueuesForEvent(args *utils.CGREvent, reply *[]string) (err error) { +func (sS *StatService) V1GetStatQueuesForEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) } @@ -421,7 +422,7 @@ func (sS *StatService) V1GetStatQueuesForEvent(args *utils.CGREvent, reply *[]st } // V1GetStatQueue returns a StatQueue object -func (sS *StatService) V1GetStatQueue(args *utils.TenantIDWithAPIOpts, reply *StatQueue) (err error) { +func (sS *StatService) V1GetStatQueue(ctx *context.Context, args *utils.TenantIDWithAPIOpts, reply *StatQueue) (err error) { if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -443,7 +444,7 @@ func (sS *StatService) V1GetStatQueue(args *utils.TenantIDWithAPIOpts, reply *St } // V1GetQueueStringMetrics returns the metrics of a Queue as string values -func (sS *StatService) V1GetQueueStringMetrics(args *utils.TenantID, reply *map[string]string) (err error) { +func (sS *StatService) V1GetQueueStringMetrics(ctx *context.Context, args *utils.TenantID, reply *map[string]string) (err error) { if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -472,7 +473,7 @@ func (sS *StatService) V1GetQueueStringMetrics(args *utils.TenantID, reply *map[ } // V1GetQueueFloatMetrics returns the metrics as float64 values -func (sS *StatService) V1GetQueueFloatMetrics(args *utils.TenantID, reply *map[string]float64) (err error) { +func (sS *StatService) V1GetQueueFloatMetrics(ctx *context.Context, args *utils.TenantID, reply *map[string]float64) (err error) { if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } @@ -501,7 +502,7 @@ func (sS *StatService) V1GetQueueFloatMetrics(args *utils.TenantID, reply *map[s } // V1GetQueueIDs returns list of queueIDs registered for a tenant -func (sS *StatService) V1GetQueueIDs(tenant string, qIDs *[]string) (err error) { +func (sS *StatService) V1GetQueueIDs(ctx *context.Context, tenant string, qIDs *[]string) (err error) { if tenant == utils.EmptyString { tenant = sS.cgrcfg.GeneralCfg().DefaultTenant } @@ -519,7 +520,7 @@ func (sS *StatService) V1GetQueueIDs(tenant string, qIDs *[]string) (err error) } // V1ResetStatQueue resets the stat queue -func (sS *StatService) V1ResetStatQueue(tntID *utils.TenantID, rply *string) (err error) { +func (sS *StatService) V1ResetStatQueue(ctx *context.Context, tntID *utils.TenantID, rply *string) (err error) { if missing := utils.MissingStructFields(tntID, []string{utils.ID}); len(missing) != 0 { //Params missing return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/engine/stats_test.go b/engine/stats_test.go index 597f52684..6cbe95261 100644 --- a/engine/stats_test.go +++ b/engine/stats_test.go @@ -28,9 +28,10 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) var ( @@ -307,37 +308,49 @@ func TestStatQueuesProcessEvent(t *testing.T) { stq := map[string]string{} reply := []string{} expected := []string{"StatQueueProfile1"} - err := statService.V1ProcessEvent(testStatsArgs[0], &reply) + err := statService.V1ProcessEvent(context.Background(), testStatsArgs[0], &reply) if err != nil { t.Errorf("Error: %+v", err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) } - err = statService.V1GetQueueStringMetrics(&utils.TenantID{Tenant: testStatsQ[0].Tenant, ID: testStatsQ[0].ID}, &stq) + err = statService.V1GetQueueStringMetrics(context.Background(), + &utils.TenantID{ + Tenant: testStatsQ[0].Tenant, + ID: testStatsQ[0].ID, + }, &stq) if err != nil { t.Errorf("Error: %+v", err) } expected = []string{"StatQueueProfile2"} - err = statService.V1ProcessEvent(testStatsArgs[1], &reply) + err = statService.V1ProcessEvent(context.Background(), testStatsArgs[1], &reply) if err != nil { t.Errorf("Error: %+v", err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) } - err = statService.V1GetQueueStringMetrics(&utils.TenantID{Tenant: testStatsQ[1].Tenant, ID: testStatsQ[1].ID}, &stq) + err = statService.V1GetQueueStringMetrics(context.Background(), + &utils.TenantID{ + Tenant: testStatsQ[1].Tenant, + ID: testStatsQ[1].ID, + }, &stq) if err != nil { t.Errorf("Error: %+v", err) } expected = []string{"StatQueueProfilePrefix"} - err = statService.V1ProcessEvent(testStatsArgs[2], &reply) + err = statService.V1ProcessEvent(context.Background(), testStatsArgs[2], &reply) if err != nil { t.Errorf("Error: %+v", err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) } - err = statService.V1GetQueueStringMetrics(&utils.TenantID{Tenant: testStatsQ[2].Tenant, ID: testStatsQ[2].ID}, &stq) + err = statService.V1GetQueueStringMetrics(context.Background(), + &utils.TenantID{ + Tenant: testStatsQ[2].Tenant, + ID: testStatsQ[2].ID, + }, &stq) if err != nil { t.Errorf("Error: %+v", err) } @@ -458,7 +471,7 @@ func TestStatQueuesV1ProcessEvent(t *testing.T) { reply := []string{} expected := []string{"StatQueueProfile1", "StatQueueProfile3"} expectedRev := []string{"StatQueueProfile3", "StatQueueProfile1"} - if err := statService.V1ProcessEvent(ev, &reply); err != nil { + if err := statService.V1ProcessEvent(context.Background(), ev, &reply); err != nil { t.Errorf("Error: %+v", err) } else if !reflect.DeepEqual(reply, expected) && !reflect.DeepEqual(reply, expectedRev) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -1438,7 +1451,7 @@ func TestStatQueueV1ProcessEventProcessEventErr(t *testing.T) { } var reply []string - if err := sS.V1ProcessEvent(args, &reply); err == nil || + if err := sS.V1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != utils.ErrPartiallyExecuted.Error() { t.Errorf("expected: <%+v>, received: <%+v>", utils.ErrPartiallyExecuted, err) } @@ -1498,7 +1511,7 @@ func TestStatQueueV1ProcessEventMissingArgs(t *testing.T) { var reply []string experr := `MANDATORY_IE_MISSING: [CGREvent]` - if err := sS.V1ProcessEvent(nil, &reply); err == nil || + if err := sS.V1ProcessEvent(context.Background(), nil, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } @@ -1514,7 +1527,7 @@ func TestStatQueueV1ProcessEventMissingArgs(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [ID]` - if err := sS.V1ProcessEvent(args, &reply); err == nil || + if err := sS.V1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } @@ -1529,7 +1542,7 @@ func TestStatQueueV1ProcessEventMissingArgs(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [Event]` - if err := sS.V1ProcessEvent(args, &reply); err == nil || + if err := sS.V1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } @@ -1606,7 +1619,7 @@ func TestStatQueueV1GetQueueIDsOK(t *testing.T) { expIDs := []string{"SQ1", "SQ3"} var qIDs []string - if err := sS.V1GetQueueIDs(utils.EmptyString, &qIDs); err != nil { + if err := sS.V1GetQueueIDs(context.Background(), utils.EmptyString, &qIDs); err != nil { t.Error(err) } else { sort.Strings(qIDs) @@ -1630,7 +1643,7 @@ func TestStatQueueV1GetQueueIDsGetKeysForPrefixErr(t *testing.T) { sS := NewStatService(dm, cfg, filterS, nil) var qIDs []string - if err := sS.V1GetQueueIDs(utils.EmptyString, &qIDs); err == nil || + if err := sS.V1GetQueueIDs(context.Background(), utils.EmptyString, &qIDs); err == nil || err.Error() != utils.ErrNotImplemented.Error() { t.Errorf("expected: <%+v>, received: <%+v>", utils.ErrNotImplemented, err) } @@ -1689,11 +1702,12 @@ func TestStatQueueV1GetStatQueueOK(t *testing.T) { } var reply StatQueue - if err := sS.V1GetStatQueue(&utils.TenantIDWithAPIOpts{ - TenantID: &utils.TenantID{ - ID: "SQ1", - }, - }, &reply); err != nil { + if err := sS.V1GetStatQueue(context.Background(), + &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + ID: "SQ1", + }, + }, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, *sq) { t.Errorf("expected: <%+v>, received: <%+v>", @@ -1715,11 +1729,12 @@ func TestStatQueueV1GetStatQueueNotFound(t *testing.T) { sS := NewStatService(dm, cfg, filterS, nil) var reply StatQueue - if err := sS.V1GetStatQueue(&utils.TenantIDWithAPIOpts{ - TenantID: &utils.TenantID{ - ID: "SQ1", - }, - }, &reply); err == nil || err != utils.ErrNotFound { + if err := sS.V1GetStatQueue(context.Background(), + &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{ + ID: "SQ1", + }, + }, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, received: <%+v>", utils.ErrNotFound, err) } } @@ -1778,9 +1793,10 @@ func TestStatQueueV1GetStatQueueMissingArgs(t *testing.T) { experr := `MANDATORY_IE_MISSING: [ID]` var reply StatQueue - if err := sS.V1GetStatQueue(&utils.TenantIDWithAPIOpts{ - TenantID: &utils.TenantID{}, - }, &reply); err == nil || err.Error() != experr { + if err := sS.V1GetStatQueue(context.Background(), + &utils.TenantIDWithAPIOpts{ + TenantID: &utils.TenantID{}, + }, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } } @@ -1852,7 +1868,7 @@ func TestStatQueueV1GetStatQueuesForEventOK(t *testing.T) { exp := []string{"SQ1", "SQ2"} var reply []string - if err := sS.V1GetStatQueuesForEvent(args, &reply); err != nil { + if err := sS.V1GetStatQueuesForEvent(context.Background(), args, &reply); err != nil { t.Error(err) } else { sort.Strings(reply) @@ -1906,7 +1922,7 @@ func TestStatQueueV1GetStatQueuesForEventNotFoundErr(t *testing.T) { } var reply []string - if err := sS.V1GetStatQueuesForEvent(args, &reply); err == nil || + if err := sS.V1GetStatQueuesForEvent(context.Background(), args, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, received: <%+v>", utils.ErrNotFound, err) } @@ -1950,7 +1966,7 @@ func TestStatQueueV1GetStatQueuesForEventMissingArgs(t *testing.T) { experr := `MANDATORY_IE_MISSING: [CGREvent]` var reply []string - if err := sS.V1GetStatQueuesForEvent(nil, &reply); err == nil || + if err := sS.V1GetStatQueuesForEvent(context.Background(), nil, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } @@ -1964,7 +1980,7 @@ func TestStatQueueV1GetStatQueuesForEventMissingArgs(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [ID]` - if err := sS.V1GetStatQueuesForEvent(args, &reply); err == nil || + if err := sS.V1GetStatQueuesForEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } @@ -1976,7 +1992,7 @@ func TestStatQueueV1GetStatQueuesForEventMissingArgs(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [Event]` - if err := sS.V1GetStatQueuesForEvent(args, &reply); err == nil || + if err := sS.V1GetStatQueuesForEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } @@ -2053,9 +2069,10 @@ func TestStatQueueV1ResetStatQueueOK(t *testing.T) { } var reply string - if err := sS.V1ResetStatQueue(&utils.TenantID{ - ID: "SQ1", - }, &reply); err != nil { + if err := sS.V1ResetStatQueue(context.Background(), + &utils.TenantID{ + ID: "SQ1", + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply returned: <%q>", reply) @@ -2121,9 +2138,10 @@ func TestStatQueueV1ResetStatQueueNotFoundErr(t *testing.T) { } var reply string - if err := sS.V1ResetStatQueue(&utils.TenantID{ - ID: "SQ2", - }, &reply); err == nil || err != utils.ErrNotFound { + if err := sS.V1ResetStatQueue(context.Background(), + &utils.TenantID{ + ID: "SQ2", + }, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, received: <%+v>", utils.ErrNotFound, err) } } @@ -2184,7 +2202,7 @@ func TestStatQueueV1ResetStatQueueMissingArgs(t *testing.T) { experr := `MANDATORY_IE_MISSING: [ID]` var reply string - if err := sS.V1ResetStatQueue(&utils.TenantID{}, &reply); err == nil || + if err := sS.V1ResetStatQueue(context.Background(), &utils.TenantID{}, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } @@ -2247,9 +2265,10 @@ func TestStatQueueV1ResetStatQueueUnsupportedMetricType(t *testing.T) { experr := `unsupported metric type ` var reply string - if err := sS.V1ResetStatQueue(&utils.TenantID{ - ID: "SQ1", - }, &reply); err == nil || err.Error() != experr { + if err := sS.V1ResetStatQueue(context.Background(), + &utils.TenantID{ + ID: "SQ1", + }, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } } @@ -2335,8 +2354,8 @@ func TestStatQueueProcessThresholdsOK(t *testing.T) { Cache.Clear(nil) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ThresholdSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { exp := &utils.CGREvent{ Tenant: "cgrates.org", ID: args.(*utils.CGREvent).ID, @@ -2358,9 +2377,9 @@ func TestStatQueueProcessThresholdsOK(t *testing.T) { }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM - connMgr = NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr = NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): rpcInternal, }) @@ -2443,15 +2462,15 @@ func TestStatQueueProcessThresholdsErrPartExec(t *testing.T) { Cache.Clear(nil) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ThresholdSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { return utils.ErrExists }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM - connMgr = NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr = NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): rpcInternal, }) @@ -2569,9 +2588,10 @@ func TestStatQueueV1GetQueueFloatMetricsOK(t *testing.T) { utils.MetaTCD: 3600000000000, } reply := map[string]float64{} - if err := sS.V1GetQueueFloatMetrics(&utils.TenantID{ - ID: "SQ1", - }, &reply); err != nil { + if err := sS.V1GetQueueFloatMetrics(context.Background(), + &utils.TenantID{ + ID: "SQ1", + }, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("expected: <%+v>, received: <%+v>", expected, reply) @@ -2633,9 +2653,10 @@ func TestStatQueueV1GetQueueFloatMetricsErrNotFound(t *testing.T) { } reply := map[string]float64{} - if err := sS.V1GetQueueFloatMetrics(&utils.TenantID{ - ID: "SQ2", - }, &reply); err == nil || err != utils.ErrNotFound { + if err := sS.V1GetQueueFloatMetrics(context.Background(), + &utils.TenantID{ + ID: "SQ2", + }, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, received: <%+v>", utils.ErrNotFound, err) } } @@ -2696,7 +2717,7 @@ func TestStatQueueV1GetQueueFloatMetricsMissingArgs(t *testing.T) { experr := `MANDATORY_IE_MISSING: [ID]` reply := map[string]float64{} - if err := sS.V1GetQueueFloatMetrics(&utils.TenantID{}, &reply); err == nil || + if err := sS.V1GetQueueFloatMetrics(context.Background(), &utils.TenantID{}, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } @@ -2716,9 +2737,10 @@ func TestStatQueueV1GetQueueFloatMetricsErrGetStats(t *testing.T) { experr := `SERVER_ERROR: NO_DATABASE_CONNECTION` reply := map[string]float64{} - if err := sS.V1GetQueueFloatMetrics(&utils.TenantID{ - ID: "SQ1", - }, &reply); err == nil || err.Error() != experr { + if err := sS.V1GetQueueFloatMetrics(context.Background(), + &utils.TenantID{ + ID: "SQ1", + }, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } } @@ -2781,9 +2803,10 @@ func TestStatQueueV1GetQueueStringMetricsOK(t *testing.T) { utils.MetaTCD: "1h0m0s", } reply := map[string]string{} - if err := sS.V1GetQueueStringMetrics(&utils.TenantID{ - ID: "SQ1", - }, &reply); err != nil { + if err := sS.V1GetQueueStringMetrics(context.Background(), + &utils.TenantID{ + ID: "SQ1", + }, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("expected: <%+v>, received: <%+v>", expected, reply) @@ -2845,9 +2868,10 @@ func TestStatQueueV1GetQueueStringMetricsErrNotFound(t *testing.T) { } reply := map[string]string{} - if err := sS.V1GetQueueStringMetrics(&utils.TenantID{ - ID: "SQ2", - }, &reply); err == nil || err != utils.ErrNotFound { + if err := sS.V1GetQueueStringMetrics(context.Background(), + &utils.TenantID{ + ID: "SQ2", + }, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, received: <%+v>", utils.ErrNotFound, err) } } @@ -2908,7 +2932,7 @@ func TestStatQueueV1GetQueueStringMetricsMissingArgs(t *testing.T) { experr := `MANDATORY_IE_MISSING: [ID]` reply := map[string]string{} - if err := sS.V1GetQueueStringMetrics(&utils.TenantID{}, &reply); err == nil || + if err := sS.V1GetQueueStringMetrics(context.Background(), &utils.TenantID{}, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } @@ -2928,9 +2952,10 @@ func TestStatQueueV1GetQueueStringMetricsErrGetStats(t *testing.T) { experr := `SERVER_ERROR: NO_DATABASE_CONNECTION` reply := map[string]string{} - if err := sS.V1GetQueueStringMetrics(&utils.TenantID{ - ID: "SQ1", - }, &reply); err == nil || err.Error() != experr { + if err := sS.V1GetQueueStringMetrics(context.Background(), + &utils.TenantID{ + ID: "SQ1", + }, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, received: <%+v>", experr, err) } } @@ -2948,7 +2973,7 @@ func TestStatQueueStoreStatQueueStoreIntervalDisabled(t *testing.T) { config.SetCgrConfig(cfg) data := NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) dm := NewDataManager(data, cfg.CacheCfg(), nil) - connMgr = NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector)) + connMgr = NewConnManager(cfg, make(map[string]chan birpc.ClientConnector)) Cache.Clear(nil) filterS := NewFilterS(cfg, nil, dm) sS := NewStatService(dm, cfg, filterS, connMgr) @@ -3034,75 +3059,6 @@ func TestStatQueueGetStatQueueOK(t *testing.T) { } } -func TestStatQueueCall(t *testing.T) { - tmpC := config.CgrConfig() - defer func() { - config.SetCgrConfig(tmpC) - }() - - cfg := config.NewDefaultCGRConfig() - data := NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) - dm := NewDataManager(data, cfg.CacheCfg(), nil) - Cache.Clear(nil) - filterS := NewFilterS(cfg, nil, dm) - sS := NewStatService(dm, cfg, filterS, nil) - - sqPrf := &StatQueueProfile{ - Tenant: "cgrates.org", - ID: "SQ1", - FilterIDs: []string{"*string:~*req.Account:1001"}, - ActivationInterval: &utils.ActivationInterval{ - ExpiryTime: time.Date(2021, 6, 1, 12, 0, 0, 0, time.UTC), - }, - Weight: 10, - Blocker: true, - QueueLength: 10, - ThresholdIDs: []string{"*none"}, - MinItems: 5, - Metrics: []*MetricWithFilters{ - { - MetricID: utils.MetaTCD, - }, - }, - } - sq := &StatQueue{ - sqPrfl: sqPrf, - dirty: utils.BoolPointer(false), - Tenant: "cgrates.org", - ID: "SQ1", - SQItems: []SQItem{ - { - EventID: "SqProcessEvent", - ExpiryTime: utils.TimePointer(time.Now()), - }, - }, - SQMetrics: map[string]StatMetric{ - utils.MetaTCD: &StatTCD{ - Sum: time.Minute, - val: utils.DurationPointer(time.Hour), - }, - }, - } - - if err := dm.SetStatQueue(sq); err != nil { - t.Error(err) - } - - args := &utils.TenantIDWithAPIOpts{ - TenantID: &utils.TenantID{ - Tenant: "cgrates.org", - ID: "SQ1", - }, - } - var reply StatQueue - if err := sS.Call(utils.StatSv1GetStatQueue, args, &reply); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(reply, *sq) { - t.Errorf("expected: <%+v>, received: <%+v>", - utils.ToJSON(*sq), utils.ToJSON(reply)) - } -} - func TestStatQueueStoreStatQueueCacheSetErr(t *testing.T) { utils.Logger.SetLogLevel(4) utils.Logger.SetSyslog(nil) @@ -3127,7 +3083,7 @@ func TestStatQueueStoreStatQueueCacheSetErr(t *testing.T) { config.SetCgrConfig(cfg) data := NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) dm := NewDataManager(data, cfg.CacheCfg(), nil) - connMgr = NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector)) + connMgr = NewConnManager(cfg, make(map[string]chan birpc.ClientConnector)) Cache = NewCacheS(cfg, dm, nil) filterS := NewFilterS(cfg, connMgr, dm) sS := NewStatService(dm, cfg, filterS, connMgr) @@ -3213,7 +3169,7 @@ func TestStatQueueV1GetStatQueuesForSliceOptsErr(t *testing.T) { }, } var reply []string - if err := sS.V1GetStatQueuesForEvent(args, &reply); err == nil { + if err := sS.V1GetStatQueuesForEvent(context.Background(), args, &reply); err == nil { t.Error(err) } } @@ -3281,7 +3237,7 @@ func TestStatQueueV1GetStatQueuesForEventBoolOptsErr(t *testing.T) { }, } var reply []string - if err := sS.V1GetStatQueuesForEvent(args, &reply); err == nil { + if err := sS.V1GetStatQueuesForEvent(context.Background(), args, &reply); err == nil { t.Error(err) } } diff --git a/engine/thresholds.go b/engine/thresholds.go index ee624239c..fda8a5a91 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -25,6 +25,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" @@ -482,7 +483,7 @@ func (tS *ThresholdService) processEvent(tnt string, args *utils.CGREvent) (thre } // V1ProcessEvent implements ThresholdService method for processing an Event -func (tS *ThresholdService) V1ProcessEvent(args *utils.CGREvent, reply *[]string) (err error) { +func (tS *ThresholdService) V1ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) } @@ -504,7 +505,7 @@ func (tS *ThresholdService) V1ProcessEvent(args *utils.CGREvent, reply *[]string } // V1GetThresholdsForEvent queries thresholds matching an Event -func (tS *ThresholdService) V1GetThresholdsForEvent(args *utils.CGREvent, reply *Thresholds) (err error) { +func (tS *ThresholdService) V1GetThresholdsForEvent(ctx *context.Context, args *utils.CGREvent, reply *Thresholds) (err error) { if args == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) } @@ -526,7 +527,7 @@ func (tS *ThresholdService) V1GetThresholdsForEvent(args *utils.CGREvent, reply } // V1GetThresholdIDs returns list of thresholdIDs configured for a tenant -func (tS *ThresholdService) V1GetThresholdIDs(tenant string, tIDs *[]string) (err error) { +func (tS *ThresholdService) V1GetThresholdIDs(ctx *context.Context, tenant string, tIDs *[]string) (err error) { if tenant == utils.EmptyString { tenant = tS.cgrcfg.GeneralCfg().DefaultTenant } @@ -544,7 +545,7 @@ func (tS *ThresholdService) V1GetThresholdIDs(tenant string, tIDs *[]string) (er } // V1GetThreshold retrieves a Threshold -func (tS *ThresholdService) V1GetThreshold(tntID *utils.TenantID, t *Threshold) (err error) { +func (tS *ThresholdService) V1GetThreshold(ctx *context.Context, tntID *utils.TenantID, t *Threshold) (err error) { var thd *Threshold tnt := tntID.Tenant if tnt == utils.EmptyString { @@ -563,7 +564,7 @@ func (tS *ThresholdService) V1GetThreshold(tntID *utils.TenantID, t *Threshold) } // V1ResetThreshold resets the threshold hits -func (tS *ThresholdService) V1ResetThreshold(tntID *utils.TenantID, rply *string) (err error) { +func (tS *ThresholdService) V1ResetThreshold(ctx *context.Context, tntID *utils.TenantID, rply *string) (err error) { var thd *Threshold tnt := tntID.Tenant if tnt == utils.EmptyString { diff --git a/engine/thresholds_test.go b/engine/thresholds_test.go index 3d530465f..e1a3ef1c7 100644 --- a/engine/thresholds_test.go +++ b/engine/thresholds_test.go @@ -28,9 +28,10 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) var ( @@ -972,7 +973,7 @@ func TestThresholdsProcessEventMaxHitsDMErr(t *testing.T) { cfg.CacheCfg().Partitions[utils.CacheThresholds].Replicate = true config.SetCgrConfig(cfg) data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr = NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector)) + connMgr = NewConnManager(cfg, make(map[string]chan birpc.ClientConnector)) dm := NewDataManager(data, cfg.CacheCfg(), connMgr) filterS := NewFilterS(cfg, nil, dm) tS := NewThresholdService(nil, cfg, filterS) @@ -1133,7 +1134,7 @@ func TestThresholdsV1ProcessEventOK(t *testing.T) { } var reply []string exp := []string{"TH1", "TH2"} - if err := tS.V1ProcessEvent(args, &reply); err != nil { + if err := tS.V1ProcessEvent(context.Background(), args, &reply); err != nil { t.Error(err) } else { sort.Strings(reply) @@ -1195,7 +1196,7 @@ func TestThresholdsV1ProcessEventPartExecErr(t *testing.T) { expLog1 := `[ERROR] Failed to get actions for ACT1: NOT_FOUND` expLog2 := `[WARNING] failed executing actions: ACT1, error: NOT_FOUND` var reply []string - if err := tS.V1ProcessEvent(args, &reply); err == nil || + if err := tS.V1ProcessEvent(context.Background(), args, &reply); err == nil || err != utils.ErrPartiallyExecuted { t.Errorf("expected: <%+v>,\nreceived: <%+v>", utils.ErrPartiallyExecuted, err) } else { @@ -1256,13 +1257,13 @@ func TestThresholdsV1ProcessEventMissingArgs(t *testing.T) { } var reply []string experr := `MANDATORY_IE_MISSING: [ID]` - if err := tS.V1ProcessEvent(args, &reply); err == nil || + if err := tS.V1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } experr = `MANDATORY_IE_MISSING: [CGREvent]` - if err := tS.V1ProcessEvent(nil, &reply); err == nil || + if err := tS.V1ProcessEvent(context.Background(), nil, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -1272,7 +1273,7 @@ func TestThresholdsV1ProcessEventMissingArgs(t *testing.T) { Event: nil, } experr = `MANDATORY_IE_MISSING: [Event]` - if err := tS.V1ProcessEvent(args, &reply); err == nil || + if err := tS.V1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -1305,9 +1306,10 @@ func TestThresholdsV1GetThresholdOK(t *testing.T) { ID: "TH1", } var rplyTh Threshold - if err := tS.V1GetThreshold(&utils.TenantID{ - ID: "TH1", - }, &rplyTh); err != nil { + if err := tS.V1GetThreshold(context.Background(), + &utils.TenantID{ + ID: "TH1", + }, &rplyTh); err != nil { t.Error(err) } else { var snooze time.Time @@ -1343,9 +1345,10 @@ func TestThresholdsV1GetThresholdNotFoundErr(t *testing.T) { } var rplyTh Threshold - if err := tS.V1GetThreshold(&utils.TenantID{ - ID: "TH2", - }, &rplyTh); err == nil || err != utils.ErrNotFound { + if err := tS.V1GetThreshold(context.Background(), + &utils.TenantID{ + ID: "TH2", + }, &rplyTh); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } } @@ -1681,7 +1684,7 @@ func TestThresholdMatchingThresholdForEventLocks5(t *testing.T) { }() Cache.Clear(nil) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - dm := NewDataManager(db, config.CgrConfig().CacheCfg(), NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector))) + dm := NewDataManager(db, config.CgrConfig().CacheCfg(), NewConnManager(cfg, make(map[string]chan birpc.ClientConnector))) cfg.ThresholdSCfg().StoreInterval = 1 cfg.ThresholdSCfg().StringIndexedFields = nil cfg.ThresholdSCfg().PrefixIndexedFields = nil @@ -1885,7 +1888,7 @@ func TestThresholdsV1GetThresholdsForEventOK(t *testing.T) { }, } var reply Thresholds - if err := tS.V1GetThresholdsForEvent(args, &reply); err != nil { + if err := tS.V1GetThresholdsForEvent(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, exp) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", exp, reply) @@ -1919,7 +1922,7 @@ func TestThresholdsV1GetThresholdsForEventMissingArgs(t *testing.T) { } experr := `MANDATORY_IE_MISSING: [CGREvent]` var reply Thresholds - if err := tS.V1GetThresholdsForEvent(nil, &reply); err == nil || + if err := tS.V1GetThresholdsForEvent(context.Background(), nil, &reply); err == nil || err.Error() != experr { t.Error(err) } @@ -1935,7 +1938,7 @@ func TestThresholdsV1GetThresholdsForEventMissingArgs(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [ID]` - if err := tS.V1GetThresholdsForEvent(args, &reply); err == nil || + if err := tS.V1GetThresholdsForEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Error(err) } @@ -1950,7 +1953,7 @@ func TestThresholdsV1GetThresholdsForEventMissingArgs(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [Event]` - if err := tS.V1GetThresholdsForEvent(args, &reply); err == nil || + if err := tS.V1GetThresholdsForEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Error(err) } @@ -1996,7 +1999,7 @@ func TestThresholdsV1GetThresholdIDsOK(t *testing.T) { expIDs := []string{"TH1", "TH2"} var reply []string - if err := tS.V1GetThresholdIDs("", &reply); err != nil { + if err := tS.V1GetThresholdIDs(context.Background(), "", &reply); err != nil { t.Error(err) } else { sort.Strings(reply) @@ -2020,7 +2023,7 @@ func TestThresholdsV1GetThresholdIDsGetKeysForPrefixErr(t *testing.T) { tS := NewThresholdService(dm, cfg, filterS) var reply []string - if err := tS.V1GetThresholdIDs("", &reply); err == nil || + if err := tS.V1GetThresholdIDs(context.Background(), "", &reply); err == nil || err != utils.ErrNotImplemented { t.Error(err) } @@ -2064,9 +2067,10 @@ func TestThresholdsV1ResetThresholdOK(t *testing.T) { "cgrates.org:TH1": {}, } var reply string - if err := tS.V1ResetThreshold(&utils.TenantID{ - ID: "TH1", - }, &reply); err != nil { + if err := tS.V1ResetThreshold(context.Background(), + &utils.TenantID{ + ID: "TH1", + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply returned: <%q>", reply) @@ -2112,9 +2116,10 @@ func TestThresholdsV1ResetThresholdErrNotFound(t *testing.T) { } var reply string - if err := tS.V1ResetThreshold(&utils.TenantID{ - ID: "TH1", - }, &reply); err == nil || err != utils.ErrNotFound { + if err := tS.V1ResetThreshold(context.Background(), + &utils.TenantID{ + ID: "TH1", + }, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } } @@ -2155,9 +2160,10 @@ func TestThresholdsV1ResetThresholdNegativeStoreIntervalOK(t *testing.T) { } var reply string - if err := tS.V1ResetThreshold(&utils.TenantID{ - ID: "TH1", - }, &reply); err != nil { + if err := tS.V1ResetThreshold(context.Background(), + &utils.TenantID{ + ID: "TH1", + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply returned: <%q>", reply) @@ -2202,9 +2208,10 @@ func TestThresholdsV1ResetThresholdNegativeStoreIntervalErr(t *testing.T) { } var reply string - if err := tS.V1ResetThreshold(&utils.TenantID{ - ID: "TH1", - }, &reply); err == nil || err != utils.ErrNoDatabaseConn { + if err := tS.V1ResetThreshold(context.Background(), + &utils.TenantID{ + ID: "TH1", + }, &reply); err == nil || err != utils.ErrNoDatabaseConn { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNoDatabaseConn, err) } } @@ -2344,7 +2351,7 @@ func TestThresholdsStoreThresholdCacheSetErr(t *testing.T) { config.SetCgrConfig(cfg) data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(data, cfg.CacheCfg(), nil) - connMgr = NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector)) + connMgr = NewConnManager(cfg, make(map[string]chan birpc.ClientConnector)) Cache = NewCacheS(cfg, dm, nil) filterS := NewFilterS(cfg, nil, dm) tS := NewThresholdService(dm, cfg, filterS) diff --git a/engine/tpreader.go b/engine/tpreader.go index 7b7c85eff..e5f157103 100644 --- a/engine/tpreader.go +++ b/engine/tpreader.go @@ -26,6 +26,7 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -784,7 +785,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *utils.TPAccountActions) return err } var reply string - if err := connMgr.Call(tpr.cacheConns, nil, + if err := connMgr.Call(context.TODO(), tpr.cacheConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ AccountActionPlanIDs: []string{id}, ActionPlanIDs: []string{accountAction.ActionPlanId}, @@ -891,7 +892,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *utils.TPAccountActions) return errors.New(err.Error() + " (SetActionTriggers): " + accountAction.ActionTriggersId) } var reply string - if err := connMgr.Call(tpr.cacheConns, nil, + if err := connMgr.Call(context.TODO(), tpr.cacheConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ActionTriggerIDs: []string{accountAction.ActionTriggersId}, }, &reply); err != nil { @@ -1009,7 +1010,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *utils.TPAccountActions) return err } var reply string - if err := connMgr.Call(tpr.cacheConns, nil, + if err := connMgr.Call(context.TODO(), tpr.cacheConns, utils.CacheSv1ReloadCache, &utils.AttrReloadCacheWithAPIOpts{ ActionIDs: []string{k}, }, &reply); err != nil { @@ -2340,7 +2341,7 @@ func CallCache(connMgr *ConnManager, cacheConns []string, caching string, args m log.Print("Reloading cache") } - if err = connMgr.Call(cacheConns, nil, method, cacheArgs, &reply); err != nil { + if err = connMgr.Call(context.TODO(), cacheConns, method, cacheArgs, &reply); err != nil { return } @@ -2348,7 +2349,7 @@ func CallCache(connMgr *ConnManager, cacheConns []string, caching string, args m if verbose { log.Print("Clearing indexes") } - if err = connMgr.Call(cacheConns, nil, utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err = connMgr.Call(context.TODO(), cacheConns, utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ APIOpts: opts, CacheIDs: cacheIDs, Tenant: tenant, @@ -2371,7 +2372,7 @@ func (tpr *TpReader) ReloadScheduler(verbose bool) (err error) { if verbose { log.Print("Reloading scheduler") } - if err = connMgr.Call(tpr.schedulerConns, nil, utils.SchedulerSv1Reload, + if err = connMgr.Call(context.TODO(), tpr.schedulerConns, utils.SchedulerSv1Reload, new(utils.CGREvent), &reply); err != nil { log.Printf("WARNING: Got error on scheduler reload: %s\n", err.Error()) } diff --git a/engine/tpreader_test.go b/engine/tpreader_test.go index 1ce315fc7..2589ac2a2 100644 --- a/engine/tpreader_test.go +++ b/engine/tpreader_test.go @@ -29,10 +29,11 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/ltcache" - "github.com/cgrates/rpcclient" ) func TestTPReaderCallCacheNoCaching(t *testing.T) { @@ -69,10 +70,10 @@ func TestTPReaderCallCacheReloadCacheFirstCallErr(t *testing.T) { cfg := config.NewDefaultCGRConfig() Cache.Clear(nil) cacheConns := []string{"cacheConn1"} - client := make(chan rpcclient.ClientConnector, 1) + client := make(chan birpc.ClientConnector, 1) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReloadCache: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReloadCache: func(ctx *context.Context, args, reply any) error { expArgs := &utils.AttrReloadCacheWithAPIOpts{ APIOpts: map[string]any{ utils.MetaSubsys: utils.MetaChargers, @@ -93,7 +94,7 @@ func TestTPReaderCallCacheReloadCacheFirstCallErr(t *testing.T) { } client <- ccM - cM := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + cM := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ "cacheConn1": client, }) caching := utils.MetaReload @@ -134,13 +135,13 @@ func TestTPReaderCallCacheReloadCacheSecondCallErr(t *testing.T) { cfg := config.NewDefaultCGRConfig() Cache.Clear(nil) cacheConns := []string{"cacheConn1"} - client := make(chan rpcclient.ClientConnector, 1) + client := make(chan birpc.ClientConnector, 1) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReloadCache: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReloadCache: func(ctx *context.Context, args, reply any) error { return nil }, - utils.CacheSv1Clear: func(args, reply any) error { + utils.CacheSv1Clear: func(ctx *context.Context, args, reply any) error { expArgs := &utils.AttrCacheIDsWithAPIOpts{ APIOpts: map[string]any{ utils.MetaSubsys: utils.MetaChargers, @@ -161,7 +162,7 @@ func TestTPReaderCallCacheReloadCacheSecondCallErr(t *testing.T) { } client <- ccM - cM := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + cM := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ "cacheConn1": client, }) caching := utils.MetaReload @@ -214,10 +215,10 @@ func TestTPReaderCallCacheLoadCache(t *testing.T) { cfg := config.NewDefaultCGRConfig() Cache.Clear(nil) cacheConns := []string{"cacheConn1"} - client := make(chan rpcclient.ClientConnector, 1) + client := make(chan birpc.ClientConnector, 1) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1LoadCache: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1LoadCache: func(ctx *context.Context, args, reply any) error { expArgs := &utils.AttrReloadCacheWithAPIOpts{ APIOpts: map[string]any{ utils.MetaSubsys: utils.MetaChargers, @@ -234,7 +235,7 @@ func TestTPReaderCallCacheLoadCache(t *testing.T) { } return nil }, - utils.CacheSv1Clear: func(args, reply any) error { + utils.CacheSv1Clear: func(ctx *context.Context, args, reply any) error { expArgs := &utils.AttrCacheIDsWithAPIOpts{ APIOpts: map[string]any{ utils.MetaSubsys: utils.MetaChargers, @@ -255,7 +256,7 @@ func TestTPReaderCallCacheLoadCache(t *testing.T) { } client <- ccM - cM := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + cM := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ "cacheConn1": client, }) caching := utils.MetaLoad @@ -283,10 +284,10 @@ func TestTPReaderCallCacheRemoveItems(t *testing.T) { cfg := config.NewDefaultCGRConfig() Cache.Clear(nil) cacheConns := []string{"cacheConn1"} - client := make(chan rpcclient.ClientConnector, 1) + client := make(chan birpc.ClientConnector, 1) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1RemoveItems: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1RemoveItems: func(ctx *context.Context, args, reply any) error { expArgs := &utils.AttrReloadCacheWithAPIOpts{ APIOpts: map[string]any{ utils.MetaSubsys: utils.MetaChargers, @@ -303,7 +304,7 @@ func TestTPReaderCallCacheRemoveItems(t *testing.T) { } return nil }, - utils.CacheSv1Clear: func(args, reply any) error { + utils.CacheSv1Clear: func(ctx *context.Context, args, reply any) error { expArgs := &utils.AttrCacheIDsWithAPIOpts{ APIOpts: map[string]any{ utils.MetaSubsys: utils.MetaChargers, @@ -324,7 +325,7 @@ func TestTPReaderCallCacheRemoveItems(t *testing.T) { } client <- ccM - cM := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + cM := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ "cacheConn1": client, }) caching := utils.MetaRemove @@ -352,10 +353,10 @@ func TestTPReaderCallCacheClear(t *testing.T) { cfg := config.NewDefaultCGRConfig() Cache.Clear(nil) cacheConns := []string{"cacheConn1"} - client := make(chan rpcclient.ClientConnector, 1) + client := make(chan birpc.ClientConnector, 1) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1Clear: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1Clear: func(ctx *context.Context, args, reply any) error { expArgs := &utils.AttrCacheIDsWithAPIOpts{ APIOpts: map[string]any{ utils.MetaSubsys: utils.MetaChargers, @@ -375,7 +376,7 @@ func TestTPReaderCallCacheClear(t *testing.T) { } client <- ccM - cM := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + cM := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ "cacheConn1": client, }) caching := utils.MetaClear @@ -950,23 +951,23 @@ func TestTPReaderReloadCache(t *testing.T) { AccountActionPlanIDs: []string{"AccountActionPlansID"}, ReverseDestinationIDs: []string{}, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.CacheSv1ReloadCache: func(args any, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.CacheSv1ReloadCache: func(ctx *context.Context, args any, reply any) error { if !reflect.DeepEqual(args, argExpect) { t.Errorf("Expected %v \nbut received %v", utils.ToJSON(argExpect), utils.ToJSON(args)) } return nil }, - utils.CacheSv1Clear: func(args any, reply any) error { + utils.CacheSv1Clear: func(ctx *context.Context, args any, reply any) error { return nil }, }, } tmp := connMgr defer func() { connMgr = tmp }() - connMgr = NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr = NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) tpr := &TpReader{ @@ -1087,8 +1088,8 @@ func TestTPReaderLoadAll(t *testing.T) { func TestTpReaderReloadScheduler(t *testing.T) { cfg := config.NewDefaultCGRConfig() ccMocK := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.SchedulerSv1Reload: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.SchedulerSv1Reload: func(ctx *context.Context, args, reply any) error { rpl := "reply" *reply.(*string) = rpl @@ -1096,12 +1097,12 @@ func TestTpReaderReloadScheduler(t *testing.T) { }, }, } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- ccMocK tmp := connMgr defer func() { connMgr = tmp }() - connMgr = NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr = NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.SchedulerConnsCfg): clientconn, }) @@ -2214,7 +2215,7 @@ func TestTprLoadAccountActionFiltered(t *testing.T) { if err != nil { t.Error(err) } - clientconn := make(chan rpcclient.ClientConnector, 1) + clientconn := make(chan birpc.ClientConnector, 1) clientconn <- clMock(func(serviceMethod string, _, _ any) error { if serviceMethod == utils.CacheSv1ReloadCache { @@ -2222,7 +2223,7 @@ func TestTprLoadAccountActionFiltered(t *testing.T) { } return utils.ErrNotImplemented }) - connMgr := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): clientconn, }) timings := &utils.ApierTPTiming{ diff --git a/engine/z_actions2_it_test.go b/engine/z_actions2_it_test.go index 4fd23586b..8e191e358 100644 --- a/engine/z_actions2_it_test.go +++ b/engine/z_actions2_it_test.go @@ -21,12 +21,13 @@ along with this program. If not, see package engine import ( - "net/rpc" "path" "runtime" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -36,7 +37,7 @@ var ( actsCfgPath string actsCfgDir string actsCfg *config.CGRConfig - actsRPC *rpc.Client + actsRPC *birpc.Client ) var sTestsActions = []func(t *testing.T){ @@ -189,13 +190,13 @@ func testActionsExecuteRemoveSMCos1(t *testing.T) { }, }, } - if err := actsRPC.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsRPC.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: "cgrates.org", ActionsId: attrsAA.ActionsId} - if err := actsRPC.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsRPC.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) @@ -222,13 +223,13 @@ func testActionsExecuteRemoveSMCos2(t *testing.T) { }, }, } - if err := actsRPC.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsRPC.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: "cgrates.org", ActionsId: attrsAA.ActionsId} - if err := actsRPC.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsRPC.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) @@ -243,7 +244,7 @@ func testActionsExecuteRemoveSMCos2(t *testing.T) { func testActionsUpdateBalance(t *testing.T) { var reply string attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "testAcc"} - if err := actsRPC.Call(utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { + if err := actsRPC.Call(context.Background(), utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -251,7 +252,7 @@ func testActionsUpdateBalance(t *testing.T) { topupAction := &utils.AttrSetActions{ActionsId: "ACT_TOPUP_RST", Actions: []*utils.TPAction{ {Identifier: utils.MetaTopUp, BalanceId: "test", BalanceType: utils.MetaMonetary, Units: "5", ExpiryTime: utils.MetaUnlimited, Weight: 20.0}, }} - if err := actsRPC.Call(utils.APIerSv2SetActions, topupAction, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsRPC.Call(context.Background(), utils.APIerSv2SetActions, topupAction, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -259,27 +260,27 @@ func testActionsUpdateBalance(t *testing.T) { changeBlockerAction := &utils.AttrSetActions{ActionsId: "ACT_BAL_UPDT", Actions: []*utils.TPAction{ {Identifier: utils.MetaSetBalance, BalanceId: "test", BalanceBlocker: "true"}, }} - if err := actsRPC.Call(utils.APIerSv2SetActions, changeBlockerAction, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsRPC.Call(context.Background(), utils.APIerSv2SetActions, changeBlockerAction, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: topupAction.ActionsId} - if err := actsRPC.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsRPC.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } runtime.Gosched() attrsEA2 := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: changeBlockerAction.ActionsId} - if err := actsRPC.Call(utils.APIerSv1ExecuteAction, attrsEA2, &reply); err != nil { + if err := actsRPC.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA2, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } var acc Account attrs2 := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testAcc"} - if err := actsRPC.Call(utils.APIerSv2GetAccount, attrs2, &acc); err != nil { + if err := actsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs2, &acc); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else if acc.BalanceMap[utils.MetaMonetary][0].ID != "test" { t.Errorf("Expected test result received %v ", acc.BalanceMap[utils.MetaMonetary][0].ID) diff --git a/engine/z_actions_it_test.go b/engine/z_actions_it_test.go index e2f252f16..26cdae77b 100644 --- a/engine/z_actions_it_test.go +++ b/engine/z_actions_it_test.go @@ -24,7 +24,6 @@ import ( "io" "net/http" "net/http/httptest" - "net/rpc" "path" "reflect" "strconv" @@ -32,13 +31,15 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) var ( actsLclCfg *config.CGRConfig - actsLclRpc *rpc.Client + actsLclRpc *birpc.Client actsLclCfgPath string actionsConfigDIR string @@ -127,7 +128,7 @@ func testActionsitRpcConn(t *testing.T) { func testActionsitSetCdrlogDebit(t *testing.T) { var reply string attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "dan2904"} - if err := actsLclRpc.Call(utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -136,19 +137,19 @@ func testActionsitSetCdrlogDebit(t *testing.T) { {Identifier: utils.MetaDebit, BalanceType: utils.MetaMonetary, Units: "5", ExpiryTime: utils.MetaUnlimited, Weight: 20.0}, {Identifier: utils.CDRLog}, }} - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: attrsAA.ActionsId} - if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } var rcvedCdrs []*ExternalCDR - if err := actsLclRpc.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, Accounts: []string{attrsSetAccount.Account}}, &rcvedCdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(rcvedCdrs) != 1 { @@ -170,7 +171,7 @@ func testActionsitSetCdrlogDebit(t *testing.T) { func testActionsitSetCdrlogTopup(t *testing.T) { var reply string attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "dan2905"} - if err := actsLclRpc.Call(utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -179,19 +180,19 @@ func testActionsitSetCdrlogTopup(t *testing.T) { {Identifier: utils.MetaTopUp, BalanceType: utils.MetaMonetary, Units: "5", ExpiryTime: utils.MetaUnlimited, Weight: 20.0}, {Identifier: utils.CDRLog}, }} - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: attrsAA.ActionsId} - if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } var rcvedCdrs []*ExternalCDR - if err := actsLclRpc.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, Accounts: []string{attrsSetAccount.Account}}, &rcvedCdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(rcvedCdrs) != 1 { @@ -218,19 +219,19 @@ func testActionsitCdrlogEmpty(t *testing.T) { Units: "5", ExpiryTime: utils.MetaUnlimited, Weight: 20.0}, {Identifier: utils.CDRLog}, }} - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: attrsAA.ActionsId} - if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } var rcvedCdrs []*ExternalCDR - if err := actsLclRpc.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, Accounts: []string{attrsSetAccount.Account}, RunIDs: []string{utils.MetaDebit}}, &rcvedCdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(rcvedCdrs) != 2 { @@ -257,25 +258,25 @@ func testActionsitCdrlogWithParams(t *testing.T) { DestinationIds: "RET", Units: "25", ExpiryTime: utils.MetaUnlimited, Weight: 20.0}, }, } - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: attrsAA.ActionsId} - if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } var rcvedCdrs []*ExternalCDR - if err := actsLclRpc.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, Accounts: []string{attrsSetAccount.Account}, RunIDs: []string{utils.MetaDebit}, RequestTypes: []string{"*pseudoprepaid"}}, &rcvedCdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(rcvedCdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(rcvedCdrs)) } - if err := actsLclRpc.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, Accounts: []string{attrsSetAccount.Account}, RunIDs: []string{utils.MetaDebitReset}, RequestTypes: []string{"*pseudoprepaid"}}, &rcvedCdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(rcvedCdrs) != 1 { @@ -295,19 +296,19 @@ func testActionsitCdrlogWithParams2(t *testing.T) { ExtraParameters: `{"RequestType":"*pseudoprepaid", "Usage":"10", "Subject":"testActionsitCdrlogWithParams2", "ToR":"~ActionType:s/^\\*(.*)$/did_$1/"}`}, }, } - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: attrsAA.ActionsId} - if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } var rcvedCdrs []*ExternalCDR - if err := actsLclRpc.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, Accounts: []string{attrsSetAccount.Account}, Subjects: []string{"testActionsitCdrlogWithParams2"}}, &rcvedCdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(rcvedCdrs) != 1 { @@ -324,7 +325,7 @@ func testActionsitThresholdCDrLog(t *testing.T) { var reply string attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "th_acc"} - if err := actsLclRpc.Call(utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -333,13 +334,13 @@ func testActionsitThresholdCDrLog(t *testing.T) { {Identifier: utils.MetaTopUp, BalanceType: utils.MetaMonetary, Units: "5", ExpiryTime: utils.MetaUnlimited, Weight: 20.0}, {Identifier: utils.CDRLog}, }} - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } //make sure that the threshold don't exit - if err := actsLclRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &thReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -361,12 +362,12 @@ func testActionsitThresholdCDrLog(t *testing.T) { Async: false, }, } - if err := actsLclRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := actsLclRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &thReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, thReply) { @@ -405,13 +406,13 @@ func testActionsitThresholdCDrLog(t *testing.T) { } var ids []string eIDs := []string{"THD_Test"} - if err := actsLclRpc.Call(utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } var rcvedCdrs []*ExternalCDR - if err := actsLclRpc.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{Sources: []string{utils.CDRLog}, Accounts: []string{attrsSetAccount.Account}}, &rcvedCdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(rcvedCdrs) != 1 { @@ -454,7 +455,7 @@ func testActionsitCDRAccount(t *testing.T) { }, Overwrite: true, } - if err := actsLclRpc.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1AddBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.AddBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.AddBalance received: %s", reply) @@ -466,7 +467,7 @@ func testActionsitCDRAccount(t *testing.T) { {Identifier: utils.MetaCDRAccount, ExpiryTime: utils.MetaUnlimited, Weight: 20.0}, }, } - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -475,7 +476,7 @@ func testActionsitCDRAccount(t *testing.T) { var acc Account attrs2 := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: acnt} var uuid string - if err := actsLclRpc.Call(utils.APIerSv2GetAccount, attrs2, &acc); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs2, &acc); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else { voice := acc.BalanceMap[utils.MetaVoice] @@ -517,7 +518,7 @@ func testActionsitCDRAccount(t *testing.T) { }, }, } - if err := actsLclRpc.Call(utils.CDRsV1ProcessCDR, args, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.CDRsV1ProcessCDR, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -525,13 +526,13 @@ func testActionsitCDRAccount(t *testing.T) { time.Sleep(100 * time.Millisecond) attrsEA := &utils.AttrExecuteAction{Tenant: "cgrates.org", Account: acnt, ActionsId: attrsAA.ActionsId} - if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } - if err := actsLclRpc.Call(utils.APIerSv2GetAccount, attrs2, &acc); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs2, &acc); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else if tv := acc.BalanceMap[utils.MetaVoice].GetTotalValue(); tv != float64(10*time.Second) { t.Errorf("Calling APIerSv1.GetBalance expected: %f, received: %f", float64(10*time.Second), tv) @@ -550,13 +551,13 @@ func testActionsitThresholdCgrRpcAction(t *testing.T) { "Attempts":1, "Async" :false, "Params": {}}`}}} - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } //make sure that the threshold don't exit - if err := actsLclRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TH_CGRRPC"}, &thReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -577,12 +578,12 @@ func testActionsitThresholdCgrRpcAction(t *testing.T) { Async: false, }, } - if err := actsLclRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := actsLclRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TH_CGRRPC"}, &thReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, thReply) { @@ -597,7 +598,7 @@ func testActionsitThresholdCgrRpcAction(t *testing.T) { } var ids []string eIDs := []string{"TH_CGRRPC"} - if err := actsLclRpc.Call(utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -614,13 +615,13 @@ func testActionsitThresholdPostEvent(t *testing.T) { attrsAA := &utils.AttrSetActions{ActionsId: "ACT_TH_POSTEVENT", Actions: []*utils.TPAction{ {Identifier: utils.MetaPostEvent, ExtraParameters: "http://127.0.0.1:12080/invalid_json"}, }} - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } //make sure that the threshold don't exit - if err := actsLclRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_PostEvent"}, &thReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -641,12 +642,12 @@ func testActionsitThresholdPostEvent(t *testing.T) { Async: false, }, } - if err := actsLclRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := actsLclRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_PostEvent"}, &thReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, thReply) { @@ -679,7 +680,7 @@ func testActionsitThresholdPostEvent(t *testing.T) { } var ids []string eIDs := []string{"THD_PostEvent"} - if err := actsLclRpc.Call(utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -693,7 +694,7 @@ func testActionsitSetSDestinations(t *testing.T) { Tenant: "cgrates.org", Account: "testAccSetDDestination", } - if err := actsLclRpc.Call(utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -702,14 +703,14 @@ func testActionsitSetSDestinations(t *testing.T) { {Identifier: utils.MetaTopUp, BalanceType: utils.MetaMonetary, DestinationIds: "*ddc_test", Units: "5", ExpiryTime: utils.MetaUnlimited, Weight: 20.0}, }} - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: attrsAA.ActionsId} - if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) @@ -717,13 +718,13 @@ func testActionsitSetSDestinations(t *testing.T) { var acc Account attrs2 := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testAccSetDDestination"} - if err := actsLclRpc.Call(utils.APIerSv2GetAccount, attrs2, &acc); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs2, &acc); err != nil { t.Error(err.Error()) } else if _, has := acc.BalanceMap[utils.MetaMonetary][0].DestinationIDs["*ddc_test"]; !has { t.Errorf("Unexpected destinationIDs: %+v", acc.BalanceMap[utils.MetaMonetary][0].DestinationIDs) } - if err := actsLclRpc.Call(utils.APIerSv1SetDestination, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1SetDestination, &utils.AttrSetDestination{Id: "*ddc_test", Prefixes: []string{"111", "222"}}, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { @@ -731,7 +732,7 @@ func testActionsitSetSDestinations(t *testing.T) { } //verify destinations var dest Destination - if err := actsLclRpc.Call(utils.APIerSv1GetDestination, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1GetDestination, utils.StringPointer("*ddc_test"), &dest); err != nil { t.Error(err.Error()) } else { @@ -756,7 +757,7 @@ func testActionsitSetSDestinations(t *testing.T) { }, } - if err := actsLclRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -772,7 +773,7 @@ func testActionsitSetSDestinations(t *testing.T) { utils.Usage: 6 * time.Second, }, } - if err := actsLclRpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -786,7 +787,7 @@ func testActionsitSetSDestinations(t *testing.T) { utils.Usage: 6 * time.Second, }, } - if err := actsLclRpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &args, &reply2); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply2, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply2) @@ -796,7 +797,7 @@ func testActionsitSetSDestinations(t *testing.T) { attrSetDDest := &utils.AttrSetActions{ActionsId: "ACT_setDDestination", Actions: []*utils.TPAction{ {Identifier: utils.MetaSetDDestinations, ExtraParameters: "DistinctMetricProfile"}, }} - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrSetDDest, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrSetDDest, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -804,14 +805,14 @@ func testActionsitSetSDestinations(t *testing.T) { attrsetDDest := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: attrSetDDest.ActionsId} - if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsetDDest, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsetDDest, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } //verify destinations - if err := actsLclRpc.Call(utils.APIerSv1GetDestination, + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1GetDestination, utils.StringPointer("*ddc_test"), &dest); err != nil { t.Error(err.Error()) } else { @@ -830,7 +831,7 @@ func testActionsitresetAccountCDR(t *testing.T) { Tenant: "cgrates.org", Account: "123456789", } - if err := actsLclRpc.Call(utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -842,7 +843,7 @@ func testActionsitresetAccountCDR(t *testing.T) { {Identifier: utils.MetaCDRAccount, ExpiryTime: utils.MetaUnlimited, Weight: 20.0}, }, } - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -851,7 +852,7 @@ func testActionsitresetAccountCDR(t *testing.T) { var acc Account attrs2 := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: account} var uuid string - if err := actsLclRpc.Call(utils.APIerSv2GetAccount, attrs2, &acc); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs2, &acc); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else { voice := acc.BalanceMap[utils.MetaVoice] @@ -892,7 +893,7 @@ func testActionsitresetAccountCDR(t *testing.T) { }, }, } - if err := actsLclRpc.Call(utils.CDRsV1ProcessCDR, args, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.CDRsV1ProcessCDR, args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -900,13 +901,13 @@ func testActionsitresetAccountCDR(t *testing.T) { time.Sleep(100 * time.Millisecond) attrsEA := &utils.AttrExecuteAction{Tenant: "cgrates.org", Account: account, ActionsId: attrsAA.ActionsId} - if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) } - if err := actsLclRpc.Call(utils.APIerSv2GetAccount, attrs2, &acc); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs2, &acc); err != nil { t.Error("Got error on APIerSv1.GetAccount: ", err.Error()) } else if tv := acc.BalanceMap[utils.MetaVoice].GetTotalValue(); tv != float64(10*time.Second) { t.Errorf("Calling APIerSv1.GetBalance expected: %f, received: %f", float64(10*time.Second), tv) @@ -957,14 +958,14 @@ func testActionsitremoteSetAccount(t *testing.T) { {Identifier: utils.MetaRemoteSetAccount, ExtraParameters: ts.URL, Weight: 20.0}, }, } - if err := actsLclRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: "cgrates.org", Account: account, ActionsId: attrsAA.ActionsId} - if err := actsLclRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) @@ -972,7 +973,7 @@ func testActionsitremoteSetAccount(t *testing.T) { var acc2 Account attrs2 := &utils.AttrGetAccount{Account: account} - if err := actsLclRpc.Call(utils.APIerSv2GetAccount, attrs2, &acc2); err != nil { + if err := actsLclRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs2, &acc2); err != nil { t.Fatal("Got error on APIerSv1.GetAccount: ", err.Error()) } acc2.UpdateTime = exp.UpdateTime diff --git a/engine/z_attributes_test.go b/engine/z_attributes_test.go index c8b226009..2f00b509d 100644 --- a/engine/z_attributes_test.go +++ b/engine/z_attributes_test.go @@ -23,6 +23,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -600,7 +601,7 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -709,7 +710,7 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -818,7 +819,7 @@ func TestAttributeProcessWithMultipleRuns3(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -908,7 +909,7 @@ func TestAttributeProcessWithMultipleRuns4(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1020,7 +1021,7 @@ func TestAttributeMultipleProcessWithBlocker(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1129,7 +1130,7 @@ func TestAttributeMultipleProcessWithBlocker2(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1199,7 +1200,7 @@ func TestAttributeProcessValue(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1279,7 +1280,7 @@ func TestAttributeAttributeFilterIDs(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1351,7 +1352,7 @@ func TestAttributeProcessEventConstant(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1429,7 +1430,7 @@ func TestAttributeProcessEventVariable(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1512,7 +1513,7 @@ func TestAttributeProcessEventComposed(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Fatalf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1587,7 +1588,7 @@ func TestAttributeProcessEventSum(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1664,7 +1665,7 @@ func TestAttributeProcessEventUsageDifference(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1741,7 +1742,7 @@ func TestAttributeProcessEventValueExponent(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -1807,7 +1808,7 @@ func BenchmarkAttributeProcessEventConstant(b *testing.B) { var reply AttrSProcessEventReply b.ResetTimer() for i := 0; i < b.N; i++ { - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { b.Errorf("Error: %+v", err) } } @@ -1866,7 +1867,7 @@ func BenchmarkAttributeProcessEventVariable(b *testing.B) { var reply AttrSProcessEventReply b.ResetTimer() for i := 0; i < b.N; i++ { - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { b.Errorf("Error: %+v", err) } } @@ -2686,7 +2687,7 @@ func TestAttributeIndexSelectsFalse(t *testing.T) { } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err == nil || err != utils.ErrNotFound { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("Expected not found, reveiced: %+v", err) } @@ -2748,7 +2749,7 @@ func TestProcessAttributeWithSameWeight(t *testing.T) { }, } var rcv AttrSProcessEventReply - if err := attrS.V1ProcessEvent(ev, &rcv); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), ev, &rcv); err != nil { t.Errorf("Error: %+v", err) } clnEv := ev.Clone() @@ -2848,7 +2849,7 @@ func TestAttributeMultipleProcessWithFiltersExists(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -2945,7 +2946,7 @@ func TestAttributeMultipleProcessWithFiltersNotEmpty(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(attrArgs, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), attrArgs, &reply); err != nil { t.Errorf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { @@ -3005,7 +3006,7 @@ func TestAttributeMetaTenant(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(args, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), args, &reply); err != nil { t.Fatal(err) } if !reflect.DeepEqual(eRply, reply) { @@ -3112,7 +3113,7 @@ func TestAttributesPorcessEventMatchingProcessRuns(t *testing.T) { }, }, } - if err := attr.V1ProcessEvent(args, reply); err != nil { + if err := attr.V1ProcessEvent(context.Background(), args, reply); err != nil { t.Error(err) } else if sort.Strings(reply.AlteredFields); !reflect.DeepEqual(expReply, reply) { t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expReply), utils.ToJSON(reply)) @@ -3193,7 +3194,7 @@ func TestAttributeMultipleProfileRunns(t *testing.T) { }, } var reply AttrSProcessEventReply - if err := attrS.V1ProcessEvent(args, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), args, &reply); err != nil { t.Errorf("Error: %+v", err) } sort.Strings(reply.AlteredFields) @@ -3233,7 +3234,7 @@ func TestAttributeMultipleProfileRunns(t *testing.T) { }, } reply = AttrSProcessEventReply{} - if err := attrS.V1ProcessEvent(args, &reply); err != nil { + if err := attrS.V1ProcessEvent(context.Background(), args, &reply); err != nil { t.Errorf("Error: %+v", err) } sort.Strings(reply.AlteredFields) diff --git a/engine/z_chargers_test.go b/engine/z_chargers_test.go index 6c5cc5891..5fe9c9bfb 100644 --- a/engine/z_chargers_test.go +++ b/engine/z_chargers_test.go @@ -24,6 +24,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" "github.com/cgrates/rpcclient" @@ -212,14 +214,14 @@ func TestChargersprocessEventNoConnIDs(t *testing.T) { } type ccMock struct { - calls map[string]func(args any, reply any) error + calls map[string]func(ctx *context.Context, args any, reply any) error } -func (ccM *ccMock) Call(serviceMethod string, args any, reply any) (err error) { +func (ccM *ccMock) Call(ctx *context.Context, serviceMethod string, args any, reply any) (err error) { if call, has := ccM.calls[serviceMethod]; !has { return rpcclient.ErrUnsupporteServiceMethod } else { - return call(args, reply) + return call(ctx, args, reply) } } @@ -243,8 +245,8 @@ func TestChargersprocessEventCallNilErr(t *testing.T) { } ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.AttributeSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.AttributeSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rply := AttrSProcessEventReply{ AlteredFields: []string{utils.AccountField}, CGREvent: &utils.CGREvent{ @@ -260,7 +262,7 @@ func TestChargersprocessEventCallNilErr(t *testing.T) { }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM cS := &ChargerService{ @@ -270,7 +272,7 @@ func TestChargersprocessEventCallNilErr(t *testing.T) { cfg: cfg, }, cfg: cfg, - connMgr: NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr: NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): rpcInternal, }), } @@ -332,13 +334,13 @@ func TestChargersprocessEventCallErr(t *testing.T) { } ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.AttributeSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.AttributeSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { return utils.ErrNotFound }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM cS := &ChargerService{ @@ -348,7 +350,7 @@ func TestChargersprocessEventCallErr(t *testing.T) { cfg: cfg, }, cfg: cfg, - connMgr: NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr: NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): rpcInternal, }), } @@ -415,8 +417,8 @@ func TestChargersV1ProcessEventErrNotFound(t *testing.T) { } ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.AttributeSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.AttributeSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rply := AttrSProcessEventReply{ AlteredFields: []string{utils.AccountField}, CGREvent: &utils.CGREvent{ @@ -432,7 +434,7 @@ func TestChargersV1ProcessEventErrNotFound(t *testing.T) { }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM cS := &ChargerService{ @@ -442,7 +444,7 @@ func TestChargersV1ProcessEventErrNotFound(t *testing.T) { cfg: cfg, }, cfg: cfg, - connMgr: NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr: NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): rpcInternal, }), } @@ -455,7 +457,7 @@ func TestChargersV1ProcessEventErrNotFound(t *testing.T) { reply := &[]*ChrgSProcessEventReply{} experr := utils.ErrNotFound - err := cS.V1ProcessEvent(args, reply) + err := cS.V1ProcessEvent(context.Background(), args, reply) if err == nil || err != experr { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) @@ -486,8 +488,8 @@ func TestChargersV1ProcessEventErrOther(t *testing.T) { } ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - "invalidMethod": func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + "invalidMethod": func(ctx *context.Context, args, reply any) error { rply := AttrSProcessEventReply{ AlteredFields: []string{utils.AccountField}, CGREvent: &utils.CGREvent{ @@ -503,7 +505,7 @@ func TestChargersV1ProcessEventErrOther(t *testing.T) { }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM cS := &ChargerService{ @@ -513,7 +515,7 @@ func TestChargersV1ProcessEventErrOther(t *testing.T) { cfg: cfg, }, cfg: cfg, - connMgr: NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr: NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): rpcInternal, }), } @@ -527,7 +529,7 @@ func TestChargersV1ProcessEventErrOther(t *testing.T) { exp := &[]*ChrgSProcessEventReply{} experr := fmt.Sprintf("SERVER_ERROR: %s", rpcclient.ErrUnsupporteServiceMethod) - err := cS.V1ProcessEvent(args, reply) + err := cS.V1ProcessEvent(context.Background(), args, reply) if err == nil || err.Error() != experr { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) @@ -563,8 +565,8 @@ func TestChargersV1ProcessEvent(t *testing.T) { } ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.AttributeSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.AttributeSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { rply := AttrSProcessEventReply{ AlteredFields: []string{utils.AccountField}, CGREvent: &utils.CGREvent{ @@ -580,7 +582,7 @@ func TestChargersV1ProcessEvent(t *testing.T) { }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM cS := &ChargerService{ @@ -590,7 +592,7 @@ func TestChargersV1ProcessEvent(t *testing.T) { cfg: cfg, }, cfg: cfg, - connMgr: NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr: NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): rpcInternal, }), } @@ -615,7 +617,7 @@ func TestChargersV1ProcessEvent(t *testing.T) { }, }, } - err := cS.V1ProcessEvent(args, reply) + err := cS.V1ProcessEvent(context.Background(), args, reply) if err != nil { t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) @@ -674,7 +676,7 @@ func TestChargersV1GetChargersForEventNilErr(t *testing.T) { RunID: "*default", }, } - err := cS.V1GetChargersForEvent(args, reply) + err := cS.V1GetChargersForEvent(context.Background(), args, reply) if err != nil { t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", nil, err) @@ -720,7 +722,7 @@ func TestChargersV1GetChargersForEventErr(t *testing.T) { exp := &ChargerProfiles{} experr := fmt.Sprintf("SERVER_ERROR: %s", utils.ErrNotImplemented) - err := cS.V1GetChargersForEvent(args, reply) + err := cS.V1GetChargersForEvent(context.Background(), args, reply) if err == nil || err.Error() != experr { t.Fatalf("\nexpected: <%+v>, \nreceived: <%+v>", experr, err) diff --git a/engine/z_loader_it_test.go b/engine/z_loader_it_test.go index c8da7b7b6..3db28b8dc 100644 --- a/engine/z_loader_it_test.go +++ b/engine/z_loader_it_test.go @@ -26,9 +26,9 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) var ( @@ -96,11 +96,15 @@ func testLoaderITInitDataDB(t *testing.T) { if err = dataDbCsv.Flush(utils.EmptyString); err != nil { t.Fatal("Error when flushing datadb") } - cacheChan := make(chan rpcclient.ClientConnector, 1) - connMgr = NewConnManager(lCfg, map[string]chan rpcclient.ClientConnector{ + cacheChan := make(chan birpc.ClientConnector, 1) + connMgr = NewConnManager(lCfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): cacheChan, }) - cacheChan <- NewCacheS(lCfg, NewDataManager(dataDbCsv, lCfg.CacheCfg(), connMgr), nil) + srv, err := NewService(NewCacheS(lCfg, NewDataManager(dataDbCsv, lCfg.CacheCfg(), connMgr), nil)) + if err != nil { + t.Fatal(err) + } + cacheChan <- srv } // Create/reset storage tariff plan tables, used as database connectin establishment also diff --git a/engine/z_resources_test.go b/engine/z_resources_test.go index 7c372f8d8..d632f2bed 100644 --- a/engine/z_resources_test.go +++ b/engine/z_resources_test.go @@ -28,6 +28,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/rpcclient" @@ -944,10 +946,10 @@ func TestResourceV1AuthorizeResourceMissingStruct(t *testing.T) { utils.OptsResourcesUnits: 20, }, } - if err := resService.V1AuthorizeResources(argsMissingTenant, reply); err != nil && err.Error() != "MANDATORY_IE_MISSING: [Event]" { + if err := resService.V1AuthorizeResources(context.Background(), argsMissingTenant, reply); err != nil && err.Error() != "MANDATORY_IE_MISSING: [Event]" { t.Error(err.Error()) } - if err := resService.V1AuthorizeResources(argsMissingUsageID, reply); err != nil && err.Error() != "MANDATORY_IE_MISSING: [Event]" { + if err := resService.V1AuthorizeResources(context.Background(), argsMissingUsageID, reply); err != nil && err.Error() != "MANDATORY_IE_MISSING: [Event]" { t.Error(err.Error()) } } @@ -2648,16 +2650,17 @@ func TestResourceAllocateResourceOtherDB(t *testing.T) { } var reply string exp := rProf.ID - if err := rs.V1AllocateResources(&utils.CGREvent{ - Tenant: "cgrates.org", - ID: "ef0f554", - Event: map[string]any{"": ""}, - APIOpts: map[string]any{ - "Resource": "RL_DB", - utils.OptsResourcesUsageID: "56156434-2e44-4f16-a766-086f10b413cd", - utils.OptsResourcesUnits: 1, - }, - }, &reply); err != nil { + if err := rs.V1AllocateResources(context.Background(), + &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "ef0f554", + Event: map[string]any{"": ""}, + APIOpts: map[string]any{ + "Resource": "RL_DB", + utils.OptsResourcesUsageID: "56156434-2e44-4f16-a766-086f10b413cd", + utils.OptsResourcesUnits: 1, + }, + }, &reply); err != nil { t.Fatal(err) } else if reply != exp { t.Errorf("Expected: %q, received: %q", exp, reply) @@ -2815,7 +2818,7 @@ func TestResourcesStoreResourceErrCache(t *testing.T) { cfg.CacheCfg().Partitions[utils.CacheResources].Replicate = true cfg.RPCConns()["test"] = &config.RPCConn{Conns: []*config.RemoteHost{{}}} config.SetCgrConfig(cfg) - dm := NewDataManager(NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items), cfg.CacheCfg(), NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector))) + dm := NewDataManager(NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items), cfg.CacheCfg(), NewConnManager(cfg, make(map[string]chan birpc.ClientConnector))) rS := NewResourceService(dm, cfg, nil, nil) Cache = NewCacheS(cfg, dm, nil) r := &Resource{ @@ -2893,8 +2896,8 @@ func TestResourcesProcessThresholdsOK(t *testing.T) { Cache.Clear(nil) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ThresholdSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { exp := &utils.CGREvent{ Tenant: "cgrates.org", ID: args.(*utils.CGREvent).ID, @@ -2916,11 +2919,11 @@ func TestResourcesProcessThresholdsOK(t *testing.T) { }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM rS := &ResourceService{ cgrcfg: cfg, - connMgr: NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr: NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): rpcInternal, }), } @@ -2960,8 +2963,8 @@ func TestResourcesProcessThresholdsCallErr(t *testing.T) { Cache.Clear(nil) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ThresholdSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { exp := &utils.CGREvent{ Tenant: "cgrates.org", ID: args.(*utils.CGREvent).ID, @@ -2983,11 +2986,11 @@ func TestResourcesProcessThresholdsCallErr(t *testing.T) { }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM rS := &ResourceService{ cgrcfg: cfg, - connMgr: NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr: NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): rpcInternal, }), } @@ -3232,7 +3235,7 @@ func TestResourcesV1ResourcesForEventOK(t *testing.T) { }, } var reply Resources - if err := rS.V1ResourcesForEvent(args, &reply); err != nil { + if err := rS.V1GetResourcesForEvent(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, exp) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", @@ -3290,7 +3293,7 @@ func TestResourcesV1ResourcesForEventNotFound(t *testing.T) { } var reply Resources - if err := rS.V1ResourcesForEvent(args, &reply); err == nil || + if err := rS.V1GetResourcesForEvent(context.Background(), args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } @@ -3336,7 +3339,7 @@ func TestResourcesV1ResourcesForEventMissingParameters(t *testing.T) { experr := `MANDATORY_IE_MISSING: [Event]` var reply Resources - if err := rS.V1ResourcesForEvent(nil, &reply); err == nil || + if err := rS.V1GetResourcesForEvent(context.Background(), nil, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -3352,7 +3355,7 @@ func TestResourcesV1ResourcesForEventMissingParameters(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [ID]` - if err := rS.V1ResourcesForEvent(args, &reply); err == nil || + if err := rS.V1GetResourcesForEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -3366,7 +3369,7 @@ func TestResourcesV1ResourcesForEventMissingParameters(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [Event]` - if err := rS.V1ResourcesForEvent(args, &reply); err == nil || + if err := rS.V1GetResourcesForEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -3380,7 +3383,7 @@ func TestResourcesV1ResourcesForEventMissingParameters(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [UsageID]` - if err := rS.V1ResourcesForEvent(args, &reply); err == nil || + if err := rS.V1GetResourcesForEvent(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -3469,7 +3472,7 @@ func TestResourcesV1ResourcesForEventCacheReplyExists(t *testing.T) { &utils.CachedRPCResponse{Result: &cacheReply, Error: nil}, nil, true, utils.NonTransactional) var reply Resources - if err := rS.V1ResourcesForEvent(args, &reply); err != nil { + if err := rS.V1GetResourcesForEvent(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, cacheReply) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", @@ -3561,7 +3564,7 @@ func TestResourcesV1ResourcesForEventCacheReplySet(t *testing.T) { }, } var reply Resources - if err := rS.V1ResourcesForEvent(args, &reply); err != nil { + if err := rS.V1GetResourcesForEvent(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, exp) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", @@ -3642,7 +3645,7 @@ func TestResourcesV1GetResourceOK(t *testing.T) { }, } var reply Resource - if err := rS.V1GetResource(args, &reply); err != nil { + if err := rS.V1GetResource(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, exp) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", @@ -3698,7 +3701,7 @@ func TestResourcesV1GetResourceNotFound(t *testing.T) { }, } var reply Resource - if err := rS.V1GetResource(args, &reply); err == nil || + if err := rS.V1GetResource(context.Background(), args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } @@ -3751,7 +3754,7 @@ func TestResourcesV1GetResourceMissingParameters(t *testing.T) { experr := `MANDATORY_IE_MISSING: [ID]` var reply Resource - if err := rS.V1GetResource(args, &reply); err == nil || + if err := rS.V1GetResource(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -3824,7 +3827,7 @@ func TestResourcesV1GetResourceWithConfigOK(t *testing.T) { }, } var reply ResourceWithConfig - if err := rS.V1GetResourceWithConfig(args, &reply); err != nil { + if err := rS.V1GetResourceWithConfig(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, exp) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", @@ -3902,7 +3905,7 @@ func TestResourcesV1GetResourceWithConfigNilrPrfOK(t *testing.T) { }, } var reply ResourceWithConfig - if err := rS.V1GetResourceWithConfig(args, &reply); err != nil { + if err := rS.V1GetResourceWithConfig(context.Background(), args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, exp) { t.Errorf("expected: <%+v>, \nreceived: <%+v>", @@ -3960,7 +3963,7 @@ func TestResourcesV1GetResourceWithConfigNilrPrfProfileNotFound(t *testing.T) { }, } var reply ResourceWithConfig - if err := rS.V1GetResourceWithConfig(args, &reply); err == nil || + if err := rS.V1GetResourceWithConfig(context.Background(), args, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } @@ -4013,7 +4016,7 @@ func TestResourcesV1GetResourceWithConfigResourceNotFound(t *testing.T) { }, } var reply ResourceWithConfig - if err := rS.V1GetResourceWithConfig(args, &reply); err == nil || err != utils.ErrNotFound { + if err := rS.V1GetResourceWithConfig(context.Background(), args, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } } @@ -4064,7 +4067,7 @@ func TestResourcesV1GetResourceWithConfigMissingParameters(t *testing.T) { TenantID: &utils.TenantID{}, } var reply ResourceWithConfig - if err := rS.V1GetResourceWithConfig(args, &reply); err == nil || err.Error() != experr { + if err := rS.V1GetResourceWithConfig(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } } @@ -4108,7 +4111,7 @@ func TestResourcesV1AuthorizeResourcesOK(t *testing.T) { } var reply string - if err := rS.V1AuthorizeResources(args, &reply); err != nil { + if err := rS.V1AuthorizeResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != "Approved" { t.Errorf("Unexpected reply returned: %q", reply) @@ -4155,7 +4158,7 @@ func TestResourcesV1AuthorizeResourcesNotAuthorized(t *testing.T) { } var reply string - if err := rS.V1AuthorizeResources(args, &reply); err == nil || + if err := rS.V1AuthorizeResources(context.Background(), args, &reply); err == nil || err != utils.ErrResourceUnauthorized { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrResourceUnauthorized, err) } @@ -4201,7 +4204,7 @@ func TestResourcesV1AuthorizeResourcesNoMatch(t *testing.T) { } var reply string - if err := rS.V1AuthorizeResources(args, &reply); err == nil || + if err := rS.V1AuthorizeResources(context.Background(), args, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } @@ -4239,7 +4242,7 @@ func TestResourcesV1AuthorizeResourcesNilCGREvent(t *testing.T) { experr := `MANDATORY_IE_MISSING: [Event]` var reply string - if err := rS.V1AuthorizeResources(args, &reply); err == nil || + if err := rS.V1AuthorizeResources(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -4284,7 +4287,7 @@ func TestResourcesV1AuthorizeResourcesMissingUsageID(t *testing.T) { experr := `MANDATORY_IE_MISSING: [UsageID]` var reply string - if err := rS.V1AuthorizeResources(args, &reply); err == nil || + if err := rS.V1AuthorizeResources(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -4363,7 +4366,7 @@ func TestResourcesV1AuthorizeResourcesCacheReplyExists(t *testing.T) { nil, true, utils.NonTransactional) var reply string - if err := rS.V1AuthorizeResources(args, &reply); err != nil { + if err := rS.V1AuthorizeResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != cacheReply { t.Errorf("Unexpected reply returned: %q", reply) @@ -4439,7 +4442,7 @@ func TestResourcesV1AuthorizeResourcesCacheReplySet(t *testing.T) { } var reply string - if err := rS.V1AuthorizeResources(args, &reply); err != nil { + if err := rS.V1AuthorizeResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != "Approved" { t.Errorf("Unexpected reply returned: %q", reply) @@ -4495,7 +4498,7 @@ func TestResourcesV1AllocateResourcesOK(t *testing.T) { } var reply string - if err := rS.V1AllocateResources(args, &reply); err != nil { + if err := rS.V1AllocateResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != "Approved" { t.Errorf("Unexpected reply returned: %q", reply) @@ -4541,7 +4544,7 @@ func TestResourcesV1AllocateResourcesNoMatch(t *testing.T) { } var reply string - if err := rS.V1AllocateResources(args, &reply); err == nil || + if err := rS.V1AllocateResources(context.Background(), args, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } @@ -4586,7 +4589,7 @@ func TestResourcesV1AllocateResourcesMissingParameters(t *testing.T) { var reply string experr := `MANDATORY_IE_MISSING: [UsageID]` - if err := rS.V1AllocateResources(args, &reply); err == nil || + if err := rS.V1AllocateResources(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -4601,7 +4604,7 @@ func TestResourcesV1AllocateResourcesMissingParameters(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [Event]` - if err := rS.V1AllocateResources(args, &reply); err == nil || + if err := rS.V1AllocateResources(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -4618,7 +4621,7 @@ func TestResourcesV1AllocateResourcesMissingParameters(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [ID]` - if err := rS.V1AllocateResources(args, &reply); err == nil || + if err := rS.V1AllocateResources(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -4697,7 +4700,7 @@ func TestResourcesV1AllocateResourcesCacheReplyExists(t *testing.T) { nil, true, utils.NonTransactional) var reply string - if err := rS.V1AllocateResources(args, &reply); err != nil { + if err := rS.V1AllocateResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != cacheReply { t.Errorf("Unexpected reply returned: %q", reply) @@ -4773,7 +4776,7 @@ func TestResourcesV1AllocateResourcesCacheReplySet(t *testing.T) { } var reply string - if err := rS.V1AllocateResources(args, &reply); err != nil { + if err := rS.V1AllocateResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != "Approved" { t.Errorf("Unexpected reply returned: %q", reply) @@ -4828,7 +4831,7 @@ func TestResourcesV1AllocateResourcesResAllocErr(t *testing.T) { } var reply string - if err := rS.V1AllocateResources(args, &reply); err == nil || + if err := rS.V1AllocateResources(context.Background(), args, &reply); err == nil || err != utils.ErrResourceUnavailable { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrResourceUnavailable, err) } @@ -4879,15 +4882,15 @@ func TestResourcesV1AllocateResourcesProcessThErr(t *testing.T) { } ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ThresholdSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { return utils.ErrExists }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM - cM := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + cM := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): rpcInternal, }) fltrs := NewFilterS(cfg, nil, dm) @@ -4906,7 +4909,7 @@ func TestResourcesV1AllocateResourcesProcessThErr(t *testing.T) { } var reply string - if err := rS.V1AllocateResources(args, &reply); err == nil || + if err := rS.V1AllocateResources(context.Background(), args, &reply); err == nil || err != utils.ErrPartiallyExecuted { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrPartiallyExecuted, err) } @@ -4951,13 +4954,13 @@ func TestResourcesV1ReleaseResourcesOK(t *testing.T) { }, } var reply string - if err := rS.V1AllocateResources(args, &reply); err != nil { + if err := rS.V1AllocateResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != "Approved" { t.Errorf("Unexpected reply returned: %q", reply) } - if err := rS.V1ReleaseResources(args, &reply); err != nil { + if err := rS.V1ReleaseResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply returned: %q", reply) @@ -5002,7 +5005,7 @@ func TestResourcesV1ReleaseResourcesUsageNotFound(t *testing.T) { }, } var reply string - if err := rS.V1AllocateResources(args, &reply); err != nil { + if err := rS.V1AllocateResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != "Approved" { t.Errorf("Unexpected reply returned: %q", reply) @@ -5021,7 +5024,7 @@ func TestResourcesV1ReleaseResourcesUsageNotFound(t *testing.T) { } experr := `cannot find usage record with id: RU_Test2` - if err := rS.V1ReleaseResources(args, &reply); err == nil || + if err := rS.V1ReleaseResources(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -5066,7 +5069,7 @@ func TestResourcesV1ReleaseResourcesNoMatch(t *testing.T) { } var reply string - if err := rS.V1ReleaseResources(args, &reply); err == nil || + if err := rS.V1ReleaseResources(context.Background(), args, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } @@ -5111,7 +5114,7 @@ func TestResourcesV1ReleaseResourcesMissingParameters(t *testing.T) { var reply string experr := `MANDATORY_IE_MISSING: [UsageID]` - if err := rS.V1ReleaseResources(args, &reply); err == nil || + if err := rS.V1ReleaseResources(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -5126,7 +5129,7 @@ func TestResourcesV1ReleaseResourcesMissingParameters(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [Event]` - if err := rS.V1ReleaseResources(args, &reply); err == nil || + if err := rS.V1ReleaseResources(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -5143,7 +5146,7 @@ func TestResourcesV1ReleaseResourcesMissingParameters(t *testing.T) { } experr = `MANDATORY_IE_MISSING: [ID]` - if err := rS.V1ReleaseResources(args, &reply); err == nil || + if err := rS.V1ReleaseResources(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -5222,7 +5225,7 @@ func TestResourcesV1ReleaseResourcesCacheReplyExists(t *testing.T) { nil, true, utils.NonTransactional) var reply string - if err := rS.V1ReleaseResources(args, &reply); err != nil { + if err := rS.V1ReleaseResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != cacheReply { t.Errorf("Unexpected reply returned: %q", reply) @@ -5299,7 +5302,7 @@ func TestResourcesV1ReleaseResourcesCacheReplySet(t *testing.T) { var reply string experr := `cannot find usage record with id: RU_Test` - if err := rS.V1ReleaseResources(args, &reply); err == nil || + if err := rS.V1ReleaseResources(context.Background(), args, &reply); err == nil || err.Error() != experr { t.Errorf("expected: <%+v>, \nreceived: <%+v>", experr, err) } @@ -5323,15 +5326,15 @@ func TestResourcesV1ReleaseResourcesProcessThErr(t *testing.T) { data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(data, cfg.CacheCfg(), nil) ccM := &ccMock{ - calls: map[string]func(args any, reply any) error{ - utils.ThresholdSv1ProcessEvent: func(args, reply any) error { + calls: map[string]func(ctx *context.Context, args any, reply any) error{ + utils.ThresholdSv1ProcessEvent: func(ctx *context.Context, args, reply any) error { return utils.ErrExists }, }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- ccM - cM := NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + cM := NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): rpcInternal, }) @@ -5395,7 +5398,7 @@ func TestResourcesV1ReleaseResourcesProcessThErr(t *testing.T) { t.Error(err) } - if err := rS.V1ReleaseResources(args, &reply); err == nil || + if err := rS.V1ReleaseResources(context.Background(), args, &reply); err == nil || err != utils.ErrPartiallyExecuted { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrPartiallyExecuted, err) } @@ -5416,7 +5419,7 @@ func TestResourcesStoreResourceError(t *testing.T) { defer config.SetCgrConfig(dft) db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - dm := NewDataManager(db, cfg.CacheCfg(), NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector))) + dm := NewDataManager(db, cfg.CacheCfg(), NewConnManager(cfg, make(map[string]chan birpc.ClientConnector))) rS := NewResourceService(dm, cfg, NewFilterS(cfg, nil, dm), nil) @@ -5450,19 +5453,19 @@ func TestResourcesStoreResourceError(t *testing.T) { } cfg.DataDbCfg().Items[utils.MetaResources].Replicate = true var reply string - if err := rS.V1AllocateResources(args, &reply); err != utils.ErrDisconnected { + if err := rS.V1AllocateResources(context.Background(), args, &reply); err != utils.ErrDisconnected { t.Error(err) } cfg.DataDbCfg().Items[utils.MetaResources].Replicate = false - if err := rS.V1AllocateResources(args, &reply); err != nil { + if err := rS.V1AllocateResources(context.Background(), args, &reply); err != nil { t.Error(err) } else if reply != "Approved" { t.Errorf("Unexpected reply returned: %q", reply) } cfg.DataDbCfg().Items[utils.MetaResources].Replicate = true - if err := rS.V1ReleaseResources(args, &reply); err != utils.ErrDisconnected { + if err := rS.V1ReleaseResources(context.Background(), args, &reply); err != utils.ErrDisconnected { t.Error(err) } } @@ -5800,7 +5803,7 @@ func TestResourceMatchingResourcesForEventLocks3(t *testing.T) { // config.SetCgrConfig(cfg) // data := NewInternalDB(nil, nil, true,cfg.DataDbCfg().Items) // dm := NewDataManager(data, cfg.CacheCfg(), nil) -// connMgr = NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector)) +// connMgr = NewConnManager(cfg, make(map[string]chan birpc.ClientConnector)) // Cache = NewCacheS(cfg, dm, nil) // fltrs := NewFilterS(cfg, nil, dm) @@ -6041,7 +6044,7 @@ func TestResourcesMatchingResourcesForEventCacheSetErr(t *testing.T) { config.SetCgrConfig(cfg) data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(data, cfg.CacheCfg(), nil) - connMgr = NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector)) + connMgr = NewConnManager(cfg, make(map[string]chan birpc.ClientConnector)) Cache = NewCacheS(cfg, dm, nil) fltrs := NewFilterS(cfg, nil, dm) @@ -6081,7 +6084,7 @@ func TestResourcesMatchingResourcesForEventFinalCacheSetErr(t *testing.T) { config.SetCgrConfig(cfg) data := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := NewDataManager(data, cfg.CacheCfg(), nil) - connMgr = NewConnManager(cfg, make(map[string]chan rpcclient.ClientConnector)) + connMgr = NewConnManager(cfg, make(map[string]chan birpc.ClientConnector)) Cache = NewCacheS(cfg, dm, nil) fltrs := NewFilterS(cfg, nil, dm) diff --git a/ers/amqpv1_it_test.go b/ers/amqpv1_it_test.go index e47577690..a46b66876 100644 --- a/ers/amqpv1_it_test.go +++ b/ers/amqpv1_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package ers import ( - "context" "flag" "fmt" "reflect" "testing" "time" + "github.com/cgrates/birpc/context" + amqpv1 "github.com/Azure/go-amqp" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" diff --git a/ers/ers.go b/ers/ers.go index 4a03809bc..68c806057 100644 --- a/ers/ers.go +++ b/ers/ers.go @@ -29,6 +29,7 @@ import ( "sync" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -228,7 +229,7 @@ func (erS *ERService) processEvent(cgrEv *utils.CGREvent, rdrCfg.Flags.ParamValue(utils.MetaRoutesMaxCost), ) rply := new(sessions.V1AuthorizeReply) - err = erS.connMgr.Call(erS.cfg.ERsCfg().SessionSConns, nil, utils.SessionSv1AuthorizeEvent, + err = erS.connMgr.Call(context.TODO(), erS.cfg.ERsCfg().SessionSConns, utils.SessionSv1AuthorizeEvent, authArgs, rply) case utils.MetaInitiate: initArgs := sessions.NewV1InitSessionArgs( @@ -242,7 +243,7 @@ func (erS *ERService) processEvent(cgrEv *utils.CGREvent, rdrCfg.Flags.Has(utils.MetaAccounts), cgrEv, rdrCfg.Flags.Has(utils.MetaFD)) rply := new(sessions.V1InitSessionReply) - err = erS.connMgr.Call(erS.cfg.ERsCfg().SessionSConns, nil, utils.SessionSv1InitiateSession, + err = erS.connMgr.Call(context.TODO(), erS.cfg.ERsCfg().SessionSConns, utils.SessionSv1InitiateSession, initArgs, rply) case utils.MetaUpdate: updateArgs := sessions.NewV1UpdateSessionArgs( @@ -251,7 +252,7 @@ func (erS *ERService) processEvent(cgrEv *utils.CGREvent, rdrCfg.Flags.Has(utils.MetaAccounts), cgrEv, rdrCfg.Flags.Has(utils.MetaFD)) rply := new(sessions.V1UpdateSessionReply) - err = erS.connMgr.Call(erS.cfg.ERsCfg().SessionSConns, nil, utils.SessionSv1UpdateSession, + err = erS.connMgr.Call(context.TODO(), erS.cfg.ERsCfg().SessionSConns, utils.SessionSv1UpdateSession, updateArgs, rply) case utils.MetaTerminate: terminateArgs := sessions.NewV1TerminateSessionArgs( @@ -263,7 +264,7 @@ func (erS *ERService) processEvent(cgrEv *utils.CGREvent, rdrCfg.Flags.ParamsSlice(utils.MetaStats, utils.MetaIDs), cgrEv, rdrCfg.Flags.Has(utils.MetaFD)) rply := utils.StringPointer("") - err = erS.connMgr.Call(erS.cfg.ERsCfg().SessionSConns, nil, utils.SessionSv1TerminateSession, + err = erS.connMgr.Call(context.TODO(), erS.cfg.ERsCfg().SessionSConns, utils.SessionSv1TerminateSession, terminateArgs, rply) case utils.MetaMessage: evArgs := sessions.NewV1ProcessMessageArgs( @@ -283,7 +284,7 @@ func (erS *ERService) processEvent(cgrEv *utils.CGREvent, rdrCfg.Flags.ParamValue(utils.MetaRoutesMaxCost), ) rply := new(sessions.V1ProcessMessageReply) // need it so rpcclient can clone - err = erS.connMgr.Call(erS.cfg.ERsCfg().SessionSConns, nil, utils.SessionSv1ProcessMessage, + err = erS.connMgr.Call(context.TODO(), erS.cfg.ERsCfg().SessionSConns, utils.SessionSv1ProcessMessage, evArgs, rply) if utils.ErrHasPrefix(err, utils.RalsErrorPrfx) { cgrEv.Event[utils.Usage] = 0 // avoid further debits @@ -297,7 +298,7 @@ func (erS *ERService) processEvent(cgrEv *utils.CGREvent, Paginator: cgrArgs, } rply := new(sessions.V1ProcessEventReply) - err = erS.connMgr.Call(erS.cfg.ERsCfg().SessionSConns, nil, utils.SessionSv1ProcessEvent, + err = erS.connMgr.Call(context.TODO(), erS.cfg.ERsCfg().SessionSConns, utils.SessionSv1ProcessEvent, evArgs, rply) case utils.MetaCDRs: // allow CDR processing } @@ -308,7 +309,7 @@ func (erS *ERService) processEvent(cgrEv *utils.CGREvent, if rdrCfg.Flags.Has(utils.MetaCDRs) && !rdrCfg.Flags.Has(utils.MetaDryRun) { rplyCDRs := utils.StringPointer("") - err = erS.connMgr.Call(erS.cfg.ERsCfg().SessionSConns, nil, utils.SessionSv1ProcessCDR, + err = erS.connMgr.Call(context.TODO(), erS.cfg.ERsCfg().SessionSConns, utils.SessionSv1ProcessCDR, cgrEv, rplyCDRs) } diff --git a/ers/ers_it_test.go b/ers/ers_it_test.go index e78158430..2b0f26fc0 100644 --- a/ers/ers_it_test.go +++ b/ers/ers_it_test.go @@ -33,6 +33,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/rpcclient" "github.com/cgrates/cgrates/config" @@ -714,7 +716,7 @@ type testMockClients struct { calls map[string]func(args any, reply any) error } -func (sT *testMockClients) Call(method string, arg any, rply any) error { +func (sT *testMockClients) Call(ctx *context.Context, method string, arg any, rply any) error { if call, has := sT.calls[method]; !has { return rpcclient.ErrUnsupporteServiceMethod } else { @@ -739,9 +741,9 @@ func TestERsProcessEvent11(t *testing.T) { }, }, } - clientChan := make(chan rpcclient.ClientConnector, 1) + clientChan := make(chan birpc.ClientConnector, 1) clientChan <- testMockClient - connMng := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMng := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaSessionS): clientChan, }) srv := NewERService(cfg, fltrS, connMng) diff --git a/ers/ers_reload_it_test.go b/ers/ers_reload_it_test.go index 683a37a6a..3d23ebb62 100644 --- a/ers/ers_reload_it_test.go +++ b/ers/ers_reload_it_test.go @@ -21,11 +21,13 @@ along with this program. If not, see package ers import ( - "net/rpc" "os" "path" "testing" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -34,7 +36,7 @@ import ( var ( reloadCfgPath string reloadCfg *config.CGRConfig - reloadRPC *rpc.Client + reloadRPC *birpc.Client ersReloadConfigDIR string reloadTests = []func(t *testing.T){ @@ -129,7 +131,7 @@ func testReloadVerifyDisabledReaders(t *testing.T) { func testReloadReloadConfigFromPath(t *testing.T) { var reply string - if err := reloadRPC.Call(utils.ConfigSv1ReloadConfig, &config.ReloadArgs{ + if err := reloadRPC.Call(context.Background(), utils.ConfigSv1ReloadConfig, &config.ReloadArgs{ Path: path.Join(*dataDir, "conf", "samples", "ers_reload", "first_reload"), Section: config.ERsJson, }, &reply); err != nil { @@ -141,7 +143,7 @@ func testReloadReloadConfigFromPath(t *testing.T) { func testReloadVerifyFirstReload(t *testing.T) { var reply map[string]any - if err := reloadRPC.Call(utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ + if err := reloadRPC.Call(context.Background(), utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{ Section: config.ERsJson, }, &reply); err != nil { t.Error(err) diff --git a/ers/filecsv_it_test.go b/ers/filecsv_it_test.go index 86b5bb446..ca5f75515 100644 --- a/ers/filecsv_it_test.go +++ b/ers/filecsv_it_test.go @@ -22,13 +22,15 @@ package ers import ( "fmt" - "net/rpc" "os" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -39,7 +41,7 @@ var ( csvCfgPath string csvCfgDIR string csvCfg *config.CGRConfig - csvRPC *rpc.Client + csvRPC *birpc.Client fileContent1 = `dbafe9c8614c785a65aabd116dd3959c3c56f7f6,default,*voice,dsafdsaf,*rated,*out,cgrates.org,call,1001,1001,+4986517174963,2013-11-07 08:42:25 +0000 UTC,2013-11-07 08:42:26 +0000 UTC,10s,1.0100,val_extra3,"",val_extra1 dbafe9c8614c785a65aabd116dd3959c3c56f7f7,default,*voice,dsafdsag,*rated,*out,cgrates.org,call,1001,1001,+4986517174964,2013-11-07 09:42:25 +0000 UTC,2013-11-07 09:42:26 +0000 UTC,20s,1.0100,val_extra3,"",val_extra1 @@ -143,7 +145,7 @@ func testCsvITLoadTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{ FolderPath: path.Join(*dataDir, "tariffplans", "testit")} var loadInst utils.LoadInstance - if err := csvRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := csvRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } @@ -179,14 +181,14 @@ func testCsvITHandleSessionFile(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 10.0 - if err := csvRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := csvRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) } aSessions := make([]*sessions.ExternalSession, 0) - if err := csvRPC.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, + if err := csvRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -203,7 +205,7 @@ func testCsvITHandleSessionFile(t *testing.T) { func testCsvITCheckSession(t *testing.T) { time.Sleep(200 * time.Millisecond) aSessions := make([]*sessions.ExternalSession, 0) - if err := csvRPC.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { + if err := csvRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) @@ -220,7 +222,7 @@ func testCsvITTerminateSession(t *testing.T) { } time.Sleep(100 * time.Millisecond) aSessions := make([]*sessions.ExternalSession, 0) - if err := csvRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || + if err := csvRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -247,7 +249,7 @@ func testCsvITAnalyseCDRs(t *testing.T) { OriginIDs: []string{"SessionFromCsv"}, }, } - if err := csvRPC.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := csvRPC.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -258,7 +260,7 @@ func testCsvITAnalyseCDRs(t *testing.T) { } args.RPCCDRsFilter = &utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}, OriginIDs: []string{"SessionFromCsv"}} - if err := csvRPC.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := csvRPC.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -271,7 +273,7 @@ func testCsvITAnalyseCDRs(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 9.85 - if err := csvRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := csvRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -299,7 +301,7 @@ func testCsvITAnalyzeFilteredCDR(t *testing.T) { Sources: []string{"ers_csv"}, }, } - if err := csvRPC.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := csvRPC.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 2 { t.Error("Unexpected number of CDRs returned: ", utils.ToJSON(cdrs)) @@ -355,7 +357,7 @@ func testCsvITAnalyzeReaderWithFilter(t *testing.T) { Sources: []string{"ers_template_combined"}, }, } - if err := csvRPC.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := csvRPC.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 2 { t.Error("Unexpected number of CDRs returned: ", utils.ToJSON(cdrs)) diff --git a/ers/filefwv_it_test.go b/ers/filefwv_it_test.go index 6ec3f73ef..df431a04b 100644 --- a/ers/filefwv_it_test.go +++ b/ers/filefwv_it_test.go @@ -23,13 +23,15 @@ package ers import ( "fmt" - "net/rpc" "os" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -40,7 +42,7 @@ var ( fwvCfgPath string fwvCfgDIR string fwvCfg *config.CGRConfig - fwvRPC *rpc.Client + fwvRPC *birpc.Client fwvTests = []func(t *testing.T){ testCreateDirs, @@ -125,7 +127,7 @@ func testFWVITLoadTPFromFolder(t *testing.T) { }, } var result string - if err := fwvRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := fwvRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -184,12 +186,12 @@ func testFWVITHandleCdr1File(t *testing.T) { func testFWVITAnalyseCDRs(t *testing.T) { time.Sleep(time.Second) var reply []*engine.ExternalCDR - if err := fwvRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &reply); err != nil { + if err := fwvRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 29 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } - if err := fwvRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{OriginIDs: []string{"CDR0000010"}}, &reply); err != nil { + if err := fwvRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{OriginIDs: []string{"CDR0000010"}}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) diff --git a/ers/filejson_it_test.go b/ers/filejson_it_test.go index bc99c6d4d..53987b798 100644 --- a/ers/filejson_it_test.go +++ b/ers/filejson_it_test.go @@ -24,13 +24,15 @@ package ers import ( "encoding/json" "fmt" - "net/rpc" "os" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" v2 "github.com/cgrates/cgrates/apier/v2" @@ -44,7 +46,7 @@ var ( jsonCfgPath string jsonCfgDIR string jsonCfg *config.CGRConfig - jsonRPC *rpc.Client + jsonRPC *birpc.Client fileContent = ` { @@ -148,7 +150,7 @@ func testJSONAddData(t *testing.T) { utils.CacheOpt: utils.MetaReload, }, } - if err := jsonRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { + if err := jsonRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -158,7 +160,7 @@ func testJSONAddData(t *testing.T) { Tenant: "cgrates.org", Account: "voiceAccount", } - if err := jsonRPC.Call(utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { + if err := jsonRPC.Call(context.Background(), utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { t.Fatal(err) } attrs := &utils.AttrSetBalance{ @@ -172,12 +174,12 @@ func testJSONAddData(t *testing.T) { utils.Weight: 10.0, }, } - if err := jsonRPC.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := jsonRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } var acnt *engine.Account - if err := jsonRPC.Call(utils.APIerSv2GetAccount, + if err := jsonRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "voiceAccount"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 600000000000 { @@ -205,7 +207,7 @@ func testJSONVerify(t *testing.T) { OriginIDs: []string{"testJsonCDR"}, }, } - if err := jsonRPC.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil { + if err := jsonRPC.Call(context.Background(), utils.CDRsV1GetCDRs, args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -216,7 +218,7 @@ func testJSONVerify(t *testing.T) { } var acnt *engine.Account - if err := jsonRPC.Call(utils.APIerSv2GetAccount, + if err := jsonRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "voiceAccount"}, &acnt); err != nil { t.Error(err) } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 480000000000 { diff --git a/ers/filexml_it_test.go b/ers/filexml_it_test.go index 22964c286..cc61ffc74 100644 --- a/ers/filexml_it_test.go +++ b/ers/filexml_it_test.go @@ -22,13 +22,15 @@ package ers import ( "fmt" - "net/rpc" "os" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/utils" "github.com/cgrates/cgrates/config" @@ -39,7 +41,7 @@ var ( xmlCfgPath string xmlCfgDIR string xmlCfg *config.CGRConfig - xmlRPC *rpc.Client + xmlRPC *birpc.Client xmlTests = []func(t *testing.T){ testCreateDirs, @@ -115,7 +117,7 @@ func testXMLITLoadTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{ FolderPath: path.Join(*dataDir, "tariffplans", "testit")} var loadInst utils.LoadInstance - if err := xmlRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := xmlRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } @@ -270,12 +272,12 @@ func testXMLITHandleCdr1File(t *testing.T) { func testXmlITAnalyseCDRs(t *testing.T) { var reply []*engine.ExternalCDR - if err := xmlRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &reply); err != nil { + if err := xmlRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 6 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } - if err := xmlRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{DestinationPrefixes: []string{"+4915117174963"}}, &reply); err != nil { + if err := xmlRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{DestinationPrefixes: []string{"+4915117174963"}}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 3 { t.Error("Unexpected number of CDRs returned: ", len(reply)) diff --git a/ers/flatstore_it_test.go b/ers/flatstore_it_test.go index 8001397fd..4cd302b66 100644 --- a/ers/flatstore_it_test.go +++ b/ers/flatstore_it_test.go @@ -22,13 +22,15 @@ along with this program. If not, see package ers import ( - "net/rpc" "os" "path" "path/filepath" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" @@ -40,7 +42,7 @@ var ( flatstoreCfgPath string flatstoreCfgDIR string flatstoreCfg *config.CGRConfig - flatstoreRPC *rpc.Client + flatstoreRPC *birpc.Client fullSuccessfull = `INVITE|2daec40c|548625ac|dd0c4c617a9919d29a6175cdff223a9e@0:0:0:0:0:0:0:0|200|OK|1436454408|*prepaid|1001|1002||3401:2069362475 BYE|2daec40c|548625ac|dd0c4c617a9919d29a6175cdff223a9e@0:0:0:0:0:0:0:0|200|OK|1436454410|||||3401:2069362475 @@ -167,7 +169,7 @@ func testFlatstoreITLoadTPFromFolder(t *testing.T) { }, } var result string - if err := flatstoreRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := flatstoreRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -229,13 +231,13 @@ func testFlatstoreITHandleCdr1File(t *testing.T) { func testFlatstoreITAnalyseCDRs(t *testing.T) { var reply []*engine.ExternalCDR - if err := flatstoreRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &reply); err != nil { + if err := flatstoreRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 8 { t.Error("Unexpected number of CDRs returned: ", len(reply)) t.Error(utils.ToJSON(reply)) } - if err := flatstoreRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{MinUsage: "1"}, &reply); err != nil { + if err := flatstoreRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{MinUsage: "1"}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 5 { t.Error("Unexpected number of CDRs returned: ", len(reply)) @@ -273,7 +275,7 @@ func testFlatstoreITHandleCdr2File(t *testing.T) { func testFlatstoreITAnalyseCDRs2(t *testing.T) { var reply []*engine.ExternalCDR - if err := flatstoreRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{OriginHosts: []string{"flatStoreACK"}, MinUsage: "1"}, &reply); err != nil { + if err := flatstoreRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{OriginHosts: []string{"flatStoreACK"}, MinUsage: "1"}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 4 { t.Error("Unexpected number of CDRs returned: ", len(reply)) @@ -310,12 +312,12 @@ func testFlatstoreITHandleCdr3File(t *testing.T) { func testFlatstoreITAnalyseCDRs3(t *testing.T) { var reply []*engine.ExternalCDR - if err := flatstoreRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{OriginHosts: []string{"flatstoreMMErs"}}, &reply); err != nil { + if err := flatstoreRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{OriginHosts: []string{"flatstoreMMErs"}}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 3 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } - if err := flatstoreRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{OriginHosts: []string{"flatstoreMMErs"}, MinUsage: "1"}, &reply); err != nil { + if err := flatstoreRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{OriginHosts: []string{"flatstoreMMErs"}, MinUsage: "1"}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 2 { t.Error("Unexpected number of CDRs returned: ", len(reply)) diff --git a/ers/kafka_it_test.go b/ers/kafka_it_test.go index 855e7e1f6..a867263c3 100644 --- a/ers/kafka_it_test.go +++ b/ers/kafka_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package ers import ( - "context" "fmt" "reflect" "testing" "time" + "github.com/cgrates/birpc/context" + "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" diff --git a/ers/lib_test.go b/ers/lib_test.go index aa3e19bc4..b01089744 100644 --- a/ers/lib_test.go +++ b/ers/lib_test.go @@ -21,11 +21,11 @@ package ers import ( "errors" "flag" - "net/rpc" - "net/rpc/jsonrpc" "os" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -37,12 +37,12 @@ var ( dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/ers/partial_csv_it_test.go b/ers/partial_csv_it_test.go index f7c6bee3f..53037a92b 100644 --- a/ers/partial_csv_it_test.go +++ b/ers/partial_csv_it_test.go @@ -22,13 +22,15 @@ along with this program. If not, see package ers import ( - "net/rpc" "os" "path" "strings" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" @@ -40,7 +42,7 @@ var ( partCfgPath string partCfgDIR string partCfg *config.CGRConfig - partRPC *rpc.Client + partRPC *birpc.Client partTests = []func(t *testing.T){ testCreateDirs, @@ -136,7 +138,7 @@ func testPartITLoadTPFromFolder(t *testing.T) { }, } var result string - if err := partRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := partRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -201,17 +203,17 @@ func testPartITVerifyFiles(t *testing.T) { func testPartITAnalyseCDRs(t *testing.T) { var reply []*engine.ExternalCDR - if err := partRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &reply); err != nil { + if err := partRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 2 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } - if err := partRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{DestinationPrefixes: []string{"+4986517174963"}}, &reply); err != nil { + if err := partRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{DestinationPrefixes: []string{"+4986517174963"}}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) } - if err := partRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{DestinationPrefixes: []string{"+4986517174960"}}, &reply); err != nil { + if err := partRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{DestinationPrefixes: []string{"+4986517174960"}}, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) diff --git a/general_tests/a1_it_test.go b/general_tests/a1_it_test.go index 2dccc7ab2..6766d9be3 100644 --- a/general_tests/a1_it_test.go +++ b/general_tests/a1_it_test.go @@ -23,12 +23,13 @@ package general_tests import ( "encoding/json" "fmt" - "net/rpc" "path" "sync" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" @@ -41,7 +42,7 @@ var ( a1ConfigDir string a1CfgPath string a1Cfg *config.CGRConfig - a1rpc *rpc.Client + a1rpc *birpc.Client sTestsA1it = []func(t *testing.T){ testA1itLoadConfig, @@ -112,7 +113,7 @@ func testA1itRPCConn(t *testing.T) { func testA1itLoadTPFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "a1")} - if err := a1rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := a1rpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(reply) @@ -131,7 +132,7 @@ func testA1itLoadTPFromFolder(t *testing.T) { }, } var cc engine.CallCost - if err := a1rpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { + if err := a1rpc.Call(context.Background(), utils.ResponderGetCost, cd, &cc); err != nil { t.Error("Got error on Responder.GetCost: ", err.Error()) } else if cc.Cost != 0.0 { t.Errorf("Calling Responder.GetCost got callcost: %v", cc) @@ -148,7 +149,7 @@ func testA1itLoadTPFromFolder(t *testing.T) { }, } var result string - if err := a1rpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := a1rpc.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -166,14 +167,14 @@ func testA1itAddBalance1(t *testing.T) { utils.ID: "rpdata1_test", }, } - if err := a1rpc.Call(utils.APIerSv1AddBalance, argAdd, &reply); err != nil { + if err := a1rpc.Call(context.Background(), utils.APIerSv1AddBalance, argAdd, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf(reply) } argGet := &utils.AttrGetAccount{Tenant: argAdd.Tenant, Account: argAdd.Account} var acnt *engine.Account - if err := a1rpc.Call(utils.APIerSv2GetAccount, argGet, &acnt); err != nil { + if err := a1rpc.Call(context.Background(), utils.APIerSv2GetAccount, argGet, &acnt); err != nil { t.Error(err) } else { if acnt.BalanceMap[utils.MetaData].GetTotalValue() != argAdd.Value { // We expect 11.5 since we have added in the previous test 1.5 @@ -213,7 +214,7 @@ func testA1itDataSession1(t *testing.T) { } var initRpl *sessions.V1InitSessionReply - if err := a1rpc.Call(utils.SessionSv1InitiateSession, + if err := a1rpc.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Fatal(err) } @@ -253,7 +254,7 @@ func testA1itDataSession1(t *testing.T) { usage = 2097152 var updateRpl *sessions.V1UpdateSessionReply - if err := a1rpc.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := a1rpc.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } if updateRpl.MaxUsage == nil || *updateRpl.MaxUsage != usage { @@ -285,11 +286,11 @@ func testA1itDataSession1(t *testing.T) { } var rpl string - if err := a1rpc.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := a1rpc.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } - if err := a1rpc.Call(utils.SessionSv1ProcessCDR, termArgs.CGREvent, &rpl); err != nil { + if err := a1rpc.Call(context.Background(), utils.SessionSv1ProcessCDR, termArgs.CGREvent, &rpl); err != nil { t.Error(err) } else if rpl != utils.OK { t.Errorf("Received reply: %s", rpl) @@ -299,7 +300,7 @@ func testA1itDataSession1(t *testing.T) { var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}} - if err := a1rpc.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := a1rpc.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -322,7 +323,7 @@ func testA1itDataSession1(t *testing.T) { } expBalance := float64(10000000000 - 2202800) // initial - total usage var acnt *engine.Account - if err := a1rpc.Call(utils.APIerSv2GetAccount, + if err := a1rpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "rpdata1"}, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaData].GetTotalValue() != expBalance { // We expect 11.5 since we have added in the previous test 1.5 @@ -346,7 +347,7 @@ func testA1itConcurrentAPs(t *testing.T) { ActionPlanIDs: []string{"PACKAGE_1"}, } var reply string - if err := a1rpc.Call(utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { + if err := a1rpc.Call(context.Background(), utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { t.Error(err) } wg.Done() @@ -355,7 +356,7 @@ func testA1itConcurrentAPs(t *testing.T) { wg.Wait() // Make sure action plan was properly set var aps []*engine.ActionPlan - if err := a1rpc.Call(utils.APIerSv1GetActionPlan, &v1.AttrGetActionPlan{ID: "PACKAGE_1"}, &aps); err != nil { + if err := a1rpc.Call(context.Background(), utils.APIerSv1GetActionPlan, &v1.AttrGetActionPlan{ID: "PACKAGE_1"}, &aps); err != nil { t.Error(err) } else if len(aps[0].AccountIDs.Slice()) != len(acnts) { t.Errorf("Received: %+v", aps[0]) @@ -365,7 +366,7 @@ func testA1itConcurrentAPs(t *testing.T) { wg.Add(3) go func(acnt string) { var atms []*v1.AccountActionTiming - if err := a1rpc.Call(utils.APIerSv1GetAccountActionPlan, + if err := a1rpc.Call(context.Background(), utils.APIerSv1GetAccountActionPlan, &utils.TenantAccount{Tenant: "cgrates.org", Account: acnt}, &atms); err != nil { t.Error(err) //} else if len(atms) != 2 || atms[0].ActionPlanId != "PACKAGE_1" { @@ -375,7 +376,7 @@ func testA1itConcurrentAPs(t *testing.T) { }(acnt) go func(acnt string) { var reply string - if err := a1rpc.Call(utils.APIerSv1RemoveActionTiming, + if err := a1rpc.Call(context.Background(), utils.APIerSv1RemoveActionTiming, &v1.AttrRemoveActionTiming{Tenant: "cgrates.org", Account: acnt, ActionPlanId: "PACKAGE_1"}, &reply); err != nil { t.Error(err) } @@ -388,7 +389,7 @@ func testA1itConcurrentAPs(t *testing.T) { ActionPlanIDs: []string{"PACKAGE_2"}, } var reply string - if err := a1rpc.Call(utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { + if err := a1rpc.Call(context.Background(), utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { t.Error(err) } wg.Done() @@ -397,13 +398,13 @@ func testA1itConcurrentAPs(t *testing.T) { wg.Wait() // Make sure action plan was properly rem/set aps = []*engine.ActionPlan{} - if err := a1rpc.Call(utils.APIerSv1GetActionPlan, &v1.AttrGetActionPlan{ID: "PACKAGE_1"}, &aps); err != nil { + if err := a1rpc.Call(context.Background(), utils.APIerSv1GetActionPlan, &v1.AttrGetActionPlan{ID: "PACKAGE_1"}, &aps); err != nil { t.Error(err) } else if len(aps[0].AccountIDs.Slice()) != 0 { t.Errorf("Received: %+v", aps[0]) } aps = []*engine.ActionPlan{} - if err := a1rpc.Call(utils.APIerSv1GetActionPlan, &v1.AttrGetActionPlan{ID: "PACKAGE_2"}, &aps); err != nil { + if err := a1rpc.Call(context.Background(), utils.APIerSv1GetActionPlan, &v1.AttrGetActionPlan{ID: "PACKAGE_2"}, &aps); err != nil { t.Error(err) } else if len(aps[0].AccountIDs.Slice()) != len(acnts) { t.Errorf("Received: %+v", aps[0]) diff --git a/general_tests/accounts_it_test.go b/general_tests/accounts_it_test.go index d37f27efc..2b7524a7b 100644 --- a/general_tests/accounts_it_test.go +++ b/general_tests/accounts_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -34,7 +35,7 @@ import ( var ( accCfgPath string accCfg *config.CGRConfig - accRpc *rpc.Client + accRpc *birpc.Client accConfDIR string //run tests for specific configuration account *engine.Account accDelay int @@ -118,7 +119,7 @@ func testV1AccRpcConn(t *testing.T) { func testV1AccGetAccountBeforeSet(t *testing.T) { var reply *engine.Account - if err := accRpc.Call(utils.APIerSv2GetAccount, + if err := accRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -128,7 +129,7 @@ func testV1AccGetAccountBeforeSet(t *testing.T) { func testV1AccLoadTarrifPlans(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := accRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := accRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -138,7 +139,7 @@ func testV1AccLoadTarrifPlans(t *testing.T) { func testV1AccGetAccountAfterLoad(t *testing.T) { var reply *engine.Account - if err := accRpc.Call(utils.APIerSv2GetAccount, + if err := accRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &reply); err != nil { t.Error(err) @@ -147,7 +148,7 @@ func testV1AccGetAccountAfterLoad(t *testing.T) { func testV1AccRemAccount(t *testing.T) { var reply string - if err := accRpc.Call(utils.APIerSv1RemoveAccount, + if err := accRpc.Call(context.Background(), utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{Tenant: "cgrates.org", Account: "1001"}, &reply); err != nil { t.Error(err) @@ -158,7 +159,7 @@ func testV1AccRemAccount(t *testing.T) { func testV1AccGetAccountAfterDelete(t *testing.T) { var reply *engine.Account - if err := accRpc.Call(utils.APIerSv2GetAccount, + if err := accRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -167,7 +168,7 @@ func testV1AccGetAccountAfterDelete(t *testing.T) { func testV1AccSetAccount(t *testing.T) { var reply string - if err := accRpc.Call(utils.APIerSv2SetAccount, + if err := accRpc.Call(context.Background(), utils.APIerSv2SetAccount, &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "testacc"}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -177,7 +178,7 @@ func testV1AccSetAccount(t *testing.T) { func testV1AccGetAccountAfterSet(t *testing.T) { var reply *engine.Account - if err := accRpc.Call(utils.APIerSv2GetAccount, + if err := accRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testacc"}, &reply); err != nil { t.Error(err) } @@ -185,7 +186,7 @@ func testV1AccGetAccountAfterSet(t *testing.T) { func testV1AccRemAccountSet(t *testing.T) { var reply string - if err := accRpc.Call(utils.APIerSv1RemoveAccount, + if err := accRpc.Call(context.Background(), utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{Tenant: "cgrates.org", Account: "testacc"}, &reply); err != nil { t.Error(err) @@ -196,7 +197,7 @@ func testV1AccRemAccountSet(t *testing.T) { func testV1AccGetAccountSetAfterDelete(t *testing.T) { var reply *engine.Account - if err := accRpc.Call(utils.APIerSv2GetAccount, + if err := accRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testacc"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -207,7 +208,7 @@ func testV1AccGetAccountSetAfterDelete(t *testing.T) { Need to investigate for redis why didn't return not found func testV1AccRemAccountAfterDelete(t *testing.T) { var reply string - if err := accRpc.Call(utils.APIerSv1RemoveAccount, + if err := accRpc.Call(context.Background(),utils.APIerSv1RemoveAccount, &utils.AttrRemoveAccount{Tenant: "cgrates.org", Account: "testacc"}, &reply); err == nil || err.Error() != utils.NewErrServerError(utils.ErrNotFound).Error() { t.Error(err) @@ -220,7 +221,7 @@ func testV1AccMonthly(t *testing.T) { timeAfter := time.Now().Add(10*time.Second).AddDate(0, 1, 0) timeBefore := time.Now().Add(-10*time.Second).AddDate(0, 1, 0) var reply *engine.Account - if err := accRpc.Call(utils.APIerSv2GetAccount, + if err := accRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1002"}, &reply); err != nil { t.Error(err) @@ -244,7 +245,7 @@ func testV1AccSendToThreshold(t *testing.T) { {Identifier: utils.MetaDisableAccount}, {Identifier: utils.MetaLog}, }} - if err := accRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := accRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -264,7 +265,7 @@ func testV1AccSendToThreshold(t *testing.T) { }, } - if err := accRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { + if err := accRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -279,7 +280,7 @@ func testV1AccSendToThreshold(t *testing.T) { utils.ID: "testAccSetBalance", }, } - if err := accRpc.Call(utils.APIerSv1SetBalance, attrs, &reply); err != nil { + if err := accRpc.Call(context.Background(), utils.APIerSv1SetBalance, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetBalance received: %s", reply) @@ -293,7 +294,7 @@ func testV1AccSendToThreshold(t *testing.T) { Tenant: "cgrates.org", Account: "testAccThreshold", } - if err := accRpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := accRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.Disabled != true { t.Errorf("Expecting: true, received: %v", acnt.Disabled) diff --git a/general_tests/accountswiththresholds_it_test.go b/general_tests/accountswiththresholds_it_test.go index af0d84e8d..35a71d3e8 100644 --- a/general_tests/accountswiththresholds_it_test.go +++ b/general_tests/accountswiththresholds_it_test.go @@ -21,12 +21,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -35,7 +36,7 @@ import ( var ( accWThdCfgPath string accWThdCfg *config.CGRConfig - accWThdRpc *rpc.Client + accWThdRpc *birpc.Client accWThdConfDIR string //run tests for specific configuration accWThdDelay int @@ -123,7 +124,7 @@ func testAccWThdSetThresholdProfile(t *testing.T) { }, } var reply string - if err := accWThdRpc.Call(utils.APIerSv1SetThresholdProfile, ThdPrf, &reply); err != nil { + if err := accWThdRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, ThdPrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -134,7 +135,7 @@ func testAccWThdSetThresholdProfile(t *testing.T) { } var result1 *engine.ThresholdProfile - if err := accWThdRpc.Call(utils.APIerSv1GetThresholdProfile, args, &result1); err != nil { + if err := accWThdRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, args, &result1); err != nil { t.Error(err) } else if !reflect.DeepEqual(result1, ThdPrf.ThresholdProfile) { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", utils.ToJSON(ThdPrf.ThresholdProfile), utils.ToJSON(result1)) @@ -154,7 +155,7 @@ func testAccWThdGetThresholdBeforeDebit(t *testing.T) { } var result2 *engine.Threshold - if err := accWThdRpc.Call(utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: args}, &result2); err != nil { + if err := accWThdRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: args}, &result2); err != nil { t.Error(err) } else if result2.Snooze = expThd.Snooze; !reflect.DeepEqual(result2, expThd) { t.Errorf("\nexpected: <%+v>, \nreceived: <%+v>", utils.ToJSON(expThd), utils.ToJSON(result2)) @@ -172,7 +173,7 @@ func testAccWThdSetBalance(t *testing.T) { }, } var reply string - if err := accWThdRpc.Call(utils.APIerSv2SetBalance, args, &reply); err != nil { + if err := accWThdRpc.Call(context.Background(), utils.APIerSv2SetBalance, args, &reply); err != nil { t.Error("Got error on SetBalance: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling SetBalance received: %s", reply) @@ -186,7 +187,7 @@ func testAccWThdGetAccountBeforeDebit(t *testing.T) { Tenant: "cgrates.org", Account: "1002", } - if err := accWThdRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := accWThdRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != exp { t.Errorf("Expecting: %v, received: %v", @@ -211,7 +212,7 @@ func testAccWThdDebit1(t *testing.T) { RunID: utils.MetaDefault, } cc := new(engine.CallCost) - err = accWThdRpc.Call(utils.ResponderMaxDebit, &engine.CallDescriptorWithAPIOpts{ + err = accWThdRpc.Call(context.Background(), utils.ResponderMaxDebit, &engine.CallDescriptorWithAPIOpts{ CallDescriptor: cd, }, cc) if err != nil { @@ -236,7 +237,7 @@ func testAccWThdDebit2(t *testing.T) { RunID: utils.MetaDefault, } cc := new(engine.CallCost) - err = accWThdRpc.Call(utils.ResponderMaxDebit, &engine.CallDescriptorWithAPIOpts{ + err = accWThdRpc.Call(context.Background(), utils.ResponderMaxDebit, &engine.CallDescriptorWithAPIOpts{ CallDescriptor: cd, }, cc) if err != nil { @@ -251,7 +252,7 @@ func testAccWThdGetAccountAfterDebit(t *testing.T) { Tenant: "cgrates.org", Account: "1002", } - if err := accWThdRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := accWThdRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != exp { t.Errorf("Expecting: %v, received: %v", @@ -261,7 +262,7 @@ func testAccWThdGetAccountAfterDebit(t *testing.T) { func testAccWThdGetThresholdAfterDebit(t *testing.T) { var result2 *engine.Threshold - if err := accWThdRpc.Call(utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1002"}}, &result2); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := accWThdRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1002"}}, &result2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } diff --git a/general_tests/all_cfg_sect_rld_it_test.go b/general_tests/all_cfg_sect_rld_it_test.go index e6d411ba4..4732a0f80 100644 --- a/general_tests/all_cfg_sect_rld_it_test.go +++ b/general_tests/all_cfg_sect_rld_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -35,7 +36,7 @@ var ( testSectCfgDir string testSectCfgPath string testSectCfg *config.CGRConfig - testSectRPC *rpc.Client + testSectRPC *birpc.Client testSectTests = []func(t *testing.T){ testSectLoadConfig, @@ -153,13 +154,13 @@ func testSectRPCConn(t *testing.T) { func testSectConfigSReloadCores(t *testing.T) { var replyPingBf string - if err := testSectRPC.Call(utils.CoreSv1Ping, &utils.CGREvent{}, &replyPingBf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.CoreSv1Ping, &utils.CGREvent{}, &replyPingBf); err != nil { t.Error(err) } else if replyPingBf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingBf) } var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"cores\":{\"caps\":0,\"caps_stats_interval\":\"0\",\"caps_strategy\":\"*busy\",\"shutdown_timeout\":\"1s\"}}", }, &reply); err != nil { @@ -169,7 +170,7 @@ func testSectConfigSReloadCores(t *testing.T) { } cfgStr := "{\"cores\":{\"caps\":0,\"caps_stats_interval\":\"0\",\"caps_strategy\":\"*busy\",\"shutdown_timeout\":\"1s\"}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.CoreSCfgJson, }, &rpl); err != nil { @@ -179,7 +180,7 @@ func testSectConfigSReloadCores(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.CoreSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.CoreSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -189,7 +190,7 @@ func testSectConfigSReloadCores(t *testing.T) { func testSectConfigSReloadRPCConns(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"rpc_conns\":{\"*bijson_localhost\":{\"conns\":[{\"address\":\"127.0.0.1:2014\",\"transport\":\"*birpc_json\"}],\"poolSize\":0,\"strategy\":\"*first\"},\"*birpc_internal\":{\"conns\":[{\"address\":\"*birpc_internal\",\"transport\":\"\"}],\"poolSize\":0,\"strategy\":\"*first\"},\"*internal\":{\"conns\":[{\"address\":\"*internal\",\"transport\":\"\"}],\"poolSize\":0,\"strategy\":\"*first\"},\"*localhost\":{\"conns\":[{\"address\":\"127.0.0.1:2012\",\"transport\":\"*json\"}],\"poolSize\":0,\"strategy\":\"*first\"}}}", }, &reply); err != nil { @@ -199,7 +200,7 @@ func testSectConfigSReloadRPCConns(t *testing.T) { } cfgStr := "{\"rpc_conns\":{\"*bijson_localhost\":{\"conns\":[{\"address\":\"127.0.0.1:2014\",\"transport\":\"*birpc_json\"}],\"poolSize\":0,\"strategy\":\"*first\"},\"*birpc_internal\":{\"conns\":[{\"address\":\"*birpc_internal\",\"transport\":\"\"}],\"poolSize\":0,\"strategy\":\"*first\"},\"*internal\":{\"conns\":[{\"address\":\"*internal\",\"transport\":\"\"}],\"poolSize\":0,\"strategy\":\"*first\"},\"*localhost\":{\"conns\":[{\"address\":\"127.0.0.1:2012\",\"transport\":\"*json\"}],\"poolSize\":0,\"strategy\":\"*first\"}}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.RPCConnsJsonName, }, &rpl); err != nil { @@ -212,7 +213,7 @@ func testSectConfigSReloadRPCConns(t *testing.T) { func testSectConfigSReloadDataDB(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"data_db\":{\"db_host\":\"127.0.0.1\",\"db_name\":\"10\",\"db_password\":\"\",\"db_port\":6379,\"db_type\":\"*internal\",\"db_user\":\"cgrates\",\"items\":{\"*account_action_plans\":{\"remote\":false,\"replicate\":false},\"*accounts\":{\"remote\":false,\"replicate\":false},\"*action_plans\":{\"remote\":false,\"replicate\":false},\"*action_triggers\":{\"remote\":false,\"replicate\":false},\"*actions\":{\"remote\":false,\"replicate\":false},\"*attribute_profiles\":{\"remote\":false,\"replicate\":false},\"*charger_profiles\":{\"remote\":false,\"replicate\":false},\"*destinations\":{\"remote\":false,\"replicate\":false},\"*dispatcher_hosts\":{\"remote\":false,\"replicate\":false},\"*dispatcher_profiles\":{\"remote\":false,\"replicate\":false},\"*filters\":{\"remote\":false,\"replicate\":false},\"*indexes\":{\"remote\":false,\"replicate\":false},\"*load_ids\":{\"remote\":false,\"replicate\":false},\"*rating_plans\":{\"remote\":false,\"replicate\":false},\"*rating_profiles\":{\"remote\":false,\"replicate\":false},\"*resource_profiles\":{\"remote\":false,\"replicate\":false},\"*resources\":{\"remote\":false,\"replicate\":false},\"*reverse_destinations\":{\"remote\":false,\"replicate\":false},\"*route_profiles\":{\"remote\":false,\"replicate\":false},\"*shared_groups\":{\"remote\":false,\"replicate\":false},\"*statqueue_profiles\":{\"remote\":false,\"replicate\":false},\"*statqueues\":{\"remote\":false,\"replicate\":false},\"*threshold_profiles\":{\"remote\":false,\"replicate\":false},\"*thresholds\":{\"remote\":false,\"replicate\":false},\"*timings\":{\"remote\":false,\"replicate\":false}},\"opts\":{\"mongoQueryTimeout\":\"10s\",\"redisCACertificate\":\"\",\"redisClientCertificate\":\"\",\"redisClientKey\":\"\",\"redisCluster\":false,\"redisClusterOndownDelay\":\"0\",\"redisClusterSync\":\"5s\",\"redisSentinel\":\"\",\"redisTLS\":false},\"remote_conn_id\":\"\",\"remote_conns\":[],\"replication_cache\":\"\",\"replication_conns\":[],\"replication_filtered\":false}}", }, &reply); err != nil { @@ -222,7 +223,7 @@ func testSectConfigSReloadDataDB(t *testing.T) { } cfgStr := "{\"data_db\":{\"db_host\":\"127.0.0.1\",\"db_name\":\"10\",\"db_password\":\"\",\"db_port\":6379,\"db_type\":\"*internal\",\"db_user\":\"cgrates\",\"items\":{\"*account_action_plans\":{\"remote\":false,\"replicate\":false},\"*accounts\":{\"remote\":false,\"replicate\":false},\"*action_plans\":{\"remote\":false,\"replicate\":false},\"*action_triggers\":{\"remote\":false,\"replicate\":false},\"*actions\":{\"remote\":false,\"replicate\":false},\"*attribute_profiles\":{\"remote\":false,\"replicate\":false},\"*charger_profiles\":{\"remote\":false,\"replicate\":false},\"*destinations\":{\"remote\":false,\"replicate\":false},\"*dispatcher_hosts\":{\"remote\":false,\"replicate\":false},\"*dispatcher_profiles\":{\"remote\":false,\"replicate\":false},\"*filters\":{\"remote\":false,\"replicate\":false},\"*indexes\":{\"remote\":false,\"replicate\":false},\"*load_ids\":{\"remote\":false,\"replicate\":false},\"*rating_plans\":{\"remote\":false,\"replicate\":false},\"*rating_profiles\":{\"remote\":false,\"replicate\":false},\"*resource_profiles\":{\"remote\":false,\"replicate\":false},\"*resources\":{\"remote\":false,\"replicate\":false},\"*reverse_destinations\":{\"remote\":false,\"replicate\":false},\"*route_profiles\":{\"remote\":false,\"replicate\":false},\"*shared_groups\":{\"remote\":false,\"replicate\":false},\"*statqueue_profiles\":{\"remote\":false,\"replicate\":false},\"*statqueues\":{\"remote\":false,\"replicate\":false},\"*threshold_profiles\":{\"remote\":false,\"replicate\":false},\"*thresholds\":{\"remote\":false,\"replicate\":false},\"*timings\":{\"remote\":false,\"replicate\":false}},\"opts\":{\"mongoQueryTimeout\":\"10s\",\"redisCACertificate\":\"\",\"redisClientCertificate\":\"\",\"redisClientKey\":\"\",\"redisCluster\":false,\"redisClusterOndownDelay\":\"0\",\"redisClusterSync\":\"5s\",\"redisSentinel\":\"\",\"redisTLS\":false},\"remote_conn_id\":\"\",\"remote_conns\":[],\"replication_cache\":\"\",\"replication_conns\":[],\"replication_filtered\":false}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.DATADB_JSN, }, &rpl); err != nil { @@ -235,7 +236,7 @@ func testSectConfigSReloadDataDB(t *testing.T) { func testSectConfigSReloadStorDB(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"stor_db\":{\"db_host\":\"127.0.0.1\",\"db_name\":\"cgrates\",\"db_password\":\"CGRateS.org\",\"db_port\":3306,\"db_type\":\"*internal\",\"db_user\":\"cgrates\",\"items\":{\"*cdrs\":{\"remote\":false,\"replicate\":false},\"*tp_actions\":{\"remote\":false,\"replicate\":false},\"*tp_attributes\":{\"remote\":false,\"replicate\":false},\"*tp_chargers\":{\"remote\":false,\"replicate\":false},\"*tp_destination_rates\":{\"remote\":false,\"replicate\":false},\"*tp_dispatcher_hosts\":{\"remote\":false,\"replicate\":false},\"*tp_dispatcher_profiles\":{\"remote\":false,\"replicate\":false},\"*tp_filters\":{\"remote\":false,\"replicate\":false},\"*tp_rates\":{\"remote\":false,\"replicate\":false},\"*tp_rating_plans\":{\"remote\":false,\"replicate\":false},\"*tp_shared_groups\":{\"remote\":false,\"replicate\":false},\"*tp_stats\":{\"remote\":false,\"replicate\":false},\"*tp_thresholds\":{\"remote\":false,\"replicate\":false},\"*tp_timings\":{\"remote\":false,\"replicate\":false},\"opts\":{\"mongoQueryTimeout\":\"10s\",\"mysqlLocation\":\"Local\",\"postgresSSLMode\":\"disable\",\"sqlConnMaxLifetime\":0,\"sqlMaxIdleConns\":10,\"sqlMaxOpenConns\":100},\"prefix_indexed_fields\":[],\"remote_conns\":null,\"replication_conns\":null,\"string_indexed_fields\":[]}}", }, &reply); err != nil { @@ -245,7 +246,7 @@ func testSectConfigSReloadStorDB(t *testing.T) { } cfgStr := "{\"stor_db\":{\"db_host\":\"127.0.0.1\",\"db_name\":\"cgrates\",\"db_password\":\"CGRateS.org\",\"db_port\":3306,\"db_type\":\"*internal\",\"db_user\":\"cgrates\",\"items\":{\"*cdrs\":{\"remote\":false,\"replicate\":false},\"*tp_action_triggers\":{\"remote\":false,\"replicate\":false},\"*tp_actions\":{\"remote\":false,\"replicate\":false},\"*tp_attributes\":{\"remote\":false,\"replicate\":false},\"*tp_chargers\":{\"remote\":false,\"replicate\":false},\"*tp_destination_rates\":{\"remote\":false,\"replicate\":false},\"*tp_dispatcher_hosts\":{\"remote\":false,\"replicate\":false},\"*tp_dispatcher_profiles\":{\"remote\":false,\"replicate\":false},\"*tp_filters\":{\"remote\":false,\"replicate\":false},\"*tp_rates\":{\"remote\":false,\"replicate\":false},\"*tp_rating_plans\":{\"remote\":false,\"replicate\":false},\"*tp_shared_groups\":{\"remote\":false,\"replicate\":false},\"*tp_stats\":{\"remote\":false,\"replicate\":false},\"*tp_thresholds\":{\"remote\":false,\"replicate\":false},\"*tp_timings\":{\"remote\":false,\"replicate\":false},\"opts\":{\"mongoQueryTimeout\":\"10s\",\"mysqlLocation\":\"Local\",\"postgresSSLMode\":\"disable\",\"sqlConnMaxLifetime\":0,\"sqlMaxIdleConns\":10,\"sqlMaxOpenConns\":100},\"prefix_indexed_fields\":[],\"remote_conns\":null,\"replication_conns\":null,\"string_indexed_fields\":[]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.STORDB_JSN, }, &rpl); err != nil { @@ -258,7 +259,7 @@ func testSectConfigSReloadStorDB(t *testing.T) { func testSectConfigSReloadListen(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"listen\":{\"http\":\":2080\",\"http_tls\":\"127.0.0.1:2280\",\"rpc_gob\":\":2013\",\"rpc_gob_tls\":\"127.0.0.1:2023\",\"rpc_json\":\":2012\",\"rpc_json_tls\":\"127.0.0.1:2022\"}}", }, &reply); err != nil { @@ -268,7 +269,7 @@ func testSectConfigSReloadListen(t *testing.T) { } cfgStr := "{\"listen\":{\"http\":\":2080\",\"http_tls\":\"127.0.0.1:2280\",\"rpc_gob\":\":2013\",\"rpc_gob_tls\":\"127.0.0.1:2023\",\"rpc_json\":\":2012\",\"rpc_json_tls\":\"127.0.0.1:2022\"}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.LISTEN_JSN, }, &rpl); err != nil { @@ -281,7 +282,7 @@ func testSectConfigSReloadListen(t *testing.T) { func testSectConfigSReloadTLS(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"tls\":{\"ca_certificate\":\"\",\"client_certificate\":\"\",\"client_key\":\"\",\"server_certificate\":\"\",\"server_key\":\"\",\"server_name\":\"\",\"server_policy\":4}}", }, &reply); err != nil { @@ -291,7 +292,7 @@ func testSectConfigSReloadTLS(t *testing.T) { } cfgStr := "{\"tls\":{\"ca_certificate\":\"\",\"client_certificate\":\"\",\"client_key\":\"\",\"server_certificate\":\"\",\"server_key\":\"\",\"server_name\":\"\",\"server_policy\":4}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.TlsCfgJson, }, &rpl); err != nil { @@ -304,7 +305,7 @@ func testSectConfigSReloadTLS(t *testing.T) { func testSectConfigSReloadHTTP(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"http\":{\"auth_users\":{},\"client_opts\":{\"dialFallbackDelay\":\"300ms\",\"dialKeepAlive\":\"30s\",\"dialTimeout\":\"30s\",\"disableCompression\":false,\"disableKeepAlives\":false,\"expectContinueTimeout\":\"0\",\"forceAttemptHttp2\":true,\"idleConnTimeout\":\"90s\",\"maxConnsPerHost\":0,\"maxIdleConns\":100,\"maxIdleConnsPerHost\":2,\"responseHeaderTimeout\":\"0\",\"skipTlsVerify\":false,\"tlsHandshakeTimeout\":\"10s\"},\"freeswitch_cdrs_url\":\"/freeswitch_json\",\"http_cdrs\":\"/cdr_http\",\"json_rpc_url\":\"/jsonrpc\",\"registrars_url\":\"/registrar\",\"use_basic_auth\":false,\"ws_url\":\"/ws\"}}", }, &reply); err != nil { @@ -315,7 +316,7 @@ func testSectConfigSReloadHTTP(t *testing.T) { cfgStr := "{\"http\":{\"auth_users\":{},\"client_opts\":{\"dialFallbackDelay\":\"300ms\",\"dialKeepAlive\":\"30s\",\"dialTimeout\":\"30s\",\"disableCompression\":false,\"disableKeepAlives\":false,\"expectContinueTimeout\":\"0s\",\"forceAttemptHttp2\":true,\"idleConnTimeout\":\"1m30s\",\"maxConnsPerHost\":0,\"maxIdleConns\":100,\"maxIdleConnsPerHost\":2,\"responseHeaderTimeout\":\"0s\",\"skipTlsVerify\":false,\"tlsHandshakeTimeout\":\"10s\"},\"freeswitch_cdrs_url\":\"/freeswitch_json\",\"http_cdrs\":\"/cdr_http\",\"json_rpc_url\":\"/jsonrpc\",\"registrars_url\":\"/registrar\",\"use_basic_auth\":false,\"ws_url\":\"/ws\"}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.HTTP_JSN, }, &rpl); err != nil { @@ -328,14 +329,14 @@ func testSectConfigSReloadHTTP(t *testing.T) { func testSectConfigSReloadSchedulers(t *testing.T) { var replyPingBf string - if err := testSectRPC.Call(utils.SchedulerSv1Ping, &utils.CGREvent{}, &replyPingBf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.SchedulerSv1Ping, &utils.CGREvent{}, &replyPingBf); err != nil { t.Error(err) } else if replyPingBf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingBf) } var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"schedulers\":{\"cdrs_conns\":[\"*internal\"],\"dynaprepaid_actionplans\":[],\"enabled\":true,\"filters\":[],\"stats_conns\":[\"*localhost\"],\"thresholds_conns\":[]}}", }, &reply); err != nil { @@ -345,7 +346,7 @@ func testSectConfigSReloadSchedulers(t *testing.T) { } cfgStr := "{\"schedulers\":{\"cdrs_conns\":[\"*internal\"],\"dynaprepaid_actionplans\":[],\"enabled\":true,\"filters\":[],\"stats_conns\":[\"*localhost\"],\"thresholds_conns\":[]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.SCHEDULER_JSN, }, &rpl); err != nil { @@ -355,7 +356,7 @@ func testSectConfigSReloadSchedulers(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.SchedulerSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.SchedulerSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -365,14 +366,14 @@ func testSectConfigSReloadSchedulers(t *testing.T) { func testSectConfigSReloadCaches(t *testing.T) { var replyPingBf string - if err := testSectRPC.Call(utils.CacheSv1Ping, &utils.CGREvent{}, &replyPingBf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.CacheSv1Ping, &utils.CGREvent{}, &replyPingBf); err != nil { t.Error(err) } else if replyPingBf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingBf) } var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"caches\":{\"partitions\":{\"*account_action_plans\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*action_plans\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*action_triggers\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*actions\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*apiban\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"2m0s\"},\"*attribute_filter_indexes\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*attribute_profiles\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*caps_events\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*cdr_ids\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"10m0s\"},\"*charger_filter_indexes\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*charger_profiles\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*closed_sessions\":{\"limit\":-1,\"precache\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"10s\"},\"*destinations\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*diameter_messages\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"3h0m0s\"},\"*dispatcher_filter_indexes\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*dispatcher_hosts\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*dispatcher_loads\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*dispatcher_profiles\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*dispatcher_routes\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*dispatchers\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*event_charges\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"10s\"},\"*event_resources\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*filters\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*load_ids\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*rating_plans\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*rating_profiles\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*replication_hosts\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*resource_filter_indexes\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*resource_profiles\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*resources\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*reverse_destinations\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*reverse_filter_indexes\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*route_filter_indexes\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*route_profiles\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*rpc_connections\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*rpc_responses\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"2s\"},\"*shared_groups\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*stat_filter_indexes\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*statqueue_profiles\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*statqueues\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*stir\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"3h0m0s\"},\"*threshold_filter_indexes\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*threshold_profiles\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*thresholds\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*timings\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false},\"*tmp_rating_profiles\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"1m0s\"},\"*uch\":{\"limit\":0,\"precache\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"3h0m0s\"}},\"replication_conns\":[]}}", }, &reply); err != nil { @@ -382,7 +383,7 @@ func testSectConfigSReloadCaches(t *testing.T) { } cfgStr := "{\"caches\":{\"partitions\":{\"*account_action_plans\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*action_plans\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*action_triggers\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*actions\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*apiban\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"2m0s\"},\"*attribute_filter_indexes\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*attribute_profiles\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*caps_events\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*cdr_ids\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"10m0s\"},\"*charger_filter_indexes\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*charger_profiles\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*closed_sessions\":{\"limit\":-1,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"10s\"},\"*destinations\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*diameter_messages\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"3h0m0s\"},\"*dispatcher_filter_indexes\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*dispatcher_hosts\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*dispatcher_loads\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*dispatcher_profiles\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*dispatcher_routes\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*dispatchers\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*event_charges\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"10s\"},\"*event_resources\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*filters\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*load_ids\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*rating_plans\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*rating_profiles\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*replication_hosts\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*resource_filter_indexes\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*resource_profiles\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*resources\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*reverse_destinations\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*reverse_filter_indexes\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*route_filter_indexes\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*route_profiles\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*rpc_connections\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*rpc_responses\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"2s\"},\"*sentrypeer\":{\"limit\":-1,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":true,\"ttl\":\"24h0m0s\"},\"*shared_groups\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*stat_filter_indexes\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*statqueue_profiles\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*statqueues\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*stir\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"3h0m0s\"},\"*threshold_filter_indexes\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*threshold_profiles\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*thresholds\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*timings\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false},\"*tmp_rating_profiles\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"1m0s\"},\"*uch\":{\"limit\":0,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"3h0m0s\"}},\"remote_conns\":[],\"replication_conns\":[]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.CACHE_JSN, }, &rpl); err != nil { @@ -392,7 +393,7 @@ func testSectConfigSReloadCaches(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.CacheSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.CacheSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -402,7 +403,7 @@ func testSectConfigSReloadCaches(t *testing.T) { func testSectConfigSReloadFilters(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"filters\":{\"apiers_conns\":[\"*internal\"],\"resources_conns\":[\"*internal\"],\"stats_conns\":[\"*localhost\"]}}", }, &reply); err != nil { @@ -412,7 +413,7 @@ func testSectConfigSReloadFilters(t *testing.T) { } cfgStr := "{\"filters\":{\"apiers_conns\":[\"*internal\"],\"resources_conns\":[\"*internal\"],\"stats_conns\":[\"*localhost\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.FilterSjsn, }, &rpl); err != nil { @@ -425,7 +426,7 @@ func testSectConfigSReloadFilters(t *testing.T) { func testSectConfigSReloadRALS(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"rals\":{\"balance_rating_subject\":{\"*any\":\"*zero1ns\",\"*voice\":\"*zero1s\"},\"enabled\":true,\"max_computed_usage\":{\"*any\":\"189h0m0s\",\"*data\":\"107374182400\",\"*mms\":\"10000\",\"*sms\":\"10000\",\"*voice\":\"72h0m0s\"},\"max_increments\":3000000,\"remove_expired\":true,\"rp_subject_prefix_matching\":false,\"stats_conns\":[],\"thresholds_conns\":[\"*internal\"]}}", }, &reply); err != nil { @@ -435,7 +436,7 @@ func testSectConfigSReloadRALS(t *testing.T) { } cfgStr := "{\"rals\":{\"balance_rating_subject\":{\"*any\":\"*zero1ns\",\"*voice\":\"*zero1s\"},\"enabled\":true,\"max_computed_usage\":{\"*any\":\"189h0m0s\",\"*data\":\"107374182400\",\"*mms\":\"10000\",\"*sms\":\"10000\",\"*voice\":\"72h0m0s\"},\"max_increments\":3000000,\"remove_expired\":true,\"rp_subject_prefix_matching\":false,\"stats_conns\":[],\"thresholds_conns\":[\"*internal\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.RALS_JSN, }, &rpl); err != nil { @@ -445,7 +446,7 @@ func testSectConfigSReloadRALS(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.RALsV1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.RALsV1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -455,14 +456,14 @@ func testSectConfigSReloadRALS(t *testing.T) { func testSectConfigSReloadCDRS(t *testing.T) { var replyPingBf string - if err := testSectRPC.Call(utils.CDRsV1Ping, &utils.CGREvent{}, &replyPingBf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.CDRsV1Ping, &utils.CGREvent{}, &replyPingBf); err != nil { t.Error(err) } else if replyPingBf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingBf) } var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"cdrs\":{\"attributes_conns\":[],\"chargers_conns\":[\"*internal\"],\"ees_conns\":[],\"enabled\":true,\"extra_fields\":[],\"online_cdr_exports\":[],\"rals_conns\":[\"*internal\"],\"scheduler_conns\":[],\"session_cost_retries\":5,\"stats_conns\":[],\"store_cdrs\":true,\"thresholds_conns\":[]}}", }, &reply); err != nil { @@ -472,7 +473,7 @@ func testSectConfigSReloadCDRS(t *testing.T) { } cfgStr := "{\"cdrs\":{\"attributes_conns\":[],\"chargers_conns\":[\"*internal\"],\"ees_conns\":[],\"enabled\":true,\"extra_fields\":[],\"online_cdr_exports\":[],\"rals_conns\":[\"*internal\"],\"scheduler_conns\":[],\"session_cost_retries\":5,\"stats_conns\":[],\"store_cdrs\":true,\"thresholds_conns\":[]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.CDRS_JSN, }, &rpl); err != nil { @@ -482,7 +483,7 @@ func testSectConfigSReloadCDRS(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.CDRsV1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.CDRsV1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -492,7 +493,7 @@ func testSectConfigSReloadCDRS(t *testing.T) { func testSectConfigSReloadERS(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"ers\":{\"enabled\":true,\"partial_cache_ttl\":\"1s\",\"readers\":[{\"cache_dump_fields\":[],\"concurrent_requests\":1024,\"fields\":[{\"mandatory\":true,\"path\":\"*cgreq.ToR\",\"tag\":\"ToR\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"mandatory\":true,\"path\":\"*cgreq.OriginID\",\"tag\":\"OriginID\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"mandatory\":true,\"path\":\"*cgreq.RequestType\",\"tag\":\"RequestType\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"mandatory\":true,\"path\":\"*cgreq.Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.6\"},{\"mandatory\":true,\"path\":\"*cgreq.Category\",\"tag\":\"Category\",\"type\":\"*variable\",\"value\":\"~*req.7\"},{\"mandatory\":true,\"path\":\"*cgreq.Account\",\"tag\":\"Account\",\"type\":\"*variable\",\"value\":\"~*req.8\"},{\"mandatory\":true,\"path\":\"*cgreq.Subject\",\"tag\":\"Subject\",\"type\":\"*variable\",\"value\":\"~*req.9\"},{\"mandatory\":true,\"path\":\"*cgreq.Destination\",\"tag\":\"Destination\",\"type\":\"*variable\",\"value\":\"~*req.10\"},{\"mandatory\":true,\"path\":\"*cgreq.SetupTime\",\"tag\":\"SetupTime\",\"type\":\"*variable\",\"value\":\"~*req.11\"},{\"mandatory\":true,\"path\":\"*cgreq.AnswerTime\",\"tag\":\"AnswerTime\",\"type\":\"*variable\",\"value\":\"~*req.12\"},{\"mandatory\":true,\"path\":\"*cgreq.Usage\",\"tag\":\"Usage\",\"type\":\"*variable\",\"value\":\"~*req.13\"}],\"filters\":[],\"flags\":[],\"id\":\"*default\",\"opts\":{\"csvFieldSeparator\":\",\",\"csvHeaderDefineChar\":\":\",\"csvRowLength\":0,\"natsSubject\":\"cgrates_cdrs\",\"partialCacheAction\":\"*none\",\"partialOrderField\":\"~*req.AnswerTime\",\"xmlRootPath\":\"\"},\"partial_commit_fields\":[],\"processed_path\":\"/var/spool/cgrates/ers/out\",\"run_delay\":\"0\",\"source_path\":\"/var/spool/cgrates/ers/in\",\"tenant\":\"\",\"timezone\":\"\",\"type\":\"*none\"}],\"sessions_conns\":[\"*internal\"]}}", }, &reply); err != nil { @@ -502,7 +503,7 @@ func testSectConfigSReloadERS(t *testing.T) { } cfgStr := "{\"ers\":{\"enabled\":true,\"partial_cache_ttl\":\"1s\",\"readers\":[{\"cache_dump_fields\":[],\"concurrent_requests\":1024,\"fields\":[{\"mandatory\":true,\"path\":\"*cgreq.ToR\",\"tag\":\"ToR\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"mandatory\":true,\"path\":\"*cgreq.OriginID\",\"tag\":\"OriginID\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"mandatory\":true,\"path\":\"*cgreq.RequestType\",\"tag\":\"RequestType\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"mandatory\":true,\"path\":\"*cgreq.Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.6\"},{\"mandatory\":true,\"path\":\"*cgreq.Category\",\"tag\":\"Category\",\"type\":\"*variable\",\"value\":\"~*req.7\"},{\"mandatory\":true,\"path\":\"*cgreq.Account\",\"tag\":\"Account\",\"type\":\"*variable\",\"value\":\"~*req.8\"},{\"mandatory\":true,\"path\":\"*cgreq.Subject\",\"tag\":\"Subject\",\"type\":\"*variable\",\"value\":\"~*req.9\"},{\"mandatory\":true,\"path\":\"*cgreq.Destination\",\"tag\":\"Destination\",\"type\":\"*variable\",\"value\":\"~*req.10\"},{\"mandatory\":true,\"path\":\"*cgreq.SetupTime\",\"tag\":\"SetupTime\",\"type\":\"*variable\",\"value\":\"~*req.11\"},{\"mandatory\":true,\"path\":\"*cgreq.AnswerTime\",\"tag\":\"AnswerTime\",\"type\":\"*variable\",\"value\":\"~*req.12\"},{\"mandatory\":true,\"path\":\"*cgreq.Usage\",\"tag\":\"Usage\",\"type\":\"*variable\",\"value\":\"~*req.13\"}],\"filters\":[],\"flags\":[],\"id\":\"*default\",\"opts\":{\"csvFieldSeparator\":\",\",\"csvHeaderDefineChar\":\":\",\"csvRowLength\":0,\"natsSubject\":\"cgrates_cdrs\",\"partialCacheAction\":\"*none\",\"partialOrderField\":\"~*req.AnswerTime\",\"xmlRootPath\":\"\"},\"partial_commit_fields\":[],\"processed_path\":\"/var/spool/cgrates/ers/out\",\"run_delay\":\"0\",\"source_path\":\"/var/spool/cgrates/ers/in\",\"tenant\":\"\",\"timezone\":\"\",\"type\":\"*none\"}],\"sessions_conns\":[\"*internal\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: "ers", }, &rpl); err != nil { @@ -515,7 +516,7 @@ func testSectConfigSReloadERS(t *testing.T) { func testSectConfigSReloadEES(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"ees\":{\"attributes_conns\":[],\"cache\":{\"*file_csv\":{\"limit\":-1,\"precache\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"5s\"}},\"enabled\":true,\"exporters\":[{\"attempts\":1,\"attribute_context\":\"\",\"attribute_ids\":[],\"concurrent_requests\":0,\"export_path\":\"/var/spool/cgrates/ees\",\"fields\":[],\"filters\":[],\"flags\":[],\"id\":\"*default\",\"opts\":{},\"synchronous\":false,\"timezone\":\"\",\"type\":\"*none\"}]}}", }, &reply); err != nil { @@ -525,7 +526,7 @@ func testSectConfigSReloadEES(t *testing.T) { } cfgStr := "{\"ees\":{\"attributes_conns\":[],\"cache\":{\"*file_csv\":{\"limit\":-1,\"precache\":false,\"remote\":false,\"replicate\":false,\"static_ttl\":false,\"ttl\":\"5s\"}},\"enabled\":true,\"exporters\":[{\"attempts\":1,\"attribute_context\":\"\",\"attribute_ids\":[],\"concurrent_requests\":0,\"export_path\":\"/var/spool/cgrates/ees\",\"failed_posts_dir\":\"/var/spool/cgrates/failed_posts\",\"fields\":[],\"filters\":[],\"flags\":[],\"id\":\"*default\",\"opts\":{},\"synchronous\":false,\"timezone\":\"\",\"type\":\"*none\"}]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: "ees", }, &rpl); err != nil { @@ -538,7 +539,7 @@ func testSectConfigSReloadEES(t *testing.T) { func testSectConfigSReloadSessions(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"sessions\":{\"alterable_fields\":[],\"attributes_conns\":[\"*internal\"],\"cdrs_conns\":[\"*internal\"],\"channel_sync_interval\":\"0\",\"chargers_conns\":[\"*internal\"],\"client_protocol\":1,\"debit_interval\":\"0\",\"default_usage\":{\"*any\":\"3h0m0s\",\"*data\":\"1048576\",\"*sms\":\"1\",\"*voice\":\"3h0m0s\"},\"enabled\":true,\"listen_bigob\":\"\",\"listen_bijson\":\"127.0.0.1:2014\",\"min_dur_low_balance\":\"0\",\"rals_conns\":[\"*internal\"],\"replication_conns\":[],\"resources_conns\":[\"*internal\"],\"routes_conns\":[\"*internal\"],\"scheduler_conns\":[],\"session_indexes\":[\"OriginID\"],\"session_ttl\":\"0\",\"stats_conns\":[],\"stir\":{\"allowed_attest\":[\"*any\"],\"default_attest\":\"A\",\"payload_maxduration\":\"-1\",\"privatekey_path\":\"\",\"publickey_path\":\"\"},\"store_session_costs\":false,\"terminate_attempts\":5,\"thresholds_conns\":[]}}", }, &reply); err != nil { @@ -548,7 +549,7 @@ func testSectConfigSReloadSessions(t *testing.T) { } cfgStr := "{\"sessions\":{\"alterable_fields\":[],\"attributes_conns\":[\"*internal\"],\"cdrs_conns\":[\"*internal\"],\"channel_sync_interval\":\"0\",\"chargers_conns\":[\"*internal\"],\"client_protocol\":1,\"debit_interval\":\"0\",\"default_usage\":{\"*any\":\"3h0m0s\",\"*data\":\"1048576\",\"*sms\":\"1\",\"*voice\":\"3h0m0s\"},\"enabled\":true,\"listen_bigob\":\"\",\"listen_bijson\":\"127.0.0.1:2014\",\"min_dur_low_balance\":\"0\",\"rals_conns\":[\"*internal\"],\"replication_conns\":[],\"resources_conns\":[\"*internal\"],\"routes_conns\":[\"*internal\"],\"scheduler_conns\":[],\"session_indexes\":[\"OriginID\"],\"session_ttl\":\"0\",\"stats_conns\":[],\"stir\":{\"allowed_attest\":[\"*any\"],\"default_attest\":\"A\",\"payload_maxduration\":\"-1\",\"privatekey_path\":\"\",\"publickey_path\":\"\"},\"store_session_costs\":false,\"terminate_attempts\":5,\"thresholds_conns\":[]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.SessionSJson, }, &rpl); err != nil { @@ -558,7 +559,7 @@ func testSectConfigSReloadSessions(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.SessionSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.SessionSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -568,7 +569,7 @@ func testSectConfigSReloadSessions(t *testing.T) { func testSectConfigSReloadAsteriskAgent(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"asterisk_agent": { "enabled": true, @@ -586,7 +587,7 @@ func testSectConfigSReloadAsteriskAgent(t *testing.T) { } cfgStr := "{\"asterisk_agent\":{\"asterisk_conns\":[{\"address\":\"127.0.0.1:8088\",\"alias\":\"\",\"connect_attempts\":3,\"max_reconnect_interval\":\"0s\",\"password\":\"CGRateS.org\",\"reconnects\":5,\"user\":\"cgrates\"}],\"create_cdr\":true,\"enabled\":true,\"sessions_conns\":[\"*birpc_internal\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.AsteriskAgentJSN, }, &rpl); err != nil { @@ -599,7 +600,7 @@ func testSectConfigSReloadAsteriskAgent(t *testing.T) { func testSectConfigSReloadFreeswitchAgent(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"freeswitch_agent": { "enabled": true, @@ -623,7 +624,7 @@ func testSectConfigSReloadFreeswitchAgent(t *testing.T) { } cfgStr := "{\"freeswitch_agent\":{\"create_cdr\":true,\"empty_balance_ann_file\":\"empty_balance_ann_file\",\"empty_balance_context\":\"empty_balance_context\",\"enabled\":true,\"event_socket_conns\":[{\"address\":\"127.0.0.1:8021\",\"alias\":\"alias\",\"password\":\"ClueCon\",\"reconnects\":5}],\"extra_fields\":\"extra_fields\",\"low_balance_ann_file\":\"low_balance_ann_file\",\"max_wait_connection\":\"2s\",\"sessions_conns\":[\"*birpc_internal\"],\"subscribe_park\":true}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.FreeSWITCHAgentJSN, }, &rpl); err != nil { @@ -633,7 +634,7 @@ func testSectConfigSReloadFreeswitchAgent(t *testing.T) { } var reply2 string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"freeswitch_agent": { "enabled": false, @@ -660,7 +661,7 @@ func testSectConfigSReloadFreeswitchAgent(t *testing.T) { func testSectConfigSReloadKamailioAgent(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"kamailio_agent": { "enabled": true, @@ -679,7 +680,7 @@ func testSectConfigSReloadKamailioAgent(t *testing.T) { } cfgStr := "{\"kamailio_agent\":{\"create_cdr\":true,\"enabled\":true,\"evapi_conns\":[{\"address\":\"127.0.0.1:8448\",\"alias\":\"\",\"reconnects\":5}],\"sessions_conns\":[\"*birpc_internal\"],\"timezone\":\"local\"}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.KamailioAgentJSN, }, &rpl); err != nil { @@ -688,7 +689,7 @@ func testSectConfigSReloadKamailioAgent(t *testing.T) { t.Errorf("\nExpected %+v ,\n received: %+v", utils.ToIJSON(cfgStr), utils.ToIJSON(rpl)) } var reply2 string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"kamailio_agent": { "enabled": false, @@ -710,7 +711,7 @@ func testSectConfigSReloadKamailioAgent(t *testing.T) { func testSectConfigSReloadDiameterAgent(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"diameter_agent": { "enabled": true, @@ -750,7 +751,7 @@ func testSectConfigSReloadDiameterAgent(t *testing.T) { } cfgStr := "{\"diameter_agent\":{\"asr_template\":\"asr_template\",\"concurrent_requests\":-1,\"dictionaries_path\":\"/usr/share/cgrates/diameter/dict/\",\"enabled\":true,\"forced_disconnect\":\"*none\",\"listen\":\"127.0.0.1:3868\",\"listen_net\":\"tcp\",\"origin_host\":\"CGR-DA\",\"origin_realm\":\"cgrates.org\",\"product_name\":\"CGRateS\",\"rar_template\":\"rar_template\",\"request_processors\":[{\"filters\":[],\"flags\":[\"1\"],\"id\":\"cgrates\",\"reply_fields\":[{\"path\":\"randomPath\",\"tag\":\"randomPath\"}],\"request_fields\":[{\"path\":\"randomPath\",\"tag\":\"randomPath\"}],\"tenant\":\"1\",\"timezone\":\"\"}],\"sessions_conns\":[\"*birpc_internal\"],\"synced_conn_requests\":false,\"vendor_id\":1}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: "diameter_agent", }, &rpl); err != nil { @@ -763,7 +764,7 @@ func testSectConfigSReloadDiameterAgent(t *testing.T) { func testSectConfigSReloadRadiusAgent(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"radius_agent": { "enabled": true, @@ -800,7 +801,7 @@ func testSectConfigSReloadRadiusAgent(t *testing.T) { } cfgStr := "{\"radius_agent\":{\"client_dictionaries\":{\"*default\":\"/usr/share/cgrates/radius/dict/\"},\"client_secrets\":{\"*default\":\"CGRateS.org\"},\"enabled\":true,\"listen_acct\":\"127.0.0.1:1813\",\"listen_auth\":\"127.0.0.1:1812\",\"listen_net\":\"udp\",\"request_processors\":[{\"filters\":[],\"flags\":[\"1\"],\"id\":\"cgrates\",\"reply_fields\":[{\"path\":\"randomPath\",\"tag\":\"randomPath\"}],\"request_fields\":[{\"path\":\"randomPath\",\"tag\":\"randomPath\"}],\"tenant\":\"1\",\"timezone\":\"\"}],\"sessions_conns\":[\"*internal\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: "radius_agent", }, &rpl); err != nil { @@ -813,7 +814,7 @@ func testSectConfigSReloadRadiusAgent(t *testing.T) { func testSectConfigSReloadHTTPAgent(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"http_agent": [ { @@ -833,7 +834,7 @@ func testSectConfigSReloadHTTPAgent(t *testing.T) { } cfgStr := "{\"http_agent\":[{\"id\":\"conecto1\",\"reply_payload\":\"*xml\",\"request_payload\":\"*url\",\"request_processors\":[],\"sessions_conns\":[\"*internal\"],\"url\":\"/conecto\"}]}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.HttpAgentJson, }, &rpl); err != nil { @@ -846,7 +847,7 @@ func testSectConfigSReloadHTTPAgent(t *testing.T) { func testSectConfigSReloadDNSAgent(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"dns_agent": { "enabled": true, @@ -868,7 +869,7 @@ func testSectConfigSReloadDNSAgent(t *testing.T) { } cfgStr := "{\"dns_agent\":{\"enabled\":true,\"listeners\":[{\"address\":\"127.0.0.1:53\",\"network\":\"udp\"}],\"request_processors\":[{\"filters\":null,\"flags\":null,\"id\":\"random\",\"timezone\":\"\"}],\"sessions_conns\":[\"*internal\"],\"timezone\":\"local\"}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.DNSAgentJson, }, &rpl); err != nil { @@ -881,7 +882,7 @@ func testSectConfigSReloadDNSAgent(t *testing.T) { func testSectConfigSReloadAttributes(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"attributes": { "enabled": true, @@ -904,7 +905,7 @@ func testSectConfigSReloadAttributes(t *testing.T) { cfgStr := "{\"attributes\":{\"any_context\":true,\"apiers_conns\":[\"*internal\"],\"enabled\":true,\"indexed_selects\":true,\"nested_fields\":true,\"opts\":{\"*processRuns\":1,\"*profileIDs\":[],\"*profileIgnoreFilters\":false,\"*profileRuns\":0},\"prefix_indexed_fields\":[\"prefix_indexed_fields\"],\"resources_conns\":[\"*internal\"],\"stats_conns\":[\"*internal\"],\"string_indexed_fields\":[\"string_indexed_fields\"],\"suffix_indexed_fields\":[\"suffix_indexed_fields\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.ATTRIBUTE_JSN, }, &rpl); err != nil { @@ -914,7 +915,7 @@ func testSectConfigSReloadAttributes(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.AttributeSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.AttributeSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -925,7 +926,7 @@ func testSectConfigSReloadAttributes(t *testing.T) { func testSectConfigSReloadChargers(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"chargers": { "enabled": true, @@ -943,7 +944,7 @@ func testSectConfigSReloadChargers(t *testing.T) { } cfgStr := "{\"chargers\":{\"attributes_conns\":[\"*internal\"],\"enabled\":true,\"indexed_selects\":true,\"nested_fields\":true,\"prefix_indexed_fields\":[\"prefix_indexed_fields\"],\"string_indexed_fields\":[\"string_indexed_fields\"],\"suffix_indexed_fields\":[\"suffix_indexed_fields\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.ChargerSCfgJson, }, &rpl); err != nil { @@ -953,7 +954,7 @@ func testSectConfigSReloadChargers(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.ChargerSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.ChargerSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -963,7 +964,7 @@ func testSectConfigSReloadChargers(t *testing.T) { func testSectConfigSReloadResources(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"resources": { "enabled": true, @@ -982,7 +983,7 @@ func testSectConfigSReloadResources(t *testing.T) { } cfgStr := "{\"resources\":{\"enabled\":true,\"indexed_selects\":true,\"nested_fields\":true,\"opts\":{\"*units\":1,\"*usageID\":\"\"},\"prefix_indexed_fields\":[\"prefix_indexed_fields\"],\"store_interval\":\"-1ns\",\"string_indexed_fields\":[\"string_indexed_fields\"],\"suffix_indexed_fields\":[\"suffix_indexed_fields\"],\"thresholds_conns\":[\"*internal\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.RESOURCES_JSON, }, &rpl); err != nil { @@ -992,7 +993,7 @@ func testSectConfigSReloadResources(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.ResourceSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.ResourceSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -1002,7 +1003,7 @@ func testSectConfigSReloadResources(t *testing.T) { func testSectConfigSReloadStats(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"stats": { "enabled": true, @@ -1023,7 +1024,7 @@ func testSectConfigSReloadStats(t *testing.T) { } cfgStr := "{\"stats\":{\"enabled\":true,\"indexed_selects\":true,\"nested_fields\":true,\"opts\":{\"*profileIDs\":[],\"*profileIgnoreFilters\":false},\"prefix_indexed_fields\":[\"prefix_indexed_fields\"],\"store_interval\":\"-1ns\",\"store_uncompressed_limit\":1,\"string_indexed_fields\":[\"string_indexed_fields\"],\"suffix_indexed_fields\":[\"suffix_indexed_fields\"],\"thresholds_conns\":[\"*internal\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.STATS_JSON, }, &rpl); err != nil { @@ -1032,7 +1033,7 @@ func testSectConfigSReloadStats(t *testing.T) { t.Errorf("\nExpected %+v ,\n received: %+v", utils.ToIJSON(cfgStr), utils.ToIJSON(rpl)) } var replyPingAf string - if err := testSectRPC.Call(utils.StatSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.StatSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -1043,7 +1044,7 @@ func testSectConfigSReloadStats(t *testing.T) { func testSectConfigSReloadThresholds(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"thresholds\":{\"enabled\":true,\"indexed_selects\":true,\"nested_fields\":true,\"prefix_indexed_fields\":[\"prefix_indexed_fields\"],\"store_interval\":\"-1\",\"string_indexed_fields\":[\"string_indexed_fields\"],\"suffix_indexed_fields\":[\"suffix_indexed_fields\"]}}", }, &reply); err != nil { @@ -1053,7 +1054,7 @@ func testSectConfigSReloadThresholds(t *testing.T) { } cfgStr := "{\"thresholds\":{\"enabled\":true,\"indexed_selects\":true,\"nested_fields\":true,\"opts\":{\"*profileIDs\":[],\"*profileIgnoreFilters\":false},\"prefix_indexed_fields\":[\"prefix_indexed_fields\"],\"store_interval\":\"-1ns\",\"string_indexed_fields\":[\"string_indexed_fields\"],\"suffix_indexed_fields\":[\"suffix_indexed_fields\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.THRESHOLDS_JSON, }, &rpl); err != nil { @@ -1063,7 +1064,7 @@ func testSectConfigSReloadThresholds(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.ThresholdSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.ThresholdSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -1073,7 +1074,7 @@ func testSectConfigSReloadThresholds(t *testing.T) { func testSectConfigSReloadRoutes(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"routes": { "enabled": true, @@ -1096,7 +1097,7 @@ func testSectConfigSReloadRoutes(t *testing.T) { } cfgStr := "{\"routes\":{\"attributes_conns\":[\"*localhost\"],\"default_ratio\":1,\"enabled\":true,\"indexed_selects\":true,\"nested_fields\":true,\"opts\":{\"*context\":\"*routes\",\"*ignoreErrors\":false,\"*maxCost\":\"\"},\"prefix_indexed_fields\":[\"prefix_indexed_fields\"],\"rals_conns\":[\"*localhost\"],\"resources_conns\":[\"*localhost\"],\"stats_conns\":[\"*localhost\"],\"string_indexed_fields\":[\"string_indexed_fields\"],\"suffix_indexed_fields\":[\"suffix_indexed_fields\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.RouteSJson, }, &rpl); err != nil { @@ -1106,7 +1107,7 @@ func testSectConfigSReloadRoutes(t *testing.T) { } var replyPingAf string - if err := testSectRPC.Call(utils.RouteSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testSectRPC.Call(context.Background(), utils.RouteSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { t.Error(err) } else if replyPingAf != utils.Pong { t.Errorf("Expected OK received: %s", replyPingAf) @@ -1116,7 +1117,7 @@ func testSectConfigSReloadRoutes(t *testing.T) { func testSectConfigSReloadLoaders(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1ReloadConfig, &config.ReloadArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1ReloadConfig, &config.ReloadArgs{ Tenant: "cgrates.org", Path: path.Join(*dataDir, "conf", "samples", "tutinternal"), Section: config.LoaderJson, @@ -1127,7 +1128,7 @@ func testSectConfigSReloadLoaders(t *testing.T) { } cfgStr := "{\"loaders\":[{\"caches_conns\":[\"*internal\"],\"data\":[{\"fields\":[{\"mandatory\":true,\"path\":\"Tenant\",\"tag\":\"TenantID\",\"type\":\"*variable\",\"value\":\"~*req.0\"},{\"mandatory\":true,\"path\":\"ID\",\"tag\":\"ProfileID\",\"type\":\"*variable\",\"value\":\"~*req.1\"},{\"path\":\"Contexts\",\"tag\":\"Contexts\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"path\":\"FilterIDs\",\"tag\":\"FilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"path\":\"ActivationInterval\",\"tag\":\"ActivationInterval\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"path\":\"AttributeFilterIDs\",\"tag\":\"AttributeFilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.5\"},{\"path\":\"Path\",\"tag\":\"Path\",\"type\":\"*variable\",\"value\":\"~*req.6\"},{\"path\":\"Type\",\"tag\":\"Type\",\"type\":\"*variable\",\"value\":\"~*req.7\"},{\"path\":\"Value\",\"tag\":\"Value\",\"type\":\"*variable\",\"value\":\"~*req.8\"},{\"path\":\"Blocker\",\"tag\":\"Blocker\",\"type\":\"*variable\",\"value\":\"~*req.9\"},{\"path\":\"Weight\",\"tag\":\"Weight\",\"type\":\"*variable\",\"value\":\"~*req.10\"}],\"file_name\":\"Attributes.csv\",\"flags\":null,\"type\":\"*attributes\"},{\"fields\":[{\"mandatory\":true,\"path\":\"Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.0\"},{\"mandatory\":true,\"path\":\"ID\",\"tag\":\"ID\",\"type\":\"*variable\",\"value\":\"~*req.1\"},{\"path\":\"Type\",\"tag\":\"Type\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"path\":\"Element\",\"tag\":\"Element\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"path\":\"Values\",\"tag\":\"Values\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"path\":\"ActivationInterval\",\"tag\":\"ActivationInterval\",\"type\":\"*variable\",\"value\":\"~*req.5\"}],\"file_name\":\"Filters.csv\",\"flags\":null,\"type\":\"*filters\"},{\"fields\":[{\"mandatory\":true,\"path\":\"Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.0\"},{\"mandatory\":true,\"path\":\"ID\",\"tag\":\"ID\",\"type\":\"*variable\",\"value\":\"~*req.1\"},{\"path\":\"FilterIDs\",\"tag\":\"FilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"path\":\"ActivationInterval\",\"tag\":\"ActivationInterval\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"path\":\"UsageTTL\",\"tag\":\"TTL\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"path\":\"Limit\",\"tag\":\"Limit\",\"type\":\"*variable\",\"value\":\"~*req.5\"},{\"path\":\"AllocationMessage\",\"tag\":\"AllocationMessage\",\"type\":\"*variable\",\"value\":\"~*req.6\"},{\"path\":\"Blocker\",\"tag\":\"Blocker\",\"type\":\"*variable\",\"value\":\"~*req.7\"},{\"path\":\"Stored\",\"tag\":\"Stored\",\"type\":\"*variable\",\"value\":\"~*req.8\"},{\"path\":\"Weight\",\"tag\":\"Weight\",\"type\":\"*variable\",\"value\":\"~*req.9\"},{\"path\":\"ThresholdIDs\",\"tag\":\"ThresholdIDs\",\"type\":\"*variable\",\"value\":\"~*req.10\"}],\"file_name\":\"Resources.csv\",\"flags\":null,\"type\":\"*resources\"},{\"fields\":[{\"mandatory\":true,\"path\":\"Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.0\"},{\"mandatory\":true,\"path\":\"ID\",\"tag\":\"ID\",\"type\":\"*variable\",\"value\":\"~*req.1\"},{\"path\":\"FilterIDs\",\"tag\":\"FilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"path\":\"ActivationInterval\",\"tag\":\"ActivationInterval\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"path\":\"QueueLength\",\"tag\":\"QueueLength\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"path\":\"TTL\",\"tag\":\"TTL\",\"type\":\"*variable\",\"value\":\"~*req.5\"},{\"path\":\"MinItems\",\"tag\":\"MinItems\",\"type\":\"*variable\",\"value\":\"~*req.6\"},{\"path\":\"MetricIDs\",\"tag\":\"MetricIDs\",\"type\":\"*variable\",\"value\":\"~*req.7\"},{\"path\":\"MetricFilterIDs\",\"tag\":\"MetricFilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.8\"},{\"path\":\"Blocker\",\"tag\":\"Blocker\",\"type\":\"*variable\",\"value\":\"~*req.9\"},{\"path\":\"Stored\",\"tag\":\"Stored\",\"type\":\"*variable\",\"value\":\"~*req.10\"},{\"path\":\"Weight\",\"tag\":\"Weight\",\"type\":\"*variable\",\"value\":\"~*req.11\"},{\"path\":\"ThresholdIDs\",\"tag\":\"ThresholdIDs\",\"type\":\"*variable\",\"value\":\"~*req.12\"}],\"file_name\":\"Stats.csv\",\"flags\":null,\"type\":\"*stats\"},{\"fields\":[{\"mandatory\":true,\"path\":\"Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.0\"},{\"mandatory\":true,\"path\":\"ID\",\"tag\":\"ID\",\"type\":\"*variable\",\"value\":\"~*req.1\"},{\"path\":\"FilterIDs\",\"tag\":\"FilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"path\":\"ActivationInterval\",\"tag\":\"ActivationInterval\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"path\":\"MaxHits\",\"tag\":\"MaxHits\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"path\":\"MinHits\",\"tag\":\"MinHits\",\"type\":\"*variable\",\"value\":\"~*req.5\"},{\"path\":\"MinSleep\",\"tag\":\"MinSleep\",\"type\":\"*variable\",\"value\":\"~*req.6\"},{\"path\":\"Blocker\",\"tag\":\"Blocker\",\"type\":\"*variable\",\"value\":\"~*req.7\"},{\"path\":\"Weight\",\"tag\":\"Weight\",\"type\":\"*variable\",\"value\":\"~*req.8\"},{\"path\":\"ActionIDs\",\"tag\":\"ActionIDs\",\"type\":\"*variable\",\"value\":\"~*req.9\"},{\"path\":\"Async\",\"tag\":\"Async\",\"type\":\"*variable\",\"value\":\"~*req.10\"}],\"file_name\":\"Thresholds.csv\",\"flags\":null,\"type\":\"*thresholds\"},{\"fields\":[{\"mandatory\":true,\"path\":\"Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.0\"},{\"mandatory\":true,\"path\":\"ID\",\"tag\":\"ID\",\"type\":\"*variable\",\"value\":\"~*req.1\"},{\"path\":\"FilterIDs\",\"tag\":\"FilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"path\":\"ActivationInterval\",\"tag\":\"ActivationInterval\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"path\":\"Sorting\",\"tag\":\"Sorting\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"path\":\"SortingParameters\",\"tag\":\"SortingParameters\",\"type\":\"*variable\",\"value\":\"~*req.5\"},{\"path\":\"RouteID\",\"tag\":\"RouteID\",\"type\":\"*variable\",\"value\":\"~*req.6\"},{\"path\":\"RouteFilterIDs\",\"tag\":\"RouteFilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.7\"},{\"path\":\"RouteAccountIDs\",\"tag\":\"RouteAccountIDs\",\"type\":\"*variable\",\"value\":\"~*req.8\"},{\"path\":\"RouteRatingPlanIDs\",\"tag\":\"RouteRatingPlanIDs\",\"type\":\"*variable\",\"value\":\"~*req.9\"},{\"path\":\"RouteResourceIDs\",\"tag\":\"RouteResourceIDs\",\"type\":\"*variable\",\"value\":\"~*req.10\"},{\"path\":\"RouteStatIDs\",\"tag\":\"RouteStatIDs\",\"type\":\"*variable\",\"value\":\"~*req.11\"},{\"path\":\"RouteWeight\",\"tag\":\"RouteWeight\",\"type\":\"*variable\",\"value\":\"~*req.12\"},{\"path\":\"RouteBlocker\",\"tag\":\"RouteBlocker\",\"type\":\"*variable\",\"value\":\"~*req.13\"},{\"path\":\"RouteParameters\",\"tag\":\"RouteParameters\",\"type\":\"*variable\",\"value\":\"~*req.14\"},{\"path\":\"Weight\",\"tag\":\"Weight\",\"type\":\"*variable\",\"value\":\"~*req.15\"}],\"file_name\":\"Routes.csv\",\"flags\":null,\"type\":\"*routes\"},{\"fields\":[{\"mandatory\":true,\"path\":\"Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.0\"},{\"mandatory\":true,\"path\":\"ID\",\"tag\":\"ID\",\"type\":\"*variable\",\"value\":\"~*req.1\"},{\"path\":\"FilterIDs\",\"tag\":\"FilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"path\":\"ActivationInterval\",\"tag\":\"ActivationInterval\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"path\":\"RunID\",\"tag\":\"RunID\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"path\":\"AttributeIDs\",\"tag\":\"AttributeIDs\",\"type\":\"*variable\",\"value\":\"~*req.5\"},{\"path\":\"Weight\",\"tag\":\"Weight\",\"type\":\"*variable\",\"value\":\"~*req.6\"}],\"file_name\":\"Chargers.csv\",\"flags\":null,\"type\":\"*chargers\"},{\"fields\":[{\"mandatory\":true,\"path\":\"Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.0\"},{\"mandatory\":true,\"path\":\"ID\",\"tag\":\"ID\",\"type\":\"*variable\",\"value\":\"~*req.1\"},{\"path\":\"Contexts\",\"tag\":\"Contexts\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"path\":\"FilterIDs\",\"tag\":\"FilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"path\":\"ActivationInterval\",\"tag\":\"ActivationInterval\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"path\":\"Strategy\",\"tag\":\"Strategy\",\"type\":\"*variable\",\"value\":\"~*req.5\"},{\"path\":\"StrategyParameters\",\"tag\":\"StrategyParameters\",\"type\":\"*variable\",\"value\":\"~*req.6\"},{\"path\":\"ConnID\",\"tag\":\"ConnID\",\"type\":\"*variable\",\"value\":\"~*req.7\"},{\"path\":\"ConnFilterIDs\",\"tag\":\"ConnFilterIDs\",\"type\":\"*variable\",\"value\":\"~*req.8\"},{\"path\":\"ConnWeight\",\"tag\":\"ConnWeight\",\"type\":\"*variable\",\"value\":\"~*req.9\"},{\"path\":\"ConnBlocker\",\"tag\":\"ConnBlocker\",\"type\":\"*variable\",\"value\":\"~*req.10\"},{\"path\":\"ConnParameters\",\"tag\":\"ConnParameters\",\"type\":\"*variable\",\"value\":\"~*req.11\"},{\"path\":\"Weight\",\"tag\":\"Weight\",\"type\":\"*variable\",\"value\":\"~*req.12\"}],\"file_name\":\"DispatcherProfiles.csv\",\"flags\":null,\"type\":\"*dispatchers\"},{\"fields\":[{\"mandatory\":true,\"path\":\"Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.0\"},{\"mandatory\":true,\"path\":\"ID\",\"tag\":\"ID\",\"type\":\"*variable\",\"value\":\"~*req.1\"},{\"path\":\"Address\",\"tag\":\"Address\",\"type\":\"*variable\",\"value\":\"~*req.2\"},{\"path\":\"Transport\",\"tag\":\"Transport\",\"type\":\"*variable\",\"value\":\"~*req.3\"},{\"path\":\"ConnectAttempts\",\"tag\":\"ConnectAttempts\",\"type\":\"*variable\",\"value\":\"~*req.4\"},{\"path\":\"Reconnects\",\"tag\":\"Reconnects\",\"type\":\"*variable\",\"value\":\"~*req.5\"},{\"path\":\"MaxReconnectInterval\",\"tag\":\"MaxReconnectInterval\",\"type\":\"*variable\",\"value\":\"~*req.6\"},{\"path\":\"ConnectTimeout\",\"tag\":\"ConnectTimeout\",\"type\":\"*variable\",\"value\":\"~*req.7\"},{\"path\":\"ReplyTimeout\",\"tag\":\"ReplyTimeout\",\"type\":\"*variable\",\"value\":\"~*req.8\"},{\"path\":\"TLS\",\"tag\":\"TLS\",\"type\":\"*variable\",\"value\":\"~*req.9\"},{\"path\":\"ClientKey\",\"tag\":\"ClientKey\",\"type\":\"*variable\",\"value\":\"~*req.10\"},{\"path\":\"ClientCertificate\",\"tag\":\"ClientCertificate\",\"type\":\"*variable\",\"value\":\"~*req.11\"},{\"path\":\"CaCertificate\",\"tag\":\"CaCertificate\",\"type\":\"*variable\",\"value\":\"~*req.12\"}],\"file_name\":\"DispatcherHosts.csv\",\"flags\":null,\"type\":\"*dispatcher_hosts\"}],\"dry_run\":false,\"enabled\":false,\"field_separator\":\",\",\"id\":\"*default\",\"lockfile_path\":\".cgr.lck\",\"run_delay\":\"0\",\"tenant\":\"\",\"tp_in_dir\":\"/var/spool/cgrates/loader/in\",\"tp_out_dir\":\"/var/spool/cgrates/loader/out\"}]}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.LoaderJson, }, &rpl); err != nil { @@ -1140,7 +1141,7 @@ func testSectConfigSReloadLoaders(t *testing.T) { func testSectConfigSReloadMailer(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"mailer\":{\"auth_password\":\"CGRateS.com\",\"auth_user\":\"cgrates2\",\"from_address\":\"cgr-mailer@internal.localdomain\",\"server\":\"internal\"}}", }, &reply); err != nil { @@ -1150,7 +1151,7 @@ func testSectConfigSReloadMailer(t *testing.T) { } cfgStr := "{\"mailer\":{\"auth_password\":\"CGRateS.com\",\"auth_user\":\"cgrates2\",\"from_address\":\"cgr-mailer@internal.localdomain\",\"server\":\"internal\"}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.MAILER_JSN, }, &rpl); err != nil { @@ -1163,7 +1164,7 @@ func testSectConfigSReloadMailer(t *testing.T) { func testSectConfigSReloadSuretax(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"suretax": { "url": "google.ro", @@ -1201,7 +1202,7 @@ func testSectConfigSReloadSuretax(t *testing.T) { } cfgStr := "{\"suretax\":{\"bill_to_number\":\"3\",\"business_unit\":\"6\",\"client_number\":\"4\",\"client_tracking\":\"~*req.CGRID\",\"customer_number\":\"~*req.Subject\",\"include_local_cost\":true,\"orig_number\":\"~*req.Subject\",\"p2pplus4\":\"3\",\"p2pzipcode\":\"3\",\"plus4\":\"3\",\"regulatory_code\":\"04\",\"response_group\":\"04\",\"response_type\":\"D5\",\"return_file_code\":\"01\",\"sales_type_code\":\"RC\",\"tax_exemption_code_list\":\"3\",\"tax_included\":\"02\",\"tax_situs_rule\":\"05\",\"term_number\":\"~*req.Destination\",\"timezone\":\"UTC\",\"trans_type_code\":\"101010\",\"unit_type\":\"01\",\"units\":\"2\",\"url\":\"google.ro\",\"validation_key\":\"5\",\"zipcode\":\"3\"}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.SURETAX_JSON, }, &rpl); err != nil { @@ -1214,7 +1215,7 @@ func testSectConfigSReloadSuretax(t *testing.T) { func testSectConfigSReloadLoader(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"loader\":{\"caches_conns\":[\"*internal\"],\"data_path\":\".path\",\"disable_reverse\":true,\"field_separator\":\";\",\"gapi_credentials\":\".testCredentials\",\"gapi_token\":\".testToken\",\"scheduler_conns\":[\"*internal\"],\"tpid\":\"testID\"}}", }, &reply); err != nil { @@ -1224,7 +1225,7 @@ func testSectConfigSReloadLoader(t *testing.T) { } cfgStr := "{\"loader\":{\"caches_conns\":[\"*internal\"],\"data_path\":\".path\",\"disable_reverse\":true,\"field_separator\":\";\",\"gapi_credentials\":\".testCredentials\",\"gapi_token\":\".testToken\",\"scheduler_conns\":[\"*internal\"],\"tpid\":\"testID\"}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.CgrLoaderCfgJson, }, &rpl); err != nil { @@ -1237,7 +1238,7 @@ func testSectConfigSReloadLoader(t *testing.T) { func testSectConfigSReloadMigrator(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"migrator\":{\"out_datadb_encoding\":\"testDatadbEncoding\",\"out_datadb_host\":\"127.1.1.1\",\"out_datadb_name\":\"10\",\"out_datadb_opts\":{\"redisCACertificate\":\"testRedisCACertificate\",\"redisClientCertificate\":\"testRedisClientCertificate\",\"redisClientKey\":\"testRedisClientKey\",\"redisCluster\":true,\"redisClusterOndownDelay\":\"4\",\"redisClusterSync\":\"10s\",\"redisSentinel\":\"redisTest\",\"redisTLS\":true},\"out_datadb_password\":\"dataDBPass\",\"out_datadb_port\":\"5555\",\"out_datadb_type\":\"redisTest\",\"out_datadb_user\":\"cgratesTest\",\"out_stordb_host\":\"125.1.1.1\",\"out_stordb_name\":\"cgratesStorDBName\",\"out_stordb_opts\":{},\"out_stordb_password\":\"StorDBPass\",\"out_stordb_port\":\"3333\",\"out_stordb_type\":\"mongo\",\"out_stordb_user\":\"cgratesTest\",\"users_filters\":[\"Stats\"]}}", }, &reply); err != nil { @@ -1247,7 +1248,7 @@ func testSectConfigSReloadMigrator(t *testing.T) { } cfgStr := "{\"migrator\":{\"out_datadb_encoding\":\"testDatadbEncoding\",\"out_datadb_host\":\"127.1.1.1\",\"out_datadb_name\":\"10\",\"out_datadb_opts\":{\"mongoQueryTimeout\":\"0s\",\"redisCACertificate\":\"testRedisCACertificate\",\"redisClientCertificate\":\"testRedisClientCertificate\",\"redisClientKey\":\"testRedisClientKey\",\"redisCluster\":true,\"redisClusterOndownDelay\":\"4ns\",\"redisClusterSync\":\"10s\",\"redisConnectAttempts\":20,\"redisConnectTimeout\":\"0s\",\"redisMaxConns\":10,\"redisReadTimeout\":\"0s\",\"redisSentinel\":\"redisTest\",\"redisTLS\":true,\"redisWriteTimeout\":\"0s\"},\"out_datadb_password\":\"dataDBPass\",\"out_datadb_port\":\"5555\",\"out_datadb_type\":\"*redisTest\",\"out_datadb_user\":\"cgratesTest\",\"out_stordb_host\":\"125.1.1.1\",\"out_stordb_name\":\"cgratesStorDBName\",\"out_stordb_opts\":{\"mongoQueryTimeout\":\"0s\",\"mysqlDSNParams\":null,\"mysqlLocation\":\"\",\"pgSSLMode\":\"\",\"sqlConnMaxLifetime\":\"0s\",\"sqlMaxIdleConns\":0,\"sqlMaxOpenConns\":0},\"out_stordb_password\":\"StorDBPass\",\"out_stordb_port\":\"3333\",\"out_stordb_type\":\"*mongo\",\"out_stordb_user\":\"cgratesTest\",\"users_filters\":[\"Stats\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.CgrMigratorCfgJson, }, &rpl); err != nil { @@ -1260,12 +1261,12 @@ func testSectConfigSReloadMigrator(t *testing.T) { func testSectConfigSReloadDispatchers(t *testing.T) { var replyPingBf string - err := testSectRPC.Call(utils.DispatcherSv1Ping, &utils.CGREvent{}, &replyPingBf) + err := testSectRPC.Call(context.Background(), utils.DispatcherSv1Ping, &utils.CGREvent{}, &replyPingBf) if err == nil || err.Error() != "rpc: can't find service DispatcherSv1.Ping" { t.Error(err) } var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"dispatchers\":{\"any_subsystem\":true,\"attributes_conns\":[\"*internal\"],\"enabled\":true,\"indexed_selects\":true,\"nested_fields\":true,\"prefix_indexed_fields\":[\"*internal\"],\"string_indexed_fields\":[\"*internal\"],\"suffix_indexed_fields\":[\"*internal\"]}}", }, &reply); err != nil { @@ -1275,7 +1276,7 @@ func testSectConfigSReloadDispatchers(t *testing.T) { } cfgStr := "{\"dispatchers\":{\"any_subsystem\":true,\"attributes_conns\":[\"*internal\"],\"enabled\":true,\"indexed_selects\":true,\"nested_fields\":true,\"prefix_indexed_fields\":[\"*internal\"],\"prevent_loop\":false,\"string_indexed_fields\":[\"*internal\"],\"suffix_indexed_fields\":[\"*internal\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.DispatcherSJson, }, &rpl); err != nil { @@ -1288,7 +1289,7 @@ func testSectConfigSReloadDispatchers(t *testing.T) { func testSectConfigSReloadRegistrarC(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"registrarc\":{\"dispatchers\":{\"enabled\":true,\"hosts\":[{\"Tenant\":\"*default\"}],\"refresh_interval\":\"5m0s\",\"registrars_conns\":[]},\"rpc\":{\"enabled\":true,\"hosts\":[{\"Tenant\":\"*default\"}],\"refresh_interval\":\"5m0s\",\"registrars_conns\":[]}}}", }, &reply); err != nil { @@ -1298,7 +1299,7 @@ func testSectConfigSReloadRegistrarC(t *testing.T) { } cfgStr := "{\"registrarc\":{\"dispatchers\":{\"hosts\":[{\"Tenant\":\"*default\",\"transport\":\"\"}],\"refresh_interval\":\"5m0s\",\"registrars_conns\":[]},\"rpc\":{\"hosts\":[{\"Tenant\":\"*default\",\"transport\":\"\"}],\"refresh_interval\":\"5m0s\",\"registrars_conns\":[]}}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.RegistrarCJson, }, &rpl); err != nil { @@ -1311,7 +1312,7 @@ func testSectConfigSReloadRegistrarC(t *testing.T) { func testSectConfigSReloadAnalyzer(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"analyzers\":{\"cleanup_interval\":\"1h0m0s\",\"db_path\":\"/var/spool/cgrates/analyzers\",\"enabled\":true,\"index_type\":\"*scorch\",\"ttl\":\"24h0m0s\"}}", }, &reply); err != nil { @@ -1321,7 +1322,7 @@ func testSectConfigSReloadAnalyzer(t *testing.T) { } cfgStr := "{\"analyzers\":{\"cleanup_interval\":\"1h0m0s\",\"db_path\":\"/var/spool/cgrates/analyzers\",\"enabled\":true,\"index_type\":\"*scorch\",\"ttl\":\"24h0m0s\"}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.AnalyzerCfgJson, }, &rpl); err != nil { @@ -1334,7 +1335,7 @@ func testSectConfigSReloadAnalyzer(t *testing.T) { func testSectConfigSReloadApiers(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"apiers\":{\"attributes_conns\":[\"*internal\"],\"caches_conns\":[\"*internal\"],\"ees_conns\":[\"*internal\"],\"enabled\":true,\"scheduler_conns\":[\"*internal\"]}}", }, &reply); err != nil { @@ -1344,7 +1345,7 @@ func testSectConfigSReloadApiers(t *testing.T) { } cfgStr := "{\"apiers\":{\"attributes_conns\":[\"*internal\"],\"caches_conns\":[\"*internal\"],\"ees_conns\":[\"*internal\"],\"enabled\":true,\"scheduler_conns\":[\"*internal\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.ApierS, }, &rpl); err != nil { @@ -1357,7 +1358,7 @@ func testSectConfigSReloadApiers(t *testing.T) { func testSectConfigSReloadSIPAgent(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"sip_agent": { "enabled": true, @@ -1398,7 +1399,7 @@ func testSectConfigSReloadSIPAgent(t *testing.T) { } cfgStr := "{\"sip_agent\":{\"enabled\":true,\"listen\":\"127.0.0.1:5060\",\"listen_net\":\"udp\",\"request_processors\":[{\"filters\":[\"*string:~*req.request_type:OutboundAUTH\",\"*string:~*req.Msisdn:497700056231\"],\"flags\":[\"*dryrun\"],\"id\":\"OutboundAUTHDryRun\",\"reply_fields\":[{\"mandatory\":true,\"path\":\"*rep.response.Allow\",\"tag\":\"Allow\",\"type\":\"*constant\",\"value\":\"1\"},{\"mandatory\":true,\"path\":\"*rep.response.Concatenated\",\"tag\":\"Concatenated1\",\"type\":\"*composed\",\"value\":\"~*req.MCC;/\"},{\"path\":\"*rep.response.Concatenated\",\"tag\":\"Concatenated2\",\"type\":\"*composed\",\"value\":\"Val1\"},{\"blocker\":true,\"path\":\"*rep.response.MaxDuration\",\"tag\":\"MaxDuration\",\"type\":\"*constant\",\"value\":\"1200\"},{\"path\":\"*rep.response.Unused\",\"tag\":\"Unused\",\"type\":\"*constant\",\"value\":\"0\"}],\"request_fields\":[],\"tenant\":\"cgrates.org\",\"timezone\":\"\"}],\"retransmission_timer\":100000000000,\"sessions_conns\":[\"*internal\"],\"timezone\":\"local\"}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.SIPAgentJson, }, &rpl); err != nil { @@ -1411,7 +1412,7 @@ func testSectConfigSReloadSIPAgent(t *testing.T) { func testSectConfigSReloadTemplates(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: "{\"templates\":{\"*asr\":[{\"mandatory\":true,\"path\":\"*diamreq.Session-Id\",\"tag\":\"SessionId\",\"type\":\"*variable\",\"value\":\"~*req.Session-Id\"},{\"mandatory\":true,\"path\":\"*diamreq.Origin-Host\",\"tag\":\"OriginHost\",\"type\":\"*variable\",\"value\":\"~*req.Destination-Host\"},{\"mandatory\":true,\"path\":\"*diamreq.Origin-Realm\",\"tag\":\"OriginRealm\",\"type\":\"*variable\",\"value\":\"~*req.Destination-Realm\"},{\"mandatory\":true,\"path\":\"*diamreq.Destination-Realm\",\"tag\":\"DestinationRealm\",\"type\":\"*variable\",\"value\":\"~*req.Origin-Realm\"},{\"mandatory\":true,\"path\":\"*diamreq.Destination-Host\",\"tag\":\"DestinationHost\",\"type\":\"*variable\",\"value\":\"~*req.Origin-Host\"},{\"mandatory\":true,\"path\":\"*diamreq.Auth-Application-Id\",\"tag\":\"AuthApplicationId\",\"type\":\"*variable\",\"value\":\"~*vars.*appid\"}],\"*cca\":[{\"mandatory\":true,\"path\":\"*rep.Session-Id\",\"tag\":\"SessionId\",\"type\":\"*variable\",\"value\":\"~*req.Session-Id\"},{\"path\":\"*rep.Result-Code\",\"tag\":\"ResultCode\",\"type\":\"*constant\",\"value\":\"2001\"},{\"mandatory\":true,\"path\":\"*rep.Origin-Host\",\"tag\":\"OriginHost\",\"type\":\"*variable\",\"value\":\"~*vars.OriginHost\"},{\"mandatory\":true,\"path\":\"*rep.Origin-Realm\",\"tag\":\"OriginRealm\",\"type\":\"*variable\",\"value\":\"~*vars.OriginRealm\"},{\"mandatory\":true,\"path\":\"*rep.Auth-Application-Id\",\"tag\":\"AuthApplicationId\",\"type\":\"*variable\",\"value\":\"~*vars.*appid\"},{\"mandatory\":true,\"path\":\"*rep.CC-Request-Type\",\"tag\":\"CCRequestType\",\"type\":\"*variable\",\"value\":\"~*req.CC-Request-Type\"},{\"mandatory\":true,\"path\":\"*rep.CC-Request-Number\",\"tag\":\"CCRequestNumber\",\"type\":\"*variable\",\"value\":\"~*req.CC-Request-Number\"}],\"*cdrLog\":[{\"mandatory\":true,\"path\":\"*cdr.ToR\",\"tag\":\"ToR\",\"type\":\"*variable\",\"value\":\"~*req.BalanceType\"},{\"mandatory\":true,\"path\":\"*cdr.OriginHost\",\"tag\":\"OriginHost\",\"type\":\"*constant\",\"value\":\"127.0.0.1\"},{\"mandatory\":true,\"path\":\"*cdr.RequestType\",\"tag\":\"RequestType\",\"type\":\"*constant\",\"value\":\"*none\"},{\"mandatory\":true,\"path\":\"*cdr.Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.Tenant\"},{\"mandatory\":true,\"path\":\"*cdr.Account\",\"tag\":\"Account\",\"type\":\"*variable\",\"value\":\"~*req.Account\"},{\"mandatory\":true,\"path\":\"*cdr.Subject\",\"tag\":\"Subject\",\"type\":\"*variable\",\"value\":\"~*req.Account\"},{\"mandatory\":true,\"path\":\"*cdr.Cost\",\"tag\":\"Cost\",\"type\":\"*variable\",\"value\":\"~*req.Cost\"},{\"mandatory\":true,\"path\":\"*cdr.Source\",\"tag\":\"Source\",\"type\":\"*constant\",\"value\":\"*cdrLog\"},{\"mandatory\":true,\"path\":\"*cdr.Usage\",\"tag\":\"Usage\",\"type\":\"*constant\",\"value\":\"1\"},{\"mandatory\":true,\"path\":\"*cdr.RunID\",\"tag\":\"RunID\",\"type\":\"*variable\",\"value\":\"~*req.ActionType\"},{\"mandatory\":true,\"path\":\"*cdr.SetupTime\",\"tag\":\"SetupTime\",\"type\":\"*constant\",\"value\":\"*now\"},{\"mandatory\":true,\"path\":\"*cdr.AnswerTime\",\"tag\":\"AnswerTime\",\"type\":\"*constant\",\"value\":\"*now\"},{\"mandatory\":true,\"path\":\"*cdr.PreRated\",\"tag\":\"PreRated\",\"type\":\"*constant\",\"value\":\"true\"}],\"*err\":[{\"mandatory\":true,\"path\":\"*rep.Session-Id\",\"tag\":\"SessionId\",\"type\":\"*variable\",\"value\":\"~*req.Session-Id\"},{\"mandatory\":true,\"path\":\"*rep.Origin-Host\",\"tag\":\"OriginHost\",\"type\":\"*variable\",\"value\":\"~*vars.OriginHost\"},{\"mandatory\":true,\"path\":\"*rep.Origin-Realm\",\"tag\":\"OriginRealm\",\"type\":\"*variable\",\"value\":\"~*vars.OriginRealm\"}],\"*errSip\":[{\"mandatory\":true,\"path\":\"*rep.Request\",\"tag\":\"Request\",\"type\":\"*constant\",\"value\":\"SIP/2.0 500 Internal Server Error\"}],\"*rar\":[{\"mandatory\":true,\"path\":\"*diamreq.Session-Id\",\"tag\":\"SessionId\",\"type\":\"*variable\",\"value\":\"~*req.Session-Id\"},{\"mandatory\":true,\"path\":\"*diamreq.Origin-Host\",\"tag\":\"OriginHost\",\"type\":\"*variable\",\"value\":\"~*req.Destination-Host\"},{\"mandatory\":true,\"path\":\"*diamreq.Origin-Realm\",\"tag\":\"OriginRealm\",\"type\":\"*variable\",\"value\":\"~*req.Destination-Realm\"},{\"mandatory\":true,\"path\":\"*diamreq.Destination-Realm\",\"tag\":\"DestinationRealm\",\"type\":\"*variable\",\"value\":\"~*req.Origin-Realm\"},{\"mandatory\":true,\"path\":\"*diamreq.Destination-Host\",\"tag\":\"DestinationHost\",\"type\":\"*variable\",\"value\":\"~*req.Origin-Host\"},{\"mandatory\":true,\"path\":\"*diamreq.Auth-Application-Id\",\"tag\":\"AuthApplicationId\",\"type\":\"*variable\",\"value\":\"~*vars.*appid\"},{\"path\":\"*diamreq.Re-Auth-Request-Type\",\"tag\":\"ReAuthRequestType\",\"type\":\"*constant\",\"value\":\"0\"}]}}", }, &reply); err != nil { @@ -1421,7 +1422,7 @@ func testSectConfigSReloadTemplates(t *testing.T) { } cfgStr := "{\"templates\":{\"*asr\":[{\"mandatory\":true,\"path\":\"*diamreq.Session-Id\",\"tag\":\"SessionId\",\"type\":\"*variable\",\"value\":\"~*req.Session-Id\"},{\"mandatory\":true,\"path\":\"*diamreq.Origin-Host\",\"tag\":\"OriginHost\",\"type\":\"*variable\",\"value\":\"~*req.Destination-Host\"},{\"mandatory\":true,\"path\":\"*diamreq.Origin-Realm\",\"tag\":\"OriginRealm\",\"type\":\"*variable\",\"value\":\"~*req.Destination-Realm\"},{\"mandatory\":true,\"path\":\"*diamreq.Destination-Realm\",\"tag\":\"DestinationRealm\",\"type\":\"*variable\",\"value\":\"~*req.Origin-Realm\"},{\"mandatory\":true,\"path\":\"*diamreq.Destination-Host\",\"tag\":\"DestinationHost\",\"type\":\"*variable\",\"value\":\"~*req.Origin-Host\"},{\"mandatory\":true,\"path\":\"*diamreq.Auth-Application-Id\",\"tag\":\"AuthApplicationId\",\"type\":\"*variable\",\"value\":\"~*vars.*appid\"}],\"*cca\":[{\"mandatory\":true,\"path\":\"*rep.Session-Id\",\"tag\":\"SessionId\",\"type\":\"*variable\",\"value\":\"~*req.Session-Id\"},{\"path\":\"*rep.Result-Code\",\"tag\":\"ResultCode\",\"type\":\"*constant\",\"value\":\"2001\"},{\"mandatory\":true,\"path\":\"*rep.Origin-Host\",\"tag\":\"OriginHost\",\"type\":\"*variable\",\"value\":\"~*vars.OriginHost\"},{\"mandatory\":true,\"path\":\"*rep.Origin-Realm\",\"tag\":\"OriginRealm\",\"type\":\"*variable\",\"value\":\"~*vars.OriginRealm\"},{\"mandatory\":true,\"path\":\"*rep.Auth-Application-Id\",\"tag\":\"AuthApplicationId\",\"type\":\"*variable\",\"value\":\"~*vars.*appid\"},{\"mandatory\":true,\"path\":\"*rep.CC-Request-Type\",\"tag\":\"CCRequestType\",\"type\":\"*variable\",\"value\":\"~*req.CC-Request-Type\"},{\"mandatory\":true,\"path\":\"*rep.CC-Request-Number\",\"tag\":\"CCRequestNumber\",\"type\":\"*variable\",\"value\":\"~*req.CC-Request-Number\"}],\"*cdrLog\":[{\"mandatory\":true,\"path\":\"*cdr.ToR\",\"tag\":\"ToR\",\"type\":\"*variable\",\"value\":\"~*req.BalanceType\"},{\"mandatory\":true,\"path\":\"*cdr.OriginHost\",\"tag\":\"OriginHost\",\"type\":\"*constant\",\"value\":\"127.0.0.1\"},{\"mandatory\":true,\"path\":\"*cdr.RequestType\",\"tag\":\"RequestType\",\"type\":\"*constant\",\"value\":\"*none\"},{\"mandatory\":true,\"path\":\"*cdr.Tenant\",\"tag\":\"Tenant\",\"type\":\"*variable\",\"value\":\"~*req.Tenant\"},{\"mandatory\":true,\"path\":\"*cdr.Account\",\"tag\":\"Account\",\"type\":\"*variable\",\"value\":\"~*req.Account\"},{\"mandatory\":true,\"path\":\"*cdr.Subject\",\"tag\":\"Subject\",\"type\":\"*variable\",\"value\":\"~*req.Account\"},{\"mandatory\":true,\"path\":\"*cdr.Cost\",\"tag\":\"Cost\",\"type\":\"*variable\",\"value\":\"~*req.Cost\"},{\"mandatory\":true,\"path\":\"*cdr.Source\",\"tag\":\"Source\",\"type\":\"*constant\",\"value\":\"*cdrLog\"},{\"mandatory\":true,\"path\":\"*cdr.Usage\",\"tag\":\"Usage\",\"type\":\"*constant\",\"value\":\"1\"},{\"mandatory\":true,\"path\":\"*cdr.RunID\",\"tag\":\"RunID\",\"type\":\"*variable\",\"value\":\"~*req.ActionType\"},{\"mandatory\":true,\"path\":\"*cdr.SetupTime\",\"tag\":\"SetupTime\",\"type\":\"*constant\",\"value\":\"*now\"},{\"mandatory\":true,\"path\":\"*cdr.AnswerTime\",\"tag\":\"AnswerTime\",\"type\":\"*constant\",\"value\":\"*now\"},{\"mandatory\":true,\"path\":\"*cdr.PreRated\",\"tag\":\"PreRated\",\"type\":\"*constant\",\"value\":\"true\"}],\"*err\":[{\"mandatory\":true,\"path\":\"*rep.Session-Id\",\"tag\":\"SessionId\",\"type\":\"*variable\",\"value\":\"~*req.Session-Id\"},{\"mandatory\":true,\"path\":\"*rep.Origin-Host\",\"tag\":\"OriginHost\",\"type\":\"*variable\",\"value\":\"~*vars.OriginHost\"},{\"mandatory\":true,\"path\":\"*rep.Origin-Realm\",\"tag\":\"OriginRealm\",\"type\":\"*variable\",\"value\":\"~*vars.OriginRealm\"}],\"*errSip\":[{\"mandatory\":true,\"path\":\"*rep.Request\",\"tag\":\"Request\",\"type\":\"*constant\",\"value\":\"SIP/2.0 500 Internal Server Error\"}],\"*rar\":[{\"mandatory\":true,\"path\":\"*diamreq.Session-Id\",\"tag\":\"SessionId\",\"type\":\"*variable\",\"value\":\"~*req.Session-Id\"},{\"mandatory\":true,\"path\":\"*diamreq.Origin-Host\",\"tag\":\"OriginHost\",\"type\":\"*variable\",\"value\":\"~*req.Destination-Host\"},{\"mandatory\":true,\"path\":\"*diamreq.Origin-Realm\",\"tag\":\"OriginRealm\",\"type\":\"*variable\",\"value\":\"~*req.Destination-Realm\"},{\"mandatory\":true,\"path\":\"*diamreq.Destination-Realm\",\"tag\":\"DestinationRealm\",\"type\":\"*variable\",\"value\":\"~*req.Origin-Realm\"},{\"mandatory\":true,\"path\":\"*diamreq.Destination-Host\",\"tag\":\"DestinationHost\",\"type\":\"*variable\",\"value\":\"~*req.Origin-Host\"},{\"mandatory\":true,\"path\":\"*diamreq.Auth-Application-Id\",\"tag\":\"AuthApplicationId\",\"type\":\"*variable\",\"value\":\"~*vars.*appid\"},{\"path\":\"*diamreq.Re-Auth-Request-Type\",\"tag\":\"ReAuthRequestType\",\"type\":\"*constant\",\"value\":\"0\"}]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.TemplatesJson, }, &rpl); err != nil { @@ -1434,7 +1435,7 @@ func testSectConfigSReloadTemplates(t *testing.T) { func testSectConfigSReloadConfigs(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"configs":{"enabled":true,"root_dir":"root_dir","url":"/configs/"}}`, }, &reply); err != nil { @@ -1444,7 +1445,7 @@ func testSectConfigSReloadConfigs(t *testing.T) { } cfgStr := `{"configs":{"enabled":true,"root_dir":"root_dir","url":"/configs/"}}` var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.ConfigSJson, }, &rpl); err != nil { @@ -1458,7 +1459,7 @@ func testSectConfigSReloadConfigs(t *testing.T) { func testSectConfigSReloadAPIBan(t *testing.T) { var reply string - if err := testSectRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", Config: `{"apiban":{"enabled":true,"keys":["keys"]}}`, }, &reply); err != nil { @@ -1468,7 +1469,7 @@ func testSectConfigSReloadAPIBan(t *testing.T) { } cfgStr := "{\"apiban\":{\"keys\":[\"keys\"]}}" var rpl string - if err := testSectRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ + if err := testSectRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", Section: config.APIBanCfgJson, }, &rpl); err != nil { @@ -1480,7 +1481,7 @@ func testSectConfigSReloadAPIBan(t *testing.T) { } func testSectStopCgrEngine(t *testing.T) { - if err := engine.KillEngine(100); err != nil { + if err := engine.KillEngine(*waitRater); err != nil { t.Error(err) } } diff --git a/general_tests/attributes_filters_index_it_test.go b/general_tests/attributes_filters_index_it_test.go index 68baf5ef3..93be8af57 100644 --- a/general_tests/attributes_filters_index_it_test.go +++ b/general_tests/attributes_filters_index_it_test.go @@ -22,11 +22,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/engine" @@ -37,7 +38,7 @@ import ( var ( attrFltrCfgPath string attrFltrCfg *config.CGRConfig - attrFltrRPC *rpc.Client + attrFltrRPC *birpc.Client alsPrfFltrConfigDIR string sTestsAlsFltrPrf = []func(t *testing.T){ testAttributeFltrSInitCfg, @@ -123,14 +124,14 @@ func testAttributeSetFltr1(t *testing.T) { }, } var result string - if err := attrFltrRPC.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := attrFltrRPC.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var indexes []string - if err := attrFltrRPC.Call(utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ + if err := attrFltrRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: "cgrates.org", FilterType: utils.MetaPrefix, Context: utils.MetaSessionS}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { @@ -155,7 +156,7 @@ func testAttributeSetProfile(t *testing.T) { Weight: 20, }, } - if err := attrFltrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrFltrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -171,7 +172,7 @@ func testAttributeSetProfile(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrFltrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrFltrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err) } @@ -180,7 +181,7 @@ func testAttributeSetProfile(t *testing.T) { expIdx := []string{ "*prefix:*req.Subject:48:ApierTest", } - if err := attrFltrRPC.Call(utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ + if err := attrFltrRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: "cgrates.org", FilterType: utils.MetaPrefix, Context: utils.MetaSessionS}, &indexes); err != nil { @@ -204,7 +205,7 @@ func testAttributeSetFltr2(t *testing.T) { }}, }, } - if err := attrFltrRPC.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := attrFltrRPC.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -235,7 +236,7 @@ func testAttributeSetFltr2(t *testing.T) { }, } var rplyEv engine.AttrSProcessEventReply - if err := attrFltrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrFltrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(exp, rplyEv) { @@ -246,7 +247,7 @@ func testAttributeSetFltr2(t *testing.T) { expIdx := []string{ "*prefix:*req.Subject:44:ApierTest", } - if err := attrFltrRPC.Call(utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ + if err := attrFltrRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: "cgrates.org", FilterType: utils.MetaPrefix, Context: utils.MetaSessionS}, &indexes); err != nil { @@ -259,14 +260,14 @@ func testAttributeSetFltr2(t *testing.T) { func testAttributeRemoveFltr(t *testing.T) { var result string - if err := attrFltrRPC.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{ + if err := attrFltrRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := attrFltrRPC.Call(utils.APIerSv1RemoveFilter, &utils.TenantIDWithAPIOpts{ + if err := attrFltrRPC.Call(context.Background(), utils.APIerSv1RemoveFilter, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_1"}}, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -274,7 +275,7 @@ func testAttributeRemoveFltr(t *testing.T) { } var indexes []string - if err := attrFltrRPC.Call(utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ + if err := attrFltrRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: "cgrates.org", FilterType: utils.MetaPrefix, Context: utils.MetaSessionS}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() { diff --git a/general_tests/attributes_it_test.go b/general_tests/attributes_it_test.go index 96555abd7..9077f7cb7 100644 --- a/general_tests/attributes_it_test.go +++ b/general_tests/attributes_it_test.go @@ -21,7 +21,6 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "sort" @@ -29,6 +28,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( attrCfgPath string attrCfg *config.CGRConfig - attrRPC *rpc.Client + attrRPC *birpc.Client alsPrfConfigDIR string sTestsAlsPrf = []func(t *testing.T){ testAttributeSInitCfg, @@ -120,7 +121,7 @@ func testAttributeSRPCConn(t *testing.T) { func testAttributeSLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := attrRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(200 * time.Millisecond) @@ -156,7 +157,7 @@ func testAttributeSProcessEvent(t *testing.T) { } sort.Strings(eRply.AlteredFields) var rplyEv engine.AttrSProcessEventReply - if err := attrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } @@ -196,13 +197,13 @@ func testAttributeSProcessEventWithAccount(t *testing.T) { }, } alsPrf.Compile() - if err := attrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyAttr *engine.AttributeProfile - if err := attrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_ACCOUNT"}}, &replyAttr); err != nil { t.Fatal(err) } @@ -239,7 +240,7 @@ func testAttributeSProcessEventWithAccount(t *testing.T) { } sort.Strings(eRply.AlteredFields) var rplyEv engine.AttrSProcessEventReply - if err := attrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } @@ -279,13 +280,13 @@ func testAttributeSProcessEventWithAccountFull(t *testing.T) { }, } alsPrf.Compile() - if err := attrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyAttr *engine.AttributeProfile - if err := attrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_ACCOUNT2"}}, &replyAttr); err != nil { t.Fatal(err) } @@ -320,7 +321,7 @@ func testAttributeSProcessEventWithAccountFull(t *testing.T) { } sort.Strings(eRply.AlteredFields) var rplyEv engine.AttrSProcessEventReply - if err := attrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } @@ -356,7 +357,7 @@ func testAttributeSProcessEventWithStat(t *testing.T) { utils.Cost: 10.0, }, } - if err := attrRPC.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { + if err := attrRPC.Call(context.Background(), utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -373,7 +374,7 @@ func testAttributeSProcessEventWithStat(t *testing.T) { utils.Cost: 10.5, }, } - if err := attrRPC.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { + if err := attrRPC.Call(context.Background(), utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -407,13 +408,13 @@ func testAttributeSProcessEventWithStat(t *testing.T) { } alsPrf.Compile() var result string - if err := attrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyAttr *engine.AttributeProfile - if err := attrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_STATS"}}, &replyAttr); err != nil { t.Fatal(err) } @@ -450,7 +451,7 @@ func testAttributeSProcessEventWithStat(t *testing.T) { } sort.Strings(eRply.AlteredFields) var rplyEv engine.AttrSProcessEventReply - if err := attrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } @@ -490,13 +491,13 @@ func testAttributeSProcessEventWithStatFull(t *testing.T) { } alsPrf.Compile() var result string - if err := attrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyAttr *engine.AttributeProfile - if err := attrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_STATS2"}}, &replyAttr); err != nil { t.Fatal(err) } @@ -533,7 +534,7 @@ func testAttributeSProcessEventWithStatFull(t *testing.T) { } sort.Strings(eRply.AlteredFields) var rplyEv engine.AttrSProcessEventReply - if err := attrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } @@ -558,14 +559,14 @@ func testAttributeSProcessEventWithResource(t *testing.T) { } var result string - if err := attrRPC.Call(utils.APIerSv1SetResourceProfile, &engine.ResourceProfileWithAPIOpts{ResourceProfile: rlsConfig}, &result); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1SetResourceProfile, &engine.ResourceProfileWithAPIOpts{ResourceProfile: rlsConfig}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.ResourceProfile - if err := attrRPC.Call(utils.APIerSv1GetResourceProfile, + if err := attrRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, rlsConfig) { @@ -584,7 +585,7 @@ func testAttributeSProcessEventWithResource(t *testing.T) { utils.OptsResourcesUnits: 3, }, } - if err := attrRPC.Call(utils.ResourceSv1AllocateResources, + if err := attrRPC.Call(context.Background(), utils.ResourceSv1AllocateResources, argsRU, &result); err != nil { t.Error(err) } @@ -600,7 +601,7 @@ func testAttributeSProcessEventWithResource(t *testing.T) { utils.OptsResourcesUnits: 2, }, } - if err := attrRPC.Call(utils.ResourceSv1AllocateResources, + if err := attrRPC.Call(context.Background(), utils.ResourceSv1AllocateResources, argsRU2, &result); err != nil { t.Error(err) } @@ -632,13 +633,13 @@ func testAttributeSProcessEventWithResource(t *testing.T) { }, } alsPrf.Compile() - if err := attrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyAttr *engine.AttributeProfile - if err := attrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_RESOURCE"}}, &replyAttr); err != nil { t.Fatal(err) } @@ -675,7 +676,7 @@ func testAttributeSProcessEventWithResource(t *testing.T) { } sort.Strings(eRply.AlteredFields) var rplyEv engine.AttrSProcessEventReply - if err := attrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } @@ -715,13 +716,13 @@ func testAttributeSProcessEventWithResourceFull(t *testing.T) { }, } alsPrf.Compile() - if err := attrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyAttr *engine.AttributeProfile - if err := attrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_RESOURCE2"}}, &replyAttr); err != nil { t.Fatal(err) } @@ -755,7 +756,7 @@ func testAttributeSProcessEventWithResourceFull(t *testing.T) { } sort.Strings(eRply.AlteredFields) var rplyEv engine.AttrSProcessEventReply - if err := attrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } @@ -806,13 +807,13 @@ func testAttributeSProcessEventWithLibPhoneNumber(t *testing.T) { }, } alsPrf.Compile() - if err := attrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyAttr *engine.AttributeProfile - if err := attrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_LIBPHONENUMBER2"}}, &replyAttr); err != nil { t.Fatal(err) } @@ -851,7 +852,7 @@ func testAttributeSProcessEventWithLibPhoneNumber(t *testing.T) { } sort.Strings(eRply.AlteredFields) var rplyEv engine.AttrSProcessEventReply - if err := attrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } @@ -909,13 +910,13 @@ func testAttributeSProcessEventWithLibPhoneNumberComposed(t *testing.T) { }, } alsPrf.Compile() - if err := attrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyAttr *engine.AttributeProfile - if err := attrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_LIBPHONENUMBER_COMPOSED"}}, &replyAttr); err != nil { t.Fatal(err) } @@ -954,7 +955,7 @@ func testAttributeSProcessEventWithLibPhoneNumberComposed(t *testing.T) { } sort.Strings(eRply.AlteredFields) var rplyEv engine.AttrSProcessEventReply - if err := attrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } @@ -994,13 +995,13 @@ func testAttributeSProcessEventWithLibPhoneNumberFull(t *testing.T) { }, } alsPrf.Compile() - if err := attrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := attrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyAttr *engine.AttributeProfile - if err := attrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := attrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_LIBPHONENUMBER"}}, &replyAttr); err != nil { t.Fatal(err) } @@ -1039,7 +1040,7 @@ func testAttributeSProcessEventWithLibPhoneNumberFull(t *testing.T) { } sort.Strings(eRply.AlteredFields) var rplyEv engine.AttrSProcessEventReply - if err := attrRPC.Call(utils.AttributeSv1ProcessEvent, + if err := attrRPC.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Fatal(err) } diff --git a/general_tests/auth_test.go b/general_tests/auth_test.go index 3cbb621f8..2079815cb 100644 --- a/general_tests/auth_test.go +++ b/general_tests/auth_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -132,7 +133,7 @@ func TestAuthPostpaidNoAcnt(t *testing.T) { t.Error(err) } var maxSessionTime time.Duration - if err := rsponder.GetMaxSessionTime(&engine.CallDescriptorWithAPIOpts{CallDescriptor: cd}, &maxSessionTime); err != utils.ErrAccountNotFound { + if err := rsponder.GetMaxSessionTime(context.Background(), &engine.CallDescriptorWithAPIOpts{CallDescriptor: cd}, &maxSessionTime); err != utils.ErrAccountNotFound { t.Error(err) } } @@ -147,7 +148,7 @@ func TestAuthPostpaidFallbackDest(t *testing.T) { t.Error(err) } var maxSessionTime time.Duration - if err = rsponder.GetMaxSessionTime(&engine.CallDescriptorWithAPIOpts{CallDescriptor: cd}, &maxSessionTime); err != nil { + if err = rsponder.GetMaxSessionTime(context.Background(), &engine.CallDescriptorWithAPIOpts{CallDescriptor: cd}, &maxSessionTime); err != nil { t.Error(err) } else if maxSessionTime != 0 { t.Error("Unexpected maxSessionTime received: ", maxSessionTime) @@ -164,7 +165,7 @@ func TestAuthPostpaidWithDestination(t *testing.T) { t.Error(err) } var maxSessionTime time.Duration - if err := rsponder.GetMaxSessionTime(&engine.CallDescriptorWithAPIOpts{CallDescriptor: cd}, &maxSessionTime); err != nil { + if err := rsponder.GetMaxSessionTime(context.Background(), &engine.CallDescriptorWithAPIOpts{CallDescriptor: cd}, &maxSessionTime); err != nil { t.Error(err) } else if maxSessionTime != 0 { t.Error("Unexpected maxSessionTime received: ", maxSessionTime) diff --git a/general_tests/broadcast_client_it_test.go b/general_tests/broadcast_client_it_test.go index fb11bea1a..b58d2add0 100644 --- a/general_tests/broadcast_client_it_test.go +++ b/general_tests/broadcast_client_it_test.go @@ -21,12 +21,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,8 +39,8 @@ var ( brodcastInternalCfgDIR string brodcastCfg *config.CGRConfig brodcastInternalCfg *config.CGRConfig - brodcastRPC *rpc.Client - brodcastInternalRPC *rpc.Client + brodcastRPC *birpc.Client + brodcastInternalRPC *birpc.Client sTestBrodcastIt = []func(t *testing.T){ testbrodcastItLoadConfig, @@ -124,10 +125,10 @@ func testbrodcastItRPCConn(t *testing.T) { func testbrodcastItLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := brodcastRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := brodcastRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } - if err := brodcastInternalRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := brodcastInternalRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(200 * time.Millisecond) @@ -152,7 +153,7 @@ func testbrodcastItProccessEvent(t *testing.T) { } var rply string - if err := brodcastRPC.Call(utils.SessionSv1ProcessCDR, args, &rply); err != nil { + if err := brodcastRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, args, &rply); err != nil { t.Fatal(err) } if rply != utils.OK { @@ -187,7 +188,7 @@ func testbrodcastItGetCDRs(t *testing.T) { } var cdrs []*engine.CDR args := utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}}} - if err := brodcastRPC.Call(utils.CDRsV1GetCDRs, &args, &cdrs); err != nil { + if err := brodcastRPC.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Fatal("Unexpected number of CDRs returned: ", len(cdrs)) @@ -197,7 +198,7 @@ func testbrodcastItGetCDRs(t *testing.T) { t.Errorf("Expected: %s ,received: %s", utils.ToJSON(eCDR), utils.ToJSON(cdrs[0])) } - if err := brodcastInternalRPC.Call(utils.CDRsV1GetCDRs, &args, &cdrs); err != nil { + if err := brodcastInternalRPC.Call(context.Background(), utils.CDRsV1GetCDRs, &args, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) diff --git a/general_tests/cacherpl_filter_update_it_test.go b/general_tests/cacherpl_filter_update_it_test.go index 9108bda78..92d5ac1df 100644 --- a/general_tests/cacherpl_filter_update_it_test.go +++ b/general_tests/cacherpl_filter_update_it_test.go @@ -21,13 +21,14 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "os/exec" "path" "reflect" "sort" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ var ( fltrUpdateCfgPath1, fltrUpdateCfgPath2 string fltrUpdateCfgDIR1, fltrUpdateCfgDIR2 string fltrUpdateCfg1, fltrUpdateCfg2 *config.CGRConfig - fltrUpdateRPC1, fltrUpdateRPC2 *rpc.Client + fltrUpdateRPC1, fltrUpdateRPC2 *birpc.Client testEng1 *exec.Cmd sTestsFilterUpdate = []func(t *testing.T){ testFilterUpdateInitCfg, @@ -168,14 +169,14 @@ func testFilterUpdateSetFilterE1(t *testing.T) { } var reply string - if err := fltrUpdateRPC1.Call(utils.APIerSv1SetFilter, fltr, &reply); err != nil { + if err := fltrUpdateRPC1.Call(context.Background(), utils.APIerSv1SetFilter, fltr, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } var result *engine.Filter - if err := fltrUpdateRPC1.Call(utils.APIerSv1GetFilter, + if err := fltrUpdateRPC1.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ID"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(fltr.Filter, result) { @@ -206,13 +207,13 @@ func testFilterUpdateSetAttrProfileE1(t *testing.T) { attrPrf.Compile() var reply string - if err := fltrUpdateRPC1.Call(utils.APIerSv1SetAttributeProfile, attrPrf, &reply); err != nil { + if err := fltrUpdateRPC1.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } var result *engine.AttributeProfile - if err := fltrUpdateRPC1.Call(utils.APIerSv1GetAttributeProfile, + if err := fltrUpdateRPC1.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_ID"}}, &result); err != nil { t.Fatal(err) } @@ -240,7 +241,7 @@ func testFilterUpdateGetAttrProfileForEventEv1E1(t *testing.T) { eAttrPrf.Compile() var attrReply *engine.AttributeProfile - if err := fltrUpdateRPC1.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrUpdateRPC1.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev1, &attrReply); err != nil { t.Fatal(err) } @@ -269,7 +270,7 @@ func testFilterUpdateGetAttrProfileForEventEv1E2(t *testing.T) { eAttrPrf.Compile() var attrReply *engine.AttributeProfile - if err := fltrUpdateRPC2.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrUpdateRPC2.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev1, &attrReply); err != nil { t.Fatal(err) } @@ -298,7 +299,7 @@ func testFilterUpdateGetAttrProfileForEventEv2E1(t *testing.T) { eAttrPrf.Compile() var attrReply *engine.AttributeProfile - if err := fltrUpdateRPC1.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrUpdateRPC1.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev2, &attrReply); err != nil { t.Fatal(err) } @@ -327,7 +328,7 @@ func testFilterUpdateGetAttrProfileForEventEv2E2(t *testing.T) { eAttrPrf.Compile() var attrReply *engine.AttributeProfile - if err := fltrUpdateRPC2.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrUpdateRPC2.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev2, &attrReply); err != nil { t.Fatal(err) } @@ -357,14 +358,14 @@ func testFilterUpdateSetFilterAfterAttrE1(t *testing.T) { } var reply string - if err := fltrUpdateRPC1.Call(utils.APIerSv1SetFilter, fltr, &reply); err != nil { + if err := fltrUpdateRPC1.Call(context.Background(), utils.APIerSv1SetFilter, fltr, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } var result *engine.Filter - if err := fltrUpdateRPC1.Call(utils.APIerSv1GetFilter, + if err := fltrUpdateRPC1.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ID"}, &result); err != nil { t.Error(err) } else if !reflect.DeepEqual(fltr.Filter, result) { @@ -374,7 +375,7 @@ func testFilterUpdateSetFilterAfterAttrE1(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv1E1NotMatching(t *testing.T) { var attrReply *engine.AttributeProfile - if err := fltrUpdateRPC1.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrUpdateRPC1.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev1, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } @@ -382,7 +383,7 @@ func testFilterUpdateGetAttrProfileForEventEv1E1NotMatching(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv1E2NotMatching(t *testing.T) { var attrReply *engine.AttributeProfile - if err := fltrUpdateRPC2.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrUpdateRPC2.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev1, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } @@ -390,7 +391,7 @@ func testFilterUpdateGetAttrProfileForEventEv1E2NotMatching(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv2E1NotMatching(t *testing.T) { var attrReply *engine.AttributeProfile - if err := fltrUpdateRPC1.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrUpdateRPC1.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev2, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } @@ -398,7 +399,7 @@ func testFilterUpdateGetAttrProfileForEventEv2E1NotMatching(t *testing.T) { func testFilterUpdateGetAttrProfileForEventEv2E2NotMatching(t *testing.T) { var attrReply *engine.AttributeProfile - if err := fltrUpdateRPC2.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrUpdateRPC2.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev2, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } diff --git a/general_tests/cacherpl_it_test.go b/general_tests/cacherpl_it_test.go index 9d802b92b..9ae2ada75 100644 --- a/general_tests/cacherpl_it_test.go +++ b/general_tests/cacherpl_it_test.go @@ -21,7 +21,6 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "os/exec" "path" "reflect" @@ -30,6 +29,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" @@ -40,13 +41,13 @@ import ( var ( dspEngine1Cfg *config.CGRConfig dspEngine1CfgPath string - dspEngine1RPC *rpc.Client + dspEngine1RPC *birpc.Client dspEngine2Cfg *config.CGRConfig dspEngine2CfgPath string - dspEngine2RPC *rpc.Client + dspEngine2RPC *birpc.Client engine1Cfg *config.CGRConfig engine1CfgPath string - engine1RPC *rpc.Client + engine1RPC *birpc.Client sTestsCacheRpl = []func(t *testing.T){ testCacheRplInitCfg, @@ -240,7 +241,7 @@ func testCacheRplAddData(t *testing.T) { }, } var result string - if err := engine1RPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := engine1RPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -299,7 +300,7 @@ func testCacheRplAAAddData(t *testing.T) { }, } var result string - if err := engine1RPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := engine1RPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -314,14 +315,14 @@ func testCacheRplPing(t *testing.T) { utils.OptsRouteID: "testRoute123", }, } - if err := dspEngine1RPC.Call(utils.DispatcherSv1RemoteStatus, &ev, &reply); err != nil { + if err := dspEngine1RPC.Call(context.Background(), utils.DispatcherSv1RemoteStatus, &ev, &reply); err != nil { t.Error(err) } else if reply[utils.NodeID] != "Engine1" { t.Errorf("Received: %s", utils.ToJSON(reply)) } var rpl string - if err := dspEngine1RPC.Call(utils.AttributeSv1Ping, &utils.CGREvent{ + if err := dspEngine1RPC.Call(context.Background(), utils.AttributeSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ @@ -339,7 +340,7 @@ func testCacheRplCheckReplication(t *testing.T) { ev := utils.TenantWithAPIOpts{ Tenant: "cgrates.org", } - if err := dspEngine2RPC.Call(utils.DispatcherSv1RemoteStatus, &ev, &reply); err != nil { + if err := dspEngine2RPC.Call(context.Background(), utils.DispatcherSv1RemoteStatus, &ev, &reply); err != nil { t.Error(err) } else if reply[utils.NodeID] != "DispatcherEngine2" { t.Errorf("Received: %s", utils.ToJSON(reply)) @@ -352,7 +353,7 @@ func testCacheRplCheckReplication(t *testing.T) { CacheID: utils.CacheDispatcherRoutes, }, } - if err := dspEngine2RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := dspEngine2RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Error(err.Error()) } sort.Strings(rcvKeys) @@ -362,7 +363,7 @@ func testCacheRplCheckReplication(t *testing.T) { } var rpl string - if err := dspEngine2RPC.Call(utils.AttributeSv1Ping, &utils.CGREvent{ + if err := dspEngine2RPC.Call(context.Background(), utils.AttributeSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ @@ -383,17 +384,17 @@ func testCacheRplAACheckReplication(t *testing.T) { CacheID: utils.CacheDispatcherRoutes, }, } - if err := dspEngine1RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || + if err := dspEngine1RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := dspEngine2RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || + if err := dspEngine2RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } var rpl string - if err := dspEngine2RPC.Call(utils.AttributeSv1Ping, &utils.CGREvent{ + if err := dspEngine2RPC.Call(context.Background(), utils.AttributeSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ @@ -405,7 +406,7 @@ func testCacheRplAACheckReplication(t *testing.T) { t.Errorf("Received: %s", rpl) } - if err := dspEngine1RPC.Call(utils.AttributeSv1Ping, &utils.CGREvent{ + if err := dspEngine1RPC.Call(context.Background(), utils.AttributeSv1Ping, &utils.CGREvent{ Tenant: "cgrates.org", APIOpts: map[string]any{ utils.OptsRouteID: "testRouteFromDispatcher1", @@ -418,7 +419,7 @@ func testCacheRplAACheckReplication(t *testing.T) { expKeys := []string{"testRouteFromDispatcher2:*attributes", "testRouteFromDispatcher1:*attributes"} - if err := dspEngine2RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := dspEngine2RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Error(err.Error()) } sort.Strings(rcvKeys) @@ -427,7 +428,7 @@ func testCacheRplAACheckReplication(t *testing.T) { t.Errorf("Expected: %+v, received: %+v", expKeys, rcvKeys) } - if err := dspEngine1RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := dspEngine1RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Error(err.Error()) } sort.Strings(rcvKeys) @@ -446,11 +447,11 @@ func testCacheRplAACheckLoadReplication(t *testing.T) { CacheID: utils.CacheDispatcherLoads, }, } - if err := dspEngine2RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || + if err := dspEngine2RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := dspEngine1RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || + if err := dspEngine1RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -462,7 +463,7 @@ func testCacheRplAACheckLoadReplication(t *testing.T) { wgDisp2.Add(1) go func() { var rpl []*engine.ChrgSProcessEventReply - if err := dspEngine1RPC.Call(utils.ChargerSv1ProcessEvent, &utils.CGREvent{ + if err := dspEngine1RPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, &utils.CGREvent{ Tenant: "cgrates.org", ID: "testCacheRplAACheckLoadReplication", Event: map[string]any{ @@ -483,7 +484,7 @@ func testCacheRplAACheckLoadReplication(t *testing.T) { }() go func() { var rpl []*engine.ChrgSProcessEventReply - if err := dspEngine2RPC.Call(utils.ChargerSv1ProcessEvent, &utils.CGREvent{ + if err := dspEngine2RPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, &utils.CGREvent{ Tenant: "cgrates.org", ID: "testCacheRplAACheckLoadReplication", @@ -515,7 +516,7 @@ func testCacheRplAACheckLoadReplication(t *testing.T) { CacheID: utils.CacheDispatcherRoutes, }, } - if err := dspEngine2RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := dspEngine2RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Error(err.Error()) } sort.Strings(rcvKeys) @@ -523,7 +524,7 @@ func testCacheRplAACheckLoadReplication(t *testing.T) { if !reflect.DeepEqual(expKeys, rcvKeys) { t.Errorf("Expected: %+v, received: %+v", expKeys, rcvKeys) } - if err := dspEngine1RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := dspEngine1RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Error(err.Error()) } sort.Strings(rcvKeys) @@ -539,7 +540,7 @@ func testCacheRplAACheckLoadReplication(t *testing.T) { CacheID: utils.CacheDispatcherLoads, }, } - if err := dspEngine2RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := dspEngine2RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Error(err.Error()) } sort.Strings(rcvKeys) @@ -547,7 +548,7 @@ func testCacheRplAACheckLoadReplication(t *testing.T) { if !reflect.DeepEqual(expKeys, rcvKeys) { t.Errorf("Expected: %+v, received: %+v", expKeys, rcvKeys) } - if err := dspEngine1RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := dspEngine1RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Error(err.Error()) } sort.Strings(rcvKeys) @@ -565,7 +566,7 @@ func testCacheRplCheckLoadReplication(t *testing.T) { CacheID: utils.CacheDispatcherLoads, }, } - if err := dspEngine2RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := dspEngine2RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -574,7 +575,7 @@ func testCacheRplCheckLoadReplication(t *testing.T) { for i := 0; i < 10; i++ { wg.Add(1) go func() { - if err := dspEngine1RPC.Call(utils.ChargerSv1ProcessEvent, &utils.CGREvent{ + if err := dspEngine1RPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, &utils.CGREvent{ Tenant: "cgrates.org", ID: "testCacheRplCheckLoadReplication", @@ -603,7 +604,7 @@ func testCacheRplCheckLoadReplication(t *testing.T) { CacheID: utils.CacheDispatcherRoutes, }, } - if err := dspEngine2RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := dspEngine2RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Error(err.Error()) } sort.Strings(rcvKeys) @@ -619,7 +620,7 @@ func testCacheRplCheckLoadReplication(t *testing.T) { CacheID: utils.CacheDispatcherLoads, }, } - if err := dspEngine2RPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { + if err := dspEngine2RPC.Call(context.Background(), utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil { t.Error(err.Error()) } sort.Strings(rcvKeys) diff --git a/general_tests/cdrs_exp_it_test.go b/general_tests/cdrs_exp_it_test.go index 147dc6c75..4c5679ac5 100644 --- a/general_tests/cdrs_exp_it_test.go +++ b/general_tests/cdrs_exp_it_test.go @@ -23,11 +23,9 @@ package general_tests import ( "bytes" - "context" "encoding/json" "fmt" "net/http" - "net/rpc" "net/url" "os" "os/exec" @@ -37,6 +35,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/ees" @@ -50,7 +50,7 @@ var ( cdrsExpCfgPath string cdrsExpCfgDir string cdrsExpCfg *config.CGRConfig - cdrsExpRPC *rpc.Client + cdrsExpRPC *birpc.Client cdrsExpHTTPEv = make(chan map[string]any, 1) cdrsExpHTTPServer *http.Server @@ -233,7 +233,7 @@ func testCDRsExpLoadAddCharger(t *testing.T) { }, } var result string - if err := cdrsExpRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := cdrsExpRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -246,7 +246,7 @@ func testCDRsExpExportEvent(t *testing.T) { t.Error(err) } var reply string - if err := cdrsExpRPC.Call(utils.CDRsV1ProcessEvent, + if err := cdrsExpRPC.Call(context.Background(), utils.CDRsV1ProcessEvent, &engine.ArgV1ProcessEvent{ Flags: []string{"*export:true", utils.MetaRALs}, CGREvent: *cdrsExpEv, diff --git a/general_tests/cdrs_internal_it_test.go b/general_tests/cdrs_internal_it_test.go index 85a3ecf68..1d80e6e90 100644 --- a/general_tests/cdrs_internal_it_test.go +++ b/general_tests/cdrs_internal_it_test.go @@ -22,11 +22,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" "github.com/cgrates/cgrates/engine" @@ -38,7 +39,7 @@ var ( cdrsIntCfgPath string cdrsIntCfgDIR string cdrsIntCfg *config.CGRConfig - cdrsIntRPC *rpc.Client + cdrsIntRPC *birpc.Client sTestsCdrsInt = []func(t *testing.T){ testCdrsIntInitCfg, @@ -113,19 +114,19 @@ func testCdrsIntTestTTL(t *testing.T) { } var reply string - if err := cdrsIntRPC.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsIntRPC.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } var cdrs []*engine.ExternalCDR - if err := cdrsIntRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &cdrs); err != nil { + if err := cdrsIntRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Errorf("Expected 1 result received %v ", len(cdrs)) } time.Sleep(time.Second + 50*time.Millisecond) - if err := cdrsIntRPC.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &cdrs); err == nil || + if err := cdrsIntRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{}, &cdrs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal("Unexpected error: ", err) } diff --git a/general_tests/cdrs_it_test.go b/general_tests/cdrs_it_test.go index 815344653..cd84a39f8 100644 --- a/general_tests/cdrs_it_test.go +++ b/general_tests/cdrs_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( cdrsCfgPath string cdrsCfg *config.CGRConfig - cdrsRpc *rpc.Client + cdrsRpc *birpc.Client cdrsConfDIR string // run the tests for specific configuration // subtests to be executed for each confDIR @@ -137,21 +138,21 @@ func testV2CDRsRpcConn(t *testing.T) { func testV2CDRsLoadTariffPlanFromFolder(t *testing.T) { var loadInst utils.LoadInstance - if err := cdrsRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, &utils.AttrLoadTpFromFolder{FolderPath: path.Join( *dataDir, "tariffplans", "testit")}, &loadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups var resp string - if err := cdrsRpc.Call(utils.APIerSv1RemoveChargerProfile, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1RemoveChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "SupplierCharges"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } var reply *engine.ChargerProfile - if err := cdrsRpc.Call(utils.APIerSv1GetChargerProfile, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "SupplierCharges"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -182,7 +183,7 @@ func testV2CDRsProcessCDR(t *testing.T) { } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -192,14 +193,14 @@ func testV2CDRsProcessCDR(t *testing.T) { func testV2CDRsGetCdrs(t *testing.T) { var cdrCnt int64 req := utils.AttrGetCdrs{} - if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 2 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) } var cdrs []*engine.ExternalCDR args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -213,7 +214,7 @@ func testV2CDRsGetCdrs(t *testing.T) { } } args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -253,7 +254,7 @@ func testV2CDRsProcessCDR2(t *testing.T) { } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -263,14 +264,14 @@ func testV2CDRsProcessCDR2(t *testing.T) { func testV2CDRsGetCdrs2(t *testing.T) { var cdrCnt int64 req := utils.AttrGetCdrs{Accounts: []string{"testV2CDRsProcessCDR2"}} - if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 2 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) } var cdrs []*engine.ExternalCDR args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}, OriginIDs: []string{"testV2CDRsProcessCDR2"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -285,7 +286,7 @@ func testV2CDRsGetCdrs2(t *testing.T) { } } args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"testV2CDRsProcessCDR2"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -325,7 +326,7 @@ func testV2CDRsProcessCDR3(t *testing.T) { } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -335,14 +336,14 @@ func testV2CDRsProcessCDR3(t *testing.T) { func testV2CDRsGetCdrs3(t *testing.T) { var cdrCnt int64 req := utils.AttrGetCdrs{Accounts: []string{"testV2CDRsProcessCDR3"}} - if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 1 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) } var cdrs []*engine.ExternalCDR args := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, OriginIDs: []string{"testV2CDRsProcessCDR3"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -357,7 +358,7 @@ func testV2CDRsGetCdrs3(t *testing.T) { } } args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"testV2CDRsProcessCDR3"}} - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error("Unexpected error: ", err) } } @@ -386,7 +387,7 @@ func testV2CDRsProcessCDR4(t *testing.T) { } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -396,7 +397,7 @@ func testV2CDRsProcessCDR4(t *testing.T) { func testV2CDRsGetCdrs4(t *testing.T) { var cdrCnt int64 req := utils.AttrGetCdrs{Accounts: []string{"testV2CDRsProcessCDR4"}} - if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 2 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) @@ -406,7 +407,7 @@ func testV2CDRsGetCdrs4(t *testing.T) { RunIDs: []string{"raw"}, OriginIDs: []string{"testV2CDRsProcessCDR4"}, } - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } if len(cdrs) != 1 { @@ -423,7 +424,7 @@ func testV2CDRsGetCdrs4(t *testing.T) { RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"testV2CDRsProcessCDR4"}, } - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } if len(cdrs) != 1 { @@ -441,7 +442,7 @@ func testV2CDRsGetCdrs4(t *testing.T) { func testV2CDRsGetCdrs5(t *testing.T) { var cdrCnt int64 req := utils.RPCCDRsFilter{Accounts: []string{"testV2CDRsProcessCDR5"}} - if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 0 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) @@ -451,21 +452,21 @@ func testV2CDRsGetCdrs5(t *testing.T) { RunIDs: []string{"raw"}, OriginIDs: []string{"testV2CDRsProcessCDR5"}, } - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal("Unexpected error: ", err) } args = utils.RPCCDRsFilter{ RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"testV2CDRsProcessCDR5"}, } - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal("Unexpected error: ", err.Error()) } } func testV2CDRsSetStats(t *testing.T) { var reply *engine.StatQueueProfile - if err := cdrsRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "STS_PoccessCDR"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -487,12 +488,12 @@ func testV2CDRsSetStats(t *testing.T) { }, } var result string - if err := cdrsRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := cdrsRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "STS_PoccessCDR"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -505,7 +506,7 @@ func testV2CDRsSetThresholdProfile(t *testing.T) { // Set Action attrsAA := &utils.AttrSetActions{ActionsId: "ACT_THD_PoccessCDR", Actions: []*utils.TPAction{{Identifier: utils.MetaLog}}} - if err := cdrsRpc.Call(utils.APIerSv2SetActions, attrsAA, &actreply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &actreply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if actreply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", actreply) @@ -513,7 +514,7 @@ func testV2CDRsSetThresholdProfile(t *testing.T) { // Set Account attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "testV2CDRsProcessCDR5"} - if err := cdrsRpc.Call(utils.APIerSv1SetAccount, attrsSetAccount, &actreply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetAccount, attrsSetAccount, &actreply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if actreply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", actreply) @@ -522,7 +523,7 @@ func testV2CDRsSetThresholdProfile(t *testing.T) { // Set Threshold var reply *engine.ThresholdProfile var result string - if err := cdrsRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_PoccessCDR"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -539,12 +540,12 @@ func testV2CDRsSetThresholdProfile(t *testing.T) { Async: false, }, } - if err := cdrsRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := cdrsRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_PoccessCDR"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { @@ -575,7 +576,7 @@ func testV2CDRsProcessCDR5(t *testing.T) { } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -588,7 +589,7 @@ func testV2CDRsGetStats1(t *testing.T) { expectedMetrics := map[string]string{ utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: utils.NotAvailable, } - if err := cdrsRpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := cdrsRpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}, }, &metrics); err != nil { @@ -601,14 +602,14 @@ func testV2CDRsGetStats1(t *testing.T) { func testV2CDRsGetThreshold1(t *testing.T) { expected := []string{"THD_ACNT_1001", "THD_PoccessCDR"} var result []string - if err := cdrsRpc.Call(utils.APIerSv1GetThresholdProfileIDs, + if err := cdrsRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) } var td engine.Threshold - if err := cdrsRpc.Call(utils.ThresholdSv1GetThreshold, + if err := cdrsRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_PoccessCDR"}, }, &td); err != nil { @@ -641,7 +642,7 @@ func testV2CDRsProcessCDR6(t *testing.T) { } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -654,7 +655,7 @@ func testV2CDRsGetStats2(t *testing.T) { expectedMetrics := map[string]string{ utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: "120000000000", } - if err := cdrsRpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := cdrsRpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}, }, &metrics); err != nil { @@ -666,7 +667,7 @@ func testV2CDRsGetStats2(t *testing.T) { func testV2CDRsGetThreshold2(t *testing.T) { var td engine.Threshold - if err := cdrsRpc.Call(utils.ThresholdSv1GetThreshold, + if err := cdrsRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_PoccessCDR"}, }, &td); err != nil { @@ -700,7 +701,7 @@ func testV2CDRsProcessCDR7(t *testing.T) { } var reply string - if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -710,7 +711,7 @@ func testV2CDRsProcessCDR7(t *testing.T) { func testV2CDRsGetCdrs7(t *testing.T) { var cdrCnt int64 req := utils.AttrGetCdrs{Accounts: []string{"testV2CDRsProcessCDR7"}} - if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil { t.Error("Unexpected error: ", err.Error()) } else if cdrCnt != 2 { t.Error("Unexpected number of CDRs returned: ", cdrCnt) @@ -720,7 +721,7 @@ func testV2CDRsGetCdrs7(t *testing.T) { RunIDs: []string{"raw"}, OriginIDs: []string{"testV2CDRsProcessCDR7"}, } - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } if len(cdrs) != 1 { @@ -737,7 +738,7 @@ func testV2CDRsGetCdrs7(t *testing.T) { RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"testV2CDRsProcessCDR7"}, } - if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { + if err := cdrsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &args, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } if len(cdrs) != 1 { diff --git a/general_tests/cdrs_onlexp_it_test.go b/general_tests/cdrs_onlexp_it_test.go index b1f97900c..ca8336f33 100644 --- a/general_tests/cdrs_onlexp_it_test.go +++ b/general_tests/cdrs_onlexp_it_test.go @@ -22,7 +22,6 @@ along with this program. If not, see package general_tests import ( - "context" "encoding/json" "fmt" "net/http" @@ -34,6 +33,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/ees" "github.com/cgrates/cgrates/engine" @@ -185,8 +185,8 @@ func testCDRsOnExpAMQPQueuesCreation(t *testing.T) { // Connect rpc client to rater func testCDRsOnExpInitMasterRPC(t *testing.T) { var err error - cdrsMasterRpc, err = rpcclient.NewRPCClient(utils.TCP, cdrsMasterCfg.ListenCfg().RPCJSONListen, false, "", "", "", 1, 1, - time.Second, 5*time.Second, rpcclient.JSONrpc, nil, false, nil) + cdrsMasterRpc, err = rpcclient.NewRPCClient(context.Background(), utils.TCP, cdrsMasterCfg.ListenCfg().RPCJSONListen, false, "", "", "", 1, 1, + 0, utils.FibDuration, time.Second, 5*time.Second, rpcclient.JSONrpc, nil, false, nil) if err != nil { t.Fatal("Could not connect to rater: ", err.Error()) } @@ -202,7 +202,7 @@ func testCDRsOnExpLoadDefaultCharger(t *testing.T) { Weight: 20, } var result string - if err := cdrsMasterRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := cdrsMasterRpc.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -235,7 +235,8 @@ func testCDRsOnExpDisableOnlineExport(t *testing.T) { }, } var reply string - if err := cdrsMasterRpc.Call(utils.CDRsV1ProcessEvent, + if err := cdrsMasterRpc.Call(context.Background(), + utils.CDRsV1ProcessEvent, &engine.ArgV1ProcessEvent{ Flags: []string{"*export:false", "*chargers:false"}, CGREvent: *testCdr.AsCGREvent(), @@ -280,21 +281,22 @@ func testCDRsOnExpHttpCdrReplication(t *testing.T) { arg.APIOpts = map[string]any{"ExporterID": "http_localhost"} // we expect that the cdr export to fail and go into the failed post directory - if err := cdrsMasterRpc.Call(utils.CDRsV1ProcessEvent, + if err := cdrsMasterRpc.Call(context.Background(), + utils.CDRsV1ProcessEvent, &engine.ArgV1ProcessEvent{ CGREvent: *arg, }, &reply); err == nil || err.Error() != utils.ErrPartiallyExecuted.Error() { t.Error("Unexpected error: ", err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) - cdrsSlaveRpc, err := rpcclient.NewRPCClient(utils.TCP, "127.0.0.1:12012", false, "", "", "", 1, 1, - time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) + cdrsSlaveRpc, err := rpcclient.NewRPCClient(context.Background(), utils.TCP, "127.0.0.1:12012", false, "", "", "", 1, 1, + 0, utils.FibDuration, time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) if err != nil { t.Fatal("Could not connect to rater: ", err.Error()) } // ToDo: Fix cdr_http to be compatible with rest of processCdr methods var rcvedCdrs []*engine.ExternalCDR - if err := cdrsSlaveRpc.Call(utils.APIerSv2GetCDRs, + if err := cdrsSlaveRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{CGRIDs: []string{testCdr1.CGRID}, RunIDs: []string{utils.MetaDefault}}, &rcvedCdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(rcvedCdrs) != 1 { @@ -396,7 +398,8 @@ func testCDRsOnExpAMQPReplication(t *testing.T) { }, } var reply string - if err := cdrsMasterRpc.Call(utils.CDRsV1ProcessEvent, + if err := cdrsMasterRpc.Call(context.Background(), + utils.CDRsV1ProcessEvent, &engine.ArgV1ProcessEvent{ Flags: []string{"*export:true"}, diff --git a/general_tests/cdrs_post_failover_it_test.go b/general_tests/cdrs_post_failover_it_test.go index 75db3c6ac..e97fa13b0 100644 --- a/general_tests/cdrs_post_failover_it_test.go +++ b/general_tests/cdrs_post_failover_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "os" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/ees" "github.com/cgrates/cgrates/engine" @@ -37,7 +38,7 @@ import ( var ( cdrsPostFailCfgPath string cdrsPostFailCfg *config.CGRConfig - cdrsPostFailRpc *rpc.Client + cdrsPostFailRpc *birpc.Client cdrsPostFailConfDIR string // run the tests for specific configuration // subtests to be executed for each confDIR @@ -117,21 +118,21 @@ func testCDRsPostFailoverRpcConn(t *testing.T) { func testCDRsPostFailoverLoadTariffPlanFromFolder(t *testing.T) { var loadInst utils.LoadInstance - if err := cdrsPostFailRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := cdrsPostFailRpc.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, &utils.AttrLoadTpFromFolder{FolderPath: path.Join( *dataDir, "tariffplans", "testit")}, &loadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups var resp string - if err := cdrsPostFailRpc.Call(utils.APIerSv1RemoveChargerProfile, + if err := cdrsPostFailRpc.Call(context.Background(), utils.APIerSv1RemoveChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "SupplierCharges"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } var reply *engine.ChargerProfile - if err := cdrsPostFailRpc.Call(utils.APIerSv1GetChargerProfile, + if err := cdrsPostFailRpc.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "SupplierCharges"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -163,21 +164,21 @@ func testCDRsPostFailoverProcessCDR(t *testing.T) { } var reply string - if err := cdrsPostFailRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsPostFailRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } args.ID = "2" args.Event[utils.OriginID] = "2" - if err := cdrsPostFailRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsPostFailRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } args.ID = "3" args.Event[utils.OriginID] = "3" - if err := cdrsPostFailRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := cdrsPostFailRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) diff --git a/general_tests/cdrs_processevent_it_test.go b/general_tests/cdrs_processevent_it_test.go index b588de4b9..17047171f 100644 --- a/general_tests/cdrs_processevent_it_test.go +++ b/general_tests/cdrs_processevent_it_test.go @@ -22,7 +22,6 @@ package general_tests import ( "fmt" - "net/rpc" "os" "path" "reflect" @@ -31,6 +30,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/ees" @@ -42,7 +43,7 @@ var ( pecdrsCfgPath string pecdrsConfDIR string pecdrsCfg *config.CGRConfig - pecdrsRpc *rpc.Client + pecdrsRpc *birpc.Client sTestsCDRsIT_ProcessEvent = []func(t *testing.T){ testV1CDRsInitConfig, @@ -128,7 +129,7 @@ func testV1CDRsRpcConn(t *testing.T) { func testV1CDRsLoadTariffPlanFromFolder(t *testing.T) { var loadInst string - if err := pecdrsRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, + if err := pecdrsRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, &utils.AttrLoadTpFromFolder{FolderPath: path.Join( *dataDir, "tariffplans", "testit")}, &loadInst); err != nil { t.Error(err) @@ -152,13 +153,13 @@ func testV1CDRsProcessEventAttrS(t *testing.T) { }, } var reply string - if err := pecdrsRpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("received: %s", reply) } expectedVoice := 120000000000.0 - if err := pecdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != expectedVoice { t.Errorf("Expecting: %v, received: %v", expectedVoice, rply) @@ -198,13 +199,13 @@ func testV1CDRsProcessEventAttrS(t *testing.T) { } alsPrf.Compile() var result string - if err := pecdrsRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyAt *engine.AttributeProfile - if err := pecdrsRpc.Call(utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{ + if err := pecdrsRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}}, &replyAt); err != nil { t.Fatal(err) } @@ -212,13 +213,13 @@ func testV1CDRsProcessEventAttrS(t *testing.T) { if !reflect.DeepEqual(alsPrf.AttributeProfile, replyAt) { t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.AttributeProfile), utils.ToJSON(replyAt)) } - if err := pecdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } // check if the CDR was correctly processed - if err := pecdrsRpc.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{OriginHosts: []string{"OriginHost1"}}}, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { @@ -265,13 +266,13 @@ func testV1CDRsProcessEventChrgS(t *testing.T) { }, } var reply string - if err := pecdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } var cdrs []*engine.CDR - if err := pecdrsRpc.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{OriginHosts: []string{"OriginHost2"}}}, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } else if len(cdrs) != 3 { @@ -308,13 +309,13 @@ func testV1CDRsProcessEventRalS(t *testing.T) { }, } var reply string - if err := pecdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } var cdrs []*engine.CDR - if err := pecdrsRpc.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{OriginHosts: []string{"OriginHost3"}}}, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { @@ -348,7 +349,7 @@ func testV1CDRsProcessEventSts(t *testing.T) { }, } var reply string - if err := pecdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -381,7 +382,7 @@ func testV1CDRsProcessEventSts(t *testing.T) { CostDetails: nil, }, } - if err := pecdrsRpc.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{OriginHosts: []string{"OriginHost4"}}}, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { @@ -400,7 +401,7 @@ func testV1CDRsProcessEventSts(t *testing.T) { utils.MetaTCD: "15m0s", } - if err := pecdrsRpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := pecdrsRpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_1"}}, &metrics); err != nil { t.Error(err) } @@ -428,13 +429,13 @@ func testV1CDRsProcessEventStore(t *testing.T) { }, } var reply string - if err := pecdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } var cdrs []*engine.CDR - if err := pecdrsRpc.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{OriginHosts: []string{"OriginHost5"}}}, &cdrs); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { t.Fatal("Unexpected error: ", err.Error()) @@ -445,7 +446,7 @@ func testV1CDRsProcessEventStore(t *testing.T) { func testV1CDRsProcessEventThreshold(t *testing.T) { var reply string - if err := pecdrsRpc.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{ + if err := pecdrsRpc.Call(context.Background(), utils.APIerSv2SetActions, &utils.AttrSetActions{ ActionsId: "ACT_LOG", Actions: []*utils.TPAction{ {Identifier: utils.MetaLog}, @@ -473,7 +474,7 @@ func testV1CDRsProcessEventThreshold(t *testing.T) { Async: true, }, } - if err := pecdrsRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -485,7 +486,7 @@ func testV1CDRsProcessEventThreshold(t *testing.T) { utils.AllowNegative: true, }, } - if err := pecdrsRpc.Call(utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil { t.Fatal(err) } attrs := &utils.AttrSetBalance{ @@ -498,7 +499,7 @@ func testV1CDRsProcessEventThreshold(t *testing.T) { utils.Weight: 10.0, }, } - if err := pecdrsRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Fatal(err) } args := &engine.ArgV1ProcessEvent{ @@ -521,21 +522,21 @@ func testV1CDRsProcessEventThreshold(t *testing.T) { }, }, } - if err := pecdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } var cdrs []*engine.CDR - if err := pecdrsRpc.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{OriginHosts: []string{"OriginHost6"}}}, &cdrs); err != nil { t.Error("Unexpected error: ", err) } else if len(cdrs) != 1 { t.Errorf("Expecting: 1, received: %+v", len(cdrs)) } var td engine.Threshold - if err := pecdrsRpc.Call(utils.ThresholdSv1GetThreshold, + if err := pecdrsRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &td); err != nil { t.Error(err) } else if td.Hits != 1 { @@ -547,7 +548,7 @@ func testV1CDRsProcessEventThreshold(t *testing.T) { Account: "1005"} time.Sleep(50 * time.Millisecond) expectedVoice := 10.0 - if err := pecdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != expectedVoice { t.Errorf("Expecting: %v, received: %v", expectedVoice, rply) @@ -572,7 +573,7 @@ func testV1CDRsProcessEventExport(t *testing.T) { }, }, } - if err := pecdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err == nil || + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err == nil || err.Error() != utils.ErrPartiallyExecuted.Error() { // the export should fail as we test if the cdr is corectly writen in file t.Error("Unexpected error: ", err) } @@ -655,7 +656,7 @@ func testV1CDRsV2ProcessEventRalS(t *testing.T) { }, } var reply []*utils.EventWithFlags - if err := pecdrsRpc.Call(utils.CDRsV2ProcessEvent, argsEv, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV2ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } reply[0].Event["CostDetails"] = nil @@ -671,7 +672,7 @@ func testV1CDRsV2ProcessEventRalS(t *testing.T) { } } var cdrs []*engine.CDR - if err := pecdrsRpc.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{OriginHosts: []string{"OriginHost101"}}}, &cdrs); err != nil { t.Fatal("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { @@ -684,7 +685,7 @@ func testV1CDRsV2ProcessEventRalS(t *testing.T) { argsEv.CGREvent.ID = "test1002" argsEv.CGREvent.Event[utils.Usage] = time.Minute - if err := pecdrsRpc.Call(utils.CDRsV2ProcessEvent, argsEv, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV2ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } expRply[0].Event["Usage"] = 60000000000. @@ -702,7 +703,7 @@ func testV1CDRsV2ProcessEventRalS(t *testing.T) { } argsEv.CGREvent.Event[utils.Usage] = 30 * time.Second - if err := pecdrsRpc.Call(utils.CDRsV2ProcessEvent, argsEv, &reply); err != nil { + if err := pecdrsRpc.Call(context.Background(), utils.CDRsV2ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } reply[0].Event["CostDetails"] = nil diff --git a/general_tests/cgrloader_it_test.go b/general_tests/cgrloader_it_test.go index 7095eac03..840f8a813 100644 --- a/general_tests/cgrloader_it_test.go +++ b/general_tests/cgrloader_it_test.go @@ -23,11 +23,12 @@ package general_tests import ( "flag" - "net/rpc" "os/exec" "path" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ var ( loaderGoogleSheet = flag.Bool("google_sheet", false, "Run the test with google sheet") cgrloaderCfgPath string cgrloaderCfg *config.CGRConfig - cgrloaderRPC *rpc.Client + cgrloaderRPC *birpc.Client cgrloaderConfDIR string //run tests for specific configuration sTestsCGRLoaders = []func(t *testing.T){ @@ -128,7 +129,7 @@ func testCGRLoaderGetData(t *testing.T) { "ATTR_1001_SESSIONAUTH", "ATTR_1002_SESSIONAUTH", "ATTR_1003_SESSIONAUTH", "ATTR_ACC_ALIAS"} var result []string - if err := cgrloaderRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { + if err := cgrloaderRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) diff --git a/general_tests/data_it_test.go b/general_tests/data_it_test.go index e41361c98..8fb9e803a 100644 --- a/general_tests/data_it_test.go +++ b/general_tests/data_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -36,7 +37,7 @@ import ( var ( dataCfgPath string dataCfg *config.CGRConfig - dataRpc *rpc.Client + dataRpc *birpc.Client dataConfDIR string //run tests for specific configuration dataDelay int @@ -116,7 +117,7 @@ func testV1DataRpcConn(t *testing.T) { func testV1DataGetAccountBeforeSet(t *testing.T) { var reply *engine.Account - if err := dataRpc.Call(utils.APIerSv2GetAccount, + if err := dataRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -126,7 +127,7 @@ func testV1DataGetAccountBeforeSet(t *testing.T) { func testV1DataLoadTarrifPlans(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testData")} - if err := dataRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := dataRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -147,7 +148,7 @@ func testV1DataDataDebitUsageWith10Kilo(t *testing.T) { }, } var reply string - if err := dataRpc.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := dataRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -155,7 +156,7 @@ func testV1DataDataDebitUsageWith10Kilo(t *testing.T) { expected := 356000000.0 var acc *engine.Account - if err := dataRpc.Call(utils.APIerSv2GetAccount, + if err := dataRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV1DataDataCost"}, &acc); err != nil { t.Error(err) @@ -177,7 +178,7 @@ func testV1DataDataDebitUsageWith10Kilo(t *testing.T) { AnswerTime: time.Date(2013, 11, 7, 7, 42, 20, 0, time.UTC).String(), } tStart := time.Now() - if err := dataRpc.Call(utils.APIerSv1DebitUsage, + if err := dataRpc.Call(context.Background(), utils.APIerSv1DebitUsage, &engine.UsageRecordWithAPIOpts{UsageRecord: usageRecord}, &reply); err != nil { t.Error(err) } @@ -186,7 +187,7 @@ func testV1DataDataDebitUsageWith10Kilo(t *testing.T) { } expected = 100000000.0 - if err := dataRpc.Call(utils.APIerSv2GetAccount, + if err := dataRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV1DataDataCost"}, &acc); err != nil { t.Error(err) @@ -203,7 +204,7 @@ func testV1DataGetCostWith10Kilo(t *testing.T) { Subject: "10kilo", AnswerTime: "*now", Usage: 256000000} var rply *engine.DataCost tStart := time.Now() - if err := dataRpc.Call(utils.APIerSv1GetDataCost, &attrs, &rply); err != nil { + if err := dataRpc.Call(context.Background(), utils.APIerSv1GetDataCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if rply.Cost != 25600.000000 { t.Errorf("Unexpected cost received: %f", rply.Cost) @@ -226,7 +227,7 @@ func testV1DataDebitBalanceWith10Kilo(t *testing.T) { }, } var reply string - if err := dataRpc.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := dataRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -234,7 +235,7 @@ func testV1DataDebitBalanceWith10Kilo(t *testing.T) { expected := 356000000.0 var acc *engine.Account - if err := dataRpc.Call(utils.APIerSv2GetAccount, + if err := dataRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV1DataDebitBalance"}, &acc); err != nil { t.Error(err) @@ -245,7 +246,7 @@ func testV1DataDebitBalanceWith10Kilo(t *testing.T) { expected, rply) } tStart := time.Now() - if err := dataRpc.Call(utils.APIerSv1DebitBalance, &v1.AttrAddBalance{ + if err := dataRpc.Call(context.Background(), utils.APIerSv1DebitBalance, &v1.AttrAddBalance{ Tenant: "cgrates.org", Account: "testV1DataDebitBalance", BalanceType: utils.MetaData, @@ -260,7 +261,7 @@ func testV1DataDebitBalanceWith10Kilo(t *testing.T) { } expected = 100000000.0 - if err := dataRpc.Call(utils.APIerSv2GetAccount, + if err := dataRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV1DataDebitBalance"}, &acc); err != nil { t.Error(err) @@ -285,7 +286,7 @@ func testV1DataDataDebitUsage1G0(t *testing.T) { }, } var reply string - if err := dataRpc.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := dataRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -293,7 +294,7 @@ func testV1DataDataDebitUsage1G0(t *testing.T) { expected := 1100000000.0 var acc *engine.Account - if err := dataRpc.Call(utils.APIerSv2GetAccount, + if err := dataRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV1DataDataDebitUsage1G0"}, &acc); err != nil { t.Error(err) @@ -315,7 +316,7 @@ func testV1DataDataDebitUsage1G0(t *testing.T) { AnswerTime: time.Date(2013, 11, 7, 7, 42, 20, 0, time.UTC).String(), } tStart := time.Now() - if err := dataRpc.Call(utils.APIerSv1DebitUsage, + if err := dataRpc.Call(context.Background(), utils.APIerSv1DebitUsage, &engine.UsageRecordWithAPIOpts{UsageRecord: usageRecord}, &reply); err != nil { t.Error(err) } @@ -324,7 +325,7 @@ func testV1DataDataDebitUsage1G0(t *testing.T) { } expected = 100000000.0 - if err := dataRpc.Call(utils.APIerSv2GetAccount, + if err := dataRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV1DataDataDebitUsage1G0"}, &acc); err != nil { t.Error(err) @@ -341,7 +342,7 @@ func testV1DataGetCost1G0(t *testing.T) { Subject: "10kilo", AnswerTime: "*now", Usage: 1000000000} var rply *engine.DataCost tStart := time.Now() - if err := dataRpc.Call(utils.APIerSv1GetDataCost, &attrs, &rply); err != nil { + if err := dataRpc.Call(context.Background(), utils.APIerSv1GetDataCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if rply.Cost != 100000.000000 { t.Errorf("Unexpected cost received: %f", rply.Cost) @@ -364,7 +365,7 @@ func testV1DataDebitBalance1G0(t *testing.T) { }, } var reply string - if err := dataRpc.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := dataRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -372,7 +373,7 @@ func testV1DataDebitBalance1G0(t *testing.T) { expected := 1100000000.0 var acc *engine.Account - if err := dataRpc.Call(utils.APIerSv2GetAccount, + if err := dataRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV1DataDebitBalance1G0"}, &acc); err != nil { t.Error(err) @@ -383,7 +384,7 @@ func testV1DataDebitBalance1G0(t *testing.T) { expected, rply) } tStart := time.Now() - if err := dataRpc.Call(utils.APIerSv1DebitBalance, &v1.AttrAddBalance{ + if err := dataRpc.Call(context.Background(), utils.APIerSv1DebitBalance, &v1.AttrAddBalance{ Tenant: "cgrates.org", Account: "testV1DataDebitBalance1G0", BalanceType: utils.MetaData, @@ -398,7 +399,7 @@ func testV1DataDebitBalance1G0(t *testing.T) { } expected = 100000000.0 - if err := dataRpc.Call(utils.APIerSv2GetAccount, + if err := dataRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV1DataDebitBalance1G0"}, &acc); err != nil { t.Error(err) @@ -423,7 +424,7 @@ func testV1DataInitSession(t *testing.T) { }, } var reply string - if err := dataRpc.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := dataRpc.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -431,7 +432,7 @@ func testV1DataInitSession(t *testing.T) { expected := 1100000000.0 var acc *engine.Account - if err := dataRpc.Call(utils.APIerSv2GetAccount, + if err := dataRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV1DataInitSession"}, &acc); err != nil { t.Error(err) @@ -471,13 +472,13 @@ func testV1DataInitSession(t *testing.T) { }, } var rply sessions.V1InitSessionReply - if err := dataRpc.Call(utils.SessionSv1InitiateSession, + if err := dataRpc.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err != nil { t.Error(err) } aSessions := make([]*sessions.ExternalSession, 0) - if err := dataRpc.Call(utils.SessionSv1GetActiveSessions, + if err := dataRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { @@ -517,12 +518,12 @@ func testV1DataUpdateWith1Mo(t *testing.T) { }, } var rply sessions.V1UpdateSessionReply - if err := dataRpc.Call(utils.SessionSv1UpdateSession, + if err := dataRpc.Call(context.Background(), utils.SessionSv1UpdateSession, args, &rply); err != nil { t.Error(err) } aSessions := make([]*sessions.ExternalSession, 0) - if err := dataRpc.Call(utils.SessionSv1GetActiveSessions, + if err := dataRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { @@ -561,12 +562,12 @@ func testV1DataUpdateWith1Go(t *testing.T) { }, } var rply sessions.V1UpdateSessionReply - if err := dataRpc.Call(utils.SessionSv1UpdateSession, + if err := dataRpc.Call(context.Background(), utils.SessionSv1UpdateSession, args, &rply); err != nil { t.Error(err) } aSessions := make([]*sessions.ExternalSession, 0) - if err := dataRpc.Call(utils.SessionSv1GetActiveSessions, + if err := dataRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { diff --git a/general_tests/dest_management_it_test.go b/general_tests/dest_management_it_test.go index 7ac47c79f..00de08b90 100644 --- a/general_tests/dest_management_it_test.go +++ b/general_tests/dest_management_it_test.go @@ -38,7 +38,7 @@ import ( var ( destCfgPath string destCfg *config.CGRConfig - destRPC *rpc.Client + destRPC *birpc.Client sTestDestManag = []func (t *testing.T){ testDestManagInitCfg, @@ -112,7 +112,7 @@ func testDestManagRpcConn(t *testing.T) { func testDestManagLoadTariffPlanFromFolderAll(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "alldests")} var destLoadInst utils.LoadInstance - if err := destRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -121,14 +121,14 @@ func testDestManagLoadTariffPlanFromFolderAll(t *testing.T) { func testDestManagAllDestinationLoaded(t *testing.T) { dests := make([]*engine.Destination, 0) - if err := destRPC.Call(utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { t.Error("Got error on APIerSv2.GetDestinations: ", err.Error()) } else if len(dests) != 6 { t.Errorf("Calling APIerSv2.GetDestinations got reply: %v", utils.ToIJSON(dests)) } var rcvStats utils.CacheStats - if err := destRPC.Call(utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error()) } else if rcvStats.Destinations != 9 { t.Errorf("Calling APIerSv1.GetCacheStats received: %+v", rcvStats) @@ -139,7 +139,7 @@ func testDestManagAllDestinationLoaded(t *testing.T) { func testDestManagLoadTariffPlanFromFolderRemoveSome(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "removesome")} var destLoadInst utils.LoadInstance - if err := destRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -147,14 +147,14 @@ func testDestManagLoadTariffPlanFromFolderRemoveSome(t *testing.T) { func testDestManagRemoveSomeDestinationLoaded(t *testing.T) { dests := make([]*engine.Destination, 0) - if err := destRPC.Call(utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { t.Error("Got error on APIerSv2.GetDestinations: ", err.Error()) } else if len(dests) != 6 { t.Errorf("Calling APIerSv2.GetDestinations got reply: %v", utils.ToIJSON(dests)) } var rcvStats utils.CacheStats - if err := destRPC.Call(utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error()) } else if rcvStats.Destinations != 9 { t.Errorf("Calling APIerSv1.GetCacheStats received: %+v", rcvStats) @@ -164,7 +164,7 @@ func testDestManagRemoveSomeDestinationLoaded(t *testing.T) { func testDestManagLoadTariffPlanFromFolderRemoveSomeFlush(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "removesome"), FlushDb: true} var destLoadInst utils.LoadInstance - if err := destRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -172,14 +172,14 @@ func testDestManagLoadTariffPlanFromFolderRemoveSomeFlush(t *testing.T) { func testDestManagRemoveSomeFlushDestinationLoaded(t *testing.T) { dests := make([]*engine.Destination, 0) - if err := destRPC.Call(utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { t.Error("Got error on APIerSv2.GetDestinations: ", err.Error()) } else if len(dests) != 4 { t.Errorf("Calling APIerSv2.GetDestinations got reply: %v", utils.ToIJSON(dests)) } var rcvStats utils.CacheStats - if err := destRPC.Call(utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error()) } else if rcvStats.Destinations != 5 { t.Errorf("Calling APIerSv1.GetCacheStats received: %+v", rcvStats) @@ -189,7 +189,7 @@ func testDestManagRemoveSomeFlushDestinationLoaded(t *testing.T) { func testDestManagLoadTariffPlanFromFolderAddBack(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "addback")} var destLoadInst utils.LoadInstance - if err := destRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -197,14 +197,14 @@ func testDestManagLoadTariffPlanFromFolderAddBack(t *testing.T) { func testDestManagAddBackDestinationLoaded(t *testing.T) { dests := make([]*engine.Destination, 0) - if err := destRPC.Call(utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { t.Error("Got error on APIerSv2.GetDestinations: ", err.Error()) } else if len(dests) != 6 { t.Errorf("Calling APIerSv2.GetDestinations got reply: %v", utils.ToIJSON(dests)) } var rcvStats utils.CacheStats - if err := destRPC.Call(utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error()) } else if rcvStats.Destinations != 9 { t.Errorf("Calling APIerSv1.GetCacheStats received: %+v", rcvStats) @@ -214,7 +214,7 @@ func testDestManagAddBackDestinationLoaded(t *testing.T) { func testDestManagLoadTariffPlanFromFolderAddOne(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "addone")} var destLoadInst utils.LoadInstance - if err := destRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -222,14 +222,14 @@ func testDestManagLoadTariffPlanFromFolderAddOne(t *testing.T) { func testDestManagAddOneDestinationLoaded(t *testing.T) { dests := make([]*engine.Destination, 0) - if err := destRPC.Call(utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { t.Error("Got error on APIerSv2.GetDestinations: ", err.Error()) } else if len(dests) != 7 { t.Errorf("Calling APIerSv2.GetDestinations got reply: %v", utils.ToIJSON(dests)) } var rcvStats utils.CacheStats - if err := destRPC.Call(utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error()) } else if rcvStats.Destinations != 10 { t.Errorf("Calling APIerSv1.GetCacheStats received: %+v", rcvStats) @@ -241,46 +241,46 @@ func testDestManagCacheWithGetCache(t *testing.T) { t.Fatal(err) } var reply string - if err := destRPC.Call(utils.APIerSv1ReloadCache, utils.AttrReloadCache{}, &reply); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv1ReloadCache, utils.AttrReloadCache{}, &reply); err != nil { t.Error("Got error on APIerSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ReloadCache received: %+v", reply) } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheall"), FlushDb: true} var destLoadInst utils.LoadInstance - if err := destRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups dests := make([]*engine.Destination, 0) - if err := destRPC.Call(utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { t.Error("Got error on APIerSv2.GetDestinations: ", err.Error()) } else if len(dests) != 1 { t.Errorf("Calling APIerSv2.GetDestinations got reply: %v", utils.ToIJSON(dests)) } var rcvStats utils.CacheStats - if err := destRPC.Call(utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error()) } else if rcvStats.Destinations != 2 { t.Errorf("Calling APIerSv1.GetCacheStats received: %+v", rcvStats) } attrs = &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheone"), FlushDb: true} - if err := destRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups dests = make([]*engine.Destination, 0) - if err := destRPC.Call(utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { t.Error("Got error on APIerSv2.GetDestinations: ", err.Error()) } else if len(dests) != 1 { t.Errorf("Calling APIerSv2.GetDestinations got reply: %v", utils.ToIJSON(dests)) } - if err := destRPC.Call(utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv1GetCacheStats, utils.AttrCacheStats{}, &rcvStats); err != nil { t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error()) } else if rcvStats.Destinations != 1 { t.Errorf("Calling APIerSv1.GetCacheStats received: %+v", rcvStats) @@ -292,20 +292,20 @@ func testDestManagCacheWithGetCost(t *testing.T) { t.Fatal(err) } var reply string - if err := destRPC.Call(utils.APIerSv1ReloadCache, utils.AttrReloadCache{}, &reply); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv1ReloadCache, utils.AttrReloadCache{}, &reply); err != nil { t.Error("Got error on APIerSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ReloadCache received: %+v", reply) } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheall"), FlushDb: true} var destLoadInst utils.LoadInstance - if err := destRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups dests := make([]*engine.Destination, 0) - if err := destRPC.Call(utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { t.Error("Got error on APIerSv2.GetDestinations: ", err.Error()) } else if len(dests) != 1 { t.Errorf("Calling APIerSv2.GetDestinations got reply: %v", utils.ToIJSON(dests)) @@ -320,26 +320,26 @@ func testDestManagCacheWithGetCost(t *testing.T) { TimeStart: time.Date(2016, 2, 24, 0, 0, 0, 0, time.UTC), TimeEnd: time.Date(2016, 2, 24, 0, 0, 10, 0, time.UTC), } - if err := destRPC.Call(utils.ResponderGetCost, cd, &cc); err != nil { + if err := destRPC.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { t.Error(err) } else if cc.Cost != 1.6667 { t.Error("Empty loadId received, loadInstance: ", utils.ToIJSON(cc)) } attrs = &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheone"), FlushDb: true} - if err := destRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &destLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups dests = make([]*engine.Destination, 0) - if err := destRPC.Call(utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + if err := destRPC.Call(context.Background(),utils.APIerSv2GetDestinations, &v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { t.Error("Got error on APIerSv2.GetDestinations: ", err.Error()) } else if len(dests) != 1 { t.Errorf("Calling APIerSv2.GetDestinations got reply: %v", utils.ToIJSON(dests)) } - if err := destRPC.Call(utils.ResponderGetCost, cd, &cc); err.Error() != utils.ErrUnauthorizedDestination.Error() { + if err := destRPC.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err.Error() != utils.ErrUnauthorizedDestination.Error() { t.Error(err) } } diff --git a/general_tests/destination_combined_it_test.go b/general_tests/destination_combined_it_test.go index e632f51df..7996a9b64 100644 --- a/general_tests/destination_combined_it_test.go +++ b/general_tests/destination_combined_it_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -101,7 +102,7 @@ func testDestinationRpcConn(t *testing.T) { func testDestinationFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tp_destination_with_any")} - if err := tutorialRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := tutorialRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -117,7 +118,7 @@ func testDestinationGetCostFor1002(t *testing.T) { Usage: "1m", } var rply *engine.EventCost - if err := tutorialRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutorialRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected error received: ", err.Error()) } else if *rply.Cost != 0.01 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -134,7 +135,7 @@ func testDestinationGetCostFor1003(t *testing.T) { Usage: "1m", } var rply *engine.EventCost - if err := tutorialRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutorialRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected error received: ", err.Error()) } else if *rply.Cost != 0.3 { t.Errorf("Unexpected cost received: %f", *rply.Cost) diff --git a/general_tests/dispatcher_opts_it_test.go b/general_tests/dispatcher_opts_it_test.go index da4925673..e33c1a795 100644 --- a/general_tests/dispatcher_opts_it_test.go +++ b/general_tests/dispatcher_opts_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -40,9 +41,9 @@ var ( setterCfg *config.CGRConfig cfg2OptsCfg *config.CGRConfig cfg1Cfg *config.CGRConfig - setterRPC *rpc.Client - cgr2RPC *rpc.Client - cgr1RPC *rpc.Client + setterRPC *birpc.Client + cgr2RPC *birpc.Client + cgr1RPC *birpc.Client cfg1ConfigDIR string cfg2ConfigDIR string setterConfigDIR string @@ -176,7 +177,7 @@ func testDispatcherCgr1CoreStatus(t *testing.T) { utils.MetaDispatchers: false, }, } - if err := cgr1RPC.Call(utils.CoreSv1Status, &ev, &reply); err != nil { + if err := cgr1RPC.Call(context.Background(), utils.CoreSv1Status, &ev, &reply); err != nil { t.Error(err) } else if reply[utils.NodeID] != "HOST1" { t.Errorf("Expected HOST1, received %v", reply[utils.NodeID]) @@ -193,7 +194,7 @@ func testDispatcherCgr2CoreStatus(t *testing.T) { utils.MetaDispatchers: false, }, } - if err := cgr2RPC.Call(utils.CoreSv1Status, &ev, &reply); err != nil { + if err := cgr2RPC.Call(context.Background(), utils.CoreSv1Status, &ev, &reply); err != nil { t.Error(err) } else if reply[utils.NodeID] != "HOST2" { t.Errorf("Expected HOST2, received %v", reply[utils.NodeID]) @@ -213,11 +214,11 @@ func testDispatcherGetItemBothEnginesFirstAttempt(t *testing.T) { }, } var reply any - if err := cgr2RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr2RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -233,11 +234,11 @@ func testDispatcherGetItemBothEnginesFirstAttempt(t *testing.T) { ItemID: "cgrates.org:DSP1", }, } - if err := cgr2RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr2RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -253,11 +254,11 @@ func testDispatcherGetItemBothEnginesFirstAttempt(t *testing.T) { ItemID: "cgrates.org:DSP1", }, } - if err := cgr2RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr2RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -307,7 +308,7 @@ func testDispatcherSetterSetDispatcherProfile(t *testing.T) { utils.MetaDispatchers: false, }, } - if err := setterRPC.Call(utils.APIerSv1SetDispatcherHost, setDispatcherHost, &replyStr); err != nil { + if err := setterRPC.Call(context.Background(), utils.APIerSv1SetDispatcherHost, setDispatcherHost, &replyStr); err != nil { t.Error("Unexpected error when calling APIerSv1.SetDispatcherHost: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -330,7 +331,7 @@ func testDispatcherSetterSetDispatcherProfile(t *testing.T) { utils.MetaDispatchers: false, }, } - if err := setterRPC.Call(utils.APIerSv1SetDispatcherHost, setDispatcherHost, &replyStr); err != nil { + if err := setterRPC.Call(context.Background(), utils.APIerSv1SetDispatcherHost, setDispatcherHost, &replyStr); err != nil { t.Error("Unexpected error when calling APIerSv1.SetDispatcherHost: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -359,7 +360,7 @@ func testDispatcherSetterSetDispatcherProfile(t *testing.T) { utils.MetaDispatchers: false, }, } - if err := setterRPC.Call(utils.APIerSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil { + if err := setterRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil { t.Error("Unexpected error when calling APIerSv1.SetDispatcherProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -375,7 +376,7 @@ func testDispatcherCgr2CoreStatusWithRouteID(t *testing.T) { }, } // even if HOST1 is prio, this engine was not staretd yet, so HOST2 matched - if err := cgr2RPC.Call(utils.CoreSv1Status, &ev, &reply); err != nil { + if err := cgr2RPC.Call(context.Background(), utils.CoreSv1Status, &ev, &reply); err != nil { t.Error(err) } else if reply[utils.NodeID] != "HOST2" { t.Errorf("Expected HOST2, received %v", reply[utils.NodeID]) @@ -391,7 +392,7 @@ func testDispatcherCgr1CoreStatusWithRouteIDSecondAttempt(t *testing.T) { }, } // same HOST2 will be matched, due to routeID - if err := cgr1RPC.Call(utils.CoreSv1Status, &ev, &reply); err != nil { + if err := cgr1RPC.Call(context.Background(), utils.CoreSv1Status, &ev, &reply); err != nil { t.Error(err) } else if reply[utils.NodeID] != "HOST2" { t.Errorf("Expected HOST2, received %v", reply[utils.NodeID]) @@ -411,7 +412,7 @@ func testDispatcherCgr2GetItemHOST2(t *testing.T) { }, } var reply any - if err := cgr2RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr2RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err != nil { t.Error(err) } else { @@ -436,7 +437,7 @@ func testDispatcherCgr2GetItemHOST2(t *testing.T) { ItemID: "cgrates.org:DSP1", }, } - if err := cgr2RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr2RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err != nil { t.Error(err) } else { @@ -483,7 +484,7 @@ func testDispatcherCgr2GetItemHOST2(t *testing.T) { }, } // reply here is an interface type(singleResultDispatcher), it exists - if err := cgr2RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr2RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err != nil { t.Error(err) } @@ -491,7 +492,7 @@ func testDispatcherCgr2GetItemHOST2(t *testing.T) { func testDisaptcherCacheClear(t *testing.T) { var reply string - if err := cgr1RPC.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ APIOpts: map[string]any{ utils.MetaDispatchers: false, }, @@ -501,7 +502,7 @@ func testDisaptcherCacheClear(t *testing.T) { t.Errorf("Unexpected reply returned") } - if err := cgr2RPC.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := cgr2RPC.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ APIOpts: map[string]any{ utils.MetaDispatchers: false, }, @@ -521,7 +522,7 @@ func testDispatcherCgr1CoreStatusWithRouteIDButHost1(t *testing.T) { }, } // as the cache was cleared, HOST1 will match due to his high prio, and it will be set as *dispatcher_routes as HOST1 - if err := cgr1RPC.Call(utils.CoreSv1Status, &ev, &reply); err != nil { + if err := cgr1RPC.Call(context.Background(), utils.CoreSv1Status, &ev, &reply); err != nil { t.Error(err) } else if reply[utils.NodeID] != "HOST1" { t.Errorf("Expected HOST1, received %v", reply[utils.NodeID]) @@ -541,7 +542,7 @@ func testDispatcherCgr1CheckCacheAfterRouting(t *testing.T) { }, } var reply any - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err != nil { t.Error(err) } else { @@ -566,7 +567,7 @@ func testDispatcherCgr1CheckCacheAfterRouting(t *testing.T) { ItemID: "cgrates.org:DSP1", }, } - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err != nil { t.Error(err) } else { @@ -613,7 +614,7 @@ func testDispatcherCgr1CheckCacheAfterRouting(t *testing.T) { }, } // reply here is an interface type(singleResultDispatcher), it exists - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err != nil { t.Error(err) } @@ -642,7 +643,7 @@ func testDispatcherSetterSetDispatcherProfileOverwrite(t *testing.T) { utils.MetaDispatchers: false, }, } - if err := setterRPC.Call(utils.APIerSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil { + if err := setterRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil { t.Error("Unexpected error when calling APIerSv1.SetDispatcherProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -664,7 +665,7 @@ func testDispatcherCheckCacheAfterSetDispatcherDSP1(t *testing.T) { }, } var reply any // Should receive NOT_FOUND, as CallCache that was called in API will remove the DispatcherRoute - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Unexpected error returned: %v", err) } @@ -682,7 +683,7 @@ func testDispatcherCheckCacheAfterSetDispatcherDSP1(t *testing.T) { }, } // as the DSP1 profile was overwritten, only HOST2 in profile will be contained - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err != nil { t.Error(err) } else { @@ -723,7 +724,7 @@ func testDispatcherCheckCacheAfterSetDispatcherDSP1(t *testing.T) { }, } // DispatcherInstance should also be removed, so it will be NOT_FOUND - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Unexpected error returned: %v and reply: %v", err, reply) } @@ -754,7 +755,7 @@ func testDispatcherSetterSetAnotherProifle(t *testing.T) { utils.MetaDispatchers: false, }, } - if err := setterRPC.Call(utils.APIerSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil { + if err := setterRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, setDispatcherProfile, &replyStr); err != nil { t.Error("Unexpected error when calling APIerSv1.SetDispatcherProfile: ", err) } else if replyStr != utils.OK { t.Error("Unexpected reply returned", replyStr) @@ -776,7 +777,7 @@ func testDispatcherCheckCacheAfterSetDispatcherDSP2(t *testing.T) { } var reply any // NOT_FOUND - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Unexpected error returned: %v", err) } @@ -793,7 +794,7 @@ func testDispatcherCheckCacheAfterSetDispatcherDSP2(t *testing.T) { }, } // NOT_FOUND - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Unexpected error returned: %v", err) } @@ -810,7 +811,7 @@ func testDispatcherCheckCacheAfterSetDispatcherDSP2(t *testing.T) { }, } // NOT_FOUND - if err := cgr1RPC.Call(utils.CacheSv1GetItem, argsCache, + if err := cgr1RPC.Call(context.Background(), utils.CacheSv1GetItem, argsCache, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Unexpected error returned: %v", err) } diff --git a/general_tests/doubleremove_it_test.go b/general_tests/doubleremove_it_test.go index 927d8931f..cdaf3ec8f 100644 --- a/general_tests/doubleremove_it_test.go +++ b/general_tests/doubleremove_it_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -105,7 +106,7 @@ func testdoubleRemoveRpcConn(t *testing.T) { func testdoubleRemoveStatQueueProfile(t *testing.T) { // check var reply *engine.StatQueueProfile - if err := sesRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := sesRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: doubleRemoveTenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -137,13 +138,13 @@ func testdoubleRemoveStatQueueProfile(t *testing.T) { }, } var result string - if err := sesRPC.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { + if err := sesRPC.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //check - if err := sesRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := sesRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: doubleRemoveTenant, ID: "TEST_PROFILE1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) { @@ -151,24 +152,24 @@ func testdoubleRemoveStatQueueProfile(t *testing.T) { } //remove - if err := sesRPC.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := sesRPC.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: doubleRemoveTenant, ID: "TEST_PROFILE1"}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := sesRPC.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := sesRPC.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: doubleRemoveTenant, ID: "TEST_PROFILE1"}, &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := sesRPC.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := sesRPC.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, &utils.TenantID{Tenant: doubleRemoveTenant, ID: "TEST_PROFILE1"}, &result); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } // check - if err := sesRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := sesRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: doubleRemoveTenant, ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -179,7 +180,7 @@ func testdoubleRemoveActions(t *testing.T) { // check var reply1 []*utils.TPAction if doubleRemoveDIR != "tutinternal" { // on internal do not get so we do not cache this action with nil in cache - if err := sesRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { + if err := sesRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { t.Error(err) } } @@ -195,13 +196,13 @@ func testdoubleRemoveActions(t *testing.T) { Weight: 20.0}}, } var reply string - if err := sesRPC.Call(utils.APIerSv1SetActions, &attrs1, &reply); err != nil { + if err := sesRPC.Call(context.Background(), utils.APIerSv1SetActions, &attrs1, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply returned: %s", reply) } // set it again (expect EXISTS) - if err := sesRPC.Call(utils.APIerSv1SetActions, &attrs1, &reply); err == nil || err.Error() != "EXISTS" { + if err := sesRPC.Call(context.Background(), utils.APIerSv1SetActions, &attrs1, &reply); err == nil || err.Error() != "EXISTS" { t.Error(err) } // check @@ -216,26 +217,26 @@ func testdoubleRemoveActions(t *testing.T) { ExpiryTime: utils.MetaUnlimited, Weight: 20.0, }} - if err := sesRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil { + if err := sesRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err != nil { t.Error("Got error on APIerSv1.GetActions: ", err.Error()) } else if !reflect.DeepEqual(eOut, reply1) { t.Errorf("Expected: %v, received: %v", utils.ToJSON(eOut), utils.ToJSON(reply1)) } // remove - if err := sesRPC.Call(utils.APIerSv1RemoveActions, &v1.AttrRemoveActions{ + if err := sesRPC.Call(context.Background(), utils.APIerSv1RemoveActions, &v1.AttrRemoveActions{ ActionIDs: []string{"ACTS_1"}}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } // remove it again (expect ErrNotFound) - // if err := sesRPC.Call(utils.APIerSv1RemoveActions, &v1.AttrRemoveActions{ + // if err := sesRPC.Call(context.Background(),utils.APIerSv1RemoveActions, &v1.AttrRemoveActions{ // ActionIDs: []string{"ACTS_1"}}, &reply); err == nil || // err.Error() != utils.ErrNotFound.Error() { // t.Error(err) // } // check again - if err := sesRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { + if err := sesRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply1); err == nil || err.Error() != "SERVER_ERROR: NOT_FOUND" { t.Error(err) } } @@ -243,7 +244,7 @@ func testdoubleRemoveActions(t *testing.T) { func testdoubleRemoveActionPlan(t *testing.T) { //set action var reply string - if err := sesRPC.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{ + if err := sesRPC.Call(context.Background(), utils.APIerSv2SetActions, &utils.AttrSetActions{ ActionsId: "ACTS_2", Actions: []*utils.TPAction{{Identifier: utils.MetaLog}}, }, &reply); err != nil { @@ -262,7 +263,7 @@ func testdoubleRemoveActionPlan(t *testing.T) { BalanceDisabled: "false", Weight: 0}} - if err := sesRPC.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_2"), &reply1); err != nil { + if err := sesRPC.Call(context.Background(), utils.APIerSv1GetActions, utils.StringPointer("ACTS_2"), &reply1); err != nil { t.Error("Got error on APIerSv1.GetActions: ", err.Error()) } else if !reflect.DeepEqual(eOut, reply1) { t.Errorf("Expected: %v, received: %v", utils.ToJSON(eOut), utils.ToJSON(reply1)) @@ -273,7 +274,7 @@ func testdoubleRemoveActionPlan(t *testing.T) { should return ErrNotFound, right now it returns nil and an empty slice, needs to be reviewed - if err := sesRPC.Call(utils.APIerSv1GetActionPlan, + if err := sesRPC.Call(context.Background(),utils.APIerSv1GetActionPlan, v1.AttrGetActionPlan{ID: utils.EmptyString}, &aps); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error: %+v, rcv: %+v", err, utils.ToJSON(aps)) } @@ -288,17 +289,17 @@ func testdoubleRemoveActionPlan(t *testing.T) { Weight: 20.0}, }, } - if err := sesRPC.Call(utils.APIerSv1SetActionPlan, &atms1, &reply); err != nil { + if err := sesRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &atms1, &reply); err != nil { t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error()) } else if reply != utils.OK { t.Errorf("Unexpected reply returned: %s", reply) } // set it again (expect EXISTS) - if err := sesRPC.Call(utils.APIerSv1SetActionPlan, &atms1, &reply); err == nil || err.Error() != "EXISTS" { + if err := sesRPC.Call(context.Background(), utils.APIerSv1SetActionPlan, &atms1, &reply); err == nil || err.Error() != "EXISTS" { t.Error(err) } // check - if err := sesRPC.Call(utils.APIerSv1GetActionPlan, + if err := sesRPC.Call(context.Background(), utils.APIerSv1GetActionPlan, &v1.AttrGetActionPlan{ID: "ATMS_1"}, &aps); err != nil { t.Error(err) } else if len(aps) != 1 { @@ -312,7 +313,7 @@ func testdoubleRemoveActionPlan(t *testing.T) { } // remove - if err := sesRPC.Call(utils.APIerSv1RemoveActionPlan, &v1.AttrGetActionPlan{ + if err := sesRPC.Call(context.Background(), utils.APIerSv1RemoveActionPlan, &v1.AttrGetActionPlan{ ID: "ATMS_1"}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -323,7 +324,7 @@ func testdoubleRemoveActionPlan(t *testing.T) { this should return ErrNotFound, right now it returns nil and an empty slice, needs to be reviewed. - if err := sesRPC.Call(utils.APIerSv1GetActionPlan, + if err := sesRPC.Call(context.Background(),utils.APIerSv1GetActionPlan, v1.AttrGetActionPlan{ID: utils.EmptyString}, &aps); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error: %+v, rcv: %+v", err, utils.ToJSON(aps)) } diff --git a/general_tests/export_it_test.go b/general_tests/export_it_test.go index e9f94d7ae..fff70511f 100644 --- a/general_tests/export_it_test.go +++ b/general_tests/export_it_test.go @@ -21,7 +21,6 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "os" "path" "reflect" @@ -29,6 +28,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ var ( expCfgDir string expCfgPath string expCfg *config.CGRConfig - expRpc *rpc.Client + expRpc *birpc.Client sTestsExp = []func(t *testing.T){ testExpLoadConfig, @@ -120,7 +121,7 @@ func testExpRPCConn(t *testing.T) { func testExpLoadTPFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := expRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := expRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(reply) @@ -132,7 +133,7 @@ func testExpExportToFolder(t *testing.T) { arg := &utils.ArgExportToFolder{ Path: "/tmp/tp/", } - if err := expRpc.Call(utils.APIerSv1ExportToFolder, arg, &reply); err != nil { + if err := expRpc.Call(context.Background(), utils.APIerSv1ExportToFolder, arg, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(reply) @@ -142,7 +143,7 @@ func testExpExportToFolder(t *testing.T) { func testExpLoadTPFromExported(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: "/tmp/tp/"} - if err := expRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := expRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(reply) @@ -167,7 +168,7 @@ func testExpVerifyAttributes(t *testing.T) { Weight: 10.0, } var reply *engine.AttributeProfile - if err := expRpc.Call(utils.APIerSv1GetAttributeProfile, + if err := expRpc.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_ACNT_1001"}}, &reply); err != nil { t.Fatal(err) @@ -199,7 +200,7 @@ func testExpVerifyFilters(t *testing.T) { }, } var reply *engine.Filter - if err := expRpc.Call(utils.APIerSv1GetFilter, + if err := expRpc.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ACCOUNT_1001"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(exp, reply) { @@ -227,7 +228,7 @@ func testExpVerifyThresholds(t *testing.T) { }, } var reply *engine.ThresholdProfile - if err := expRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := expRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { @@ -251,7 +252,7 @@ func testExpVerifyResources(t *testing.T) { rPrf.ThresholdIDs = nil } var reply *engine.ResourceProfile - if err := expRpc.Call(utils.APIerSv1GetResourceProfile, + if err := expRpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "RES_ACNT_1001"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, rPrf) { @@ -287,7 +288,7 @@ func testExpVerifyStats(t *testing.T) { ThresholdIDs: []string{utils.MetaNone}, } var reply *engine.StatQueueProfile - if err := expRpc.Call(utils.APIerSv1GetStatQueueProfile, + if err := expRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_1"}, &reply); err != nil { t.Error(err) } @@ -348,7 +349,7 @@ func testExpVerifyRoutes(t *testing.T) { }, Weight: 10, } - if err := expRpc.Call(utils.APIerSv1GetRouteProfile, + if err := expRpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}, &reply); err != nil { t.Fatal(err) } diff --git a/general_tests/filtered_replication_it_test.go b/general_tests/filtered_replication_it_test.go index f8e1d577d..fcdecb83f 100644 --- a/general_tests/filtered_replication_it_test.go +++ b/general_tests/filtered_replication_it_test.go @@ -27,12 +27,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) var ( @@ -40,15 +41,15 @@ var ( fltrRplInternalCfgPath string fltrRplInternalCfg *config.CGRConfig - fltrRplInternalRPC rpcclient.ClientConnector + fltrRplInternalRPC birpc.ClientConnector fltrRplEngine1CfgPath string fltrRplEngine1Cfg *config.CGRConfig - fltrRplEngine1RPC rpcclient.ClientConnector + fltrRplEngine1RPC birpc.ClientConnector fltrRplEngine2CfgPath string fltrRplEngine2Cfg *config.CGRConfig - fltrRplEngine2RPC rpcclient.ClientConnector + fltrRplEngine2RPC birpc.ClientConnector sTestsFltrRpl = []func(t *testing.T){ testFltrRplInitCfg, @@ -175,21 +176,21 @@ func testFltrRplAttributeProfile(t *testing.T) { var replyPrfl *engine.AttributeProfile var rplyIDs []string // empty - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: attrID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -199,16 +200,16 @@ func testFltrRplAttributeProfile(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetAttributeProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: attrID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -218,12 +219,12 @@ func testFltrRplAttributeProfile(t *testing.T) { } replyPrfl = nil attrPrf.Weight = 15 - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: attrID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -234,7 +235,7 @@ func testFltrRplAttributeProfile(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetAttributeProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: attrID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -243,22 +244,22 @@ func testFltrRplAttributeProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(attrPrf.AttributeProfile), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1RemoveAttributeProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1RemoveAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: attrID}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -282,21 +283,21 @@ func testFltrRplFilters(t *testing.T) { var replyPrfl *engine.Filter var rplyIDs []string // empty - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetFilter, fltr, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetFilter, fltr, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetFilter, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: fltrID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -306,16 +307,16 @@ func testFltrRplFilters(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetFilter, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: fltrID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -325,12 +326,12 @@ func testFltrRplFilters(t *testing.T) { } replyPrfl = nil fltr.Rules[0].Type = utils.MetaPrefix - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetFilter, fltr, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetFilter, fltr, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetFilter, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: fltrID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -341,7 +342,7 @@ func testFltrRplFilters(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetFilter, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetFilter, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: fltrID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -350,22 +351,22 @@ func testFltrRplFilters(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(fltr.Filter), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1RemoveFilter, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1RemoveFilter, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: fltrID}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -398,30 +399,30 @@ func testFltrRplThresholdProfile(t *testing.T) { }, } // empty - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetThresholdProfile, thPrfl, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetThresholdProfile, thPrfl, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: thID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -430,25 +431,25 @@ func testFltrRplThresholdProfile(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetThresholdProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: thID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -456,7 +457,7 @@ func testFltrRplThresholdProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(thPrfl.ThresholdProfile), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine1RPC.Call(utils.ThresholdSv1GetThreshold, argsTh, &replyTh); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, argsTh, &replyTh); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(th, replyTh) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(th), utils.ToJSON(replyTh)) @@ -464,12 +465,12 @@ func testFltrRplThresholdProfile(t *testing.T) { replyPrfl = nil thPrfl.Weight = 10 - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetThresholdProfile, thPrfl, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetThresholdProfile, thPrfl, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetThresholdProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: thID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -479,7 +480,7 @@ func testFltrRplThresholdProfile(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetThresholdProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetThresholdProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: thID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -487,7 +488,7 @@ func testFltrRplThresholdProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(thPrfl.ThresholdProfile), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -501,13 +502,13 @@ func testFltrRplThresholdProfile(t *testing.T) { } var thIDs []string //Testing ProcessEvent on set thresholdprofile using apier - if err := fltrRplInternalRPC.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err != nil { t.Fatal(err) } else if expected := []string{thID}; !reflect.DeepEqual(expected, thIDs) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(expected), utils.ToJSON(thIDs)) } - if err := fltrRplEngine1RPC.Call(utils.ThresholdSv1GetThreshold, argsTh, &replyTh); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, argsTh, &replyTh); err != nil { t.Fatal(err) } th.Hits = 1 @@ -516,26 +517,26 @@ func testFltrRplThresholdProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(th), utils.ToJSON(replyTh)) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1RemoveThresholdProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: thID}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetThreshold, argsTh, &replyTh); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -580,30 +581,30 @@ func testFltrRplStatQueueProfile(t *testing.T) { }, } // empty - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetStatQueueProfile, stPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, stPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: stID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -612,25 +613,25 @@ func testFltrRplStatQueueProfile(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: stID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -643,7 +644,7 @@ func testFltrRplStatQueueProfile(t *testing.T) { sq.SQMetrics = map[string]engine.StatMetric{ utils.MetaACD: s, } - if err := fltrRplEngine1RPC.Call(utils.StatSv1GetStatQueue, argsSq, &replySq); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.StatSv1GetStatQueue, argsSq, &replySq); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(sq, replySq) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(sq), utils.ToJSON(replySq)) @@ -651,12 +652,12 @@ func testFltrRplStatQueueProfile(t *testing.T) { replyPrfl = nil stPrf.Weight = 15 - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetStatQueueProfile, stPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, stPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetStatQueueProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: stID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -666,7 +667,7 @@ func testFltrRplStatQueueProfile(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetStatQueueProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueueProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: stID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -674,7 +675,7 @@ func testFltrRplStatQueueProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(stPrf.StatQueueProfile), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -689,13 +690,13 @@ func testFltrRplStatQueueProfile(t *testing.T) { } var sqIDs []string //Testing ProcessEvent on set thresholdprofile using apier - if err := fltrRplInternalRPC.Call(utils.StatSv1ProcessEvent, sEv, &sqIDs); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.StatSv1ProcessEvent, sEv, &sqIDs); err != nil { t.Fatal(err) } else if expected := []string{stID}; !reflect.DeepEqual(expected, sqIDs) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(expected), utils.ToJSON(sqIDs)) } - if err := fltrRplEngine1RPC.Call(utils.StatSv1GetStatQueue, argsSq, &replySq); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.StatSv1GetStatQueue, argsSq, &replySq); err != nil { t.Fatal(err) } sq.SQItems = []engine.SQItem{{ @@ -707,26 +708,26 @@ func testFltrRplStatQueueProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(sq), utils.ToJSON(replySq)) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1RemoveStatQueueProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1RemoveStatQueueProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: stID}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetStatQueue, argsSq, &replySq); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -764,29 +765,29 @@ func testFltrRplResourceProfile(t *testing.T) { }, } // empty - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetResourceProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: resID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -795,25 +796,25 @@ func testFltrRplResourceProfile(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetResourceProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: resID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -821,7 +822,7 @@ func testFltrRplResourceProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(resPrf.ResourceProfile), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine1RPC.Call(utils.ResourceSv1GetResource, argsRs, &replyRs); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ResourceSv1GetResource, argsRs, &replyRs); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(rs, replyRs) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(rs), utils.ToJSON(replyRs)) @@ -829,12 +830,12 @@ func testFltrRplResourceProfile(t *testing.T) { replyPrfl = nil resPrf.Weight = 15 - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetResourceProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: resID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -844,7 +845,7 @@ func testFltrRplResourceProfile(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetResourceProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetResourceProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: resID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -852,7 +853,7 @@ func testFltrRplResourceProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(resPrf.ResourceProfile), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -870,13 +871,13 @@ func testFltrRplResourceProfile(t *testing.T) { } var rsIDs string //Testing ProcessEvent on set thresholdprofile using apier - if err := fltrRplInternalRPC.Call(utils.ResourceSv1AllocateResources, rEv, &rsIDs); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.ResourceSv1AllocateResources, rEv, &rsIDs); err != nil { t.Fatal(err) } else if expected := resPrf.AllocationMessage; !reflect.DeepEqual(expected, rsIDs) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(expected), utils.ToJSON(rsIDs)) } - if err := fltrRplEngine1RPC.Call(utils.ResourceSv1GetResource, argsRs, &replyRs); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ResourceSv1GetResource, argsRs, &replyRs); err != nil { t.Fatal(err) } usageID := utils.IfaceAsString(rEv.APIOpts[utils.OptsResourcesUsageID]) @@ -893,26 +894,26 @@ func testFltrRplResourceProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(rs), utils.ToJSON(replyRs)) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1RemoveResourceProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1RemoveResourceProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: resID}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetResourceProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetResource, argsRs, &replyRs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -945,21 +946,21 @@ func testFltrRplRouteProfile(t *testing.T) { var replyPrfl *engine.RouteProfile var rplyIDs []string // empty - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetRouteProfile, rpPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetRouteProfile, rpPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetRouteProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rpID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -969,16 +970,16 @@ func testFltrRplRouteProfile(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetRouteProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rpID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -988,12 +989,12 @@ func testFltrRplRouteProfile(t *testing.T) { } replyPrfl = nil rpPrf.Weight = 15 - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetRouteProfile, rpPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetRouteProfile, rpPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetRouteProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rpID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1004,7 +1005,7 @@ func testFltrRplRouteProfile(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetRouteProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetRouteProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: rpID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1013,22 +1014,22 @@ func testFltrRplRouteProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(rpPrf.RouteProfile), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1RemoveRouteProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1RemoveRouteProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: rpID}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetRouteProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -1050,21 +1051,21 @@ func testFltrRplChargerProfile(t *testing.T) { var replyPrfl *engine.ChargerProfile var rplyIDs []string // empty - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetChargerProfile, chPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetChargerProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: chID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1073,16 +1074,16 @@ func testFltrRplChargerProfile(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetChargerProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: chID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1091,12 +1092,12 @@ func testFltrRplChargerProfile(t *testing.T) { } replyPrfl = nil chPrf.Weight = 15 - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetChargerProfile, chPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetChargerProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: chID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1106,7 +1107,7 @@ func testFltrRplChargerProfile(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetChargerProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetChargerProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: chID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1114,22 +1115,22 @@ func testFltrRplChargerProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(chPrf.ChargerProfile), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1RemoveChargerProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1RemoveChargerProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: chID}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetChargerProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -1150,21 +1151,21 @@ func testFltrRplDispatcherProfile(t *testing.T) { var replyPrfl *engine.DispatcherProfile var rplyIDs []string // empty - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetDispatcherProfile, dspPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dspPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: dspID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1173,16 +1174,16 @@ func testFltrRplDispatcherProfile(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: dspID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1191,12 +1192,12 @@ func testFltrRplDispatcherProfile(t *testing.T) { } replyPrfl = nil dspPrf.Weight = 15 - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetDispatcherProfile, dspPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dspPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: dspID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1206,7 +1207,7 @@ func testFltrRplDispatcherProfile(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetDispatcherProfile, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: dspID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1214,22 +1215,22 @@ func testFltrRplDispatcherProfile(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(dspPrf.DispatcherProfile), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1RemoveDispatcherProfile, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: dspID}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -1250,21 +1251,21 @@ func testFltrRplDispatcherHost(t *testing.T) { var replyPrfl *engine.DispatcherHost var rplyIDs []string // empty - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetDispatcherHost, dspPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetDispatcherHost, dspPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: dspID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1273,16 +1274,16 @@ func testFltrRplDispatcherHost(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetDispatcherHost, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: dspID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1291,12 +1292,12 @@ func testFltrRplDispatcherHost(t *testing.T) { } replyPrfl = nil dspPrf.Address = "127.0.0.1:2012" - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetDispatcherHost, dspPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetDispatcherHost, dspPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetDispatcherHost, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetDispatcherHost, &utils.TenantID{Tenant: "cgrates.org", ID: dspID}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1306,7 +1307,7 @@ func testFltrRplDispatcherHost(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetDispatcherHost, + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetDispatcherHost, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: dspID}}, &replyPrfl); err != nil { t.Fatal(err) } @@ -1314,22 +1315,22 @@ func testFltrRplDispatcherHost(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(dspPrf.DispatcherHost), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1RemoveDispatcherHost, + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1RemoveDispatcherHost, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: dspID}}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetDispatcherHostIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } @@ -1347,23 +1348,23 @@ func testFltrRplAccount(t *testing.T) { var replyPrfl *engine.Account var rplyCount int // empty - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetAccountsCount, &utils.PaginatorWithTenant{}, &rplyCount); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetAccountsCount, &utils.PaginatorWithTenant{}, &rplyCount); err != nil { t.Fatal(err) } else if rplyCount != 0 { t.Fatal("Expected no accounts") } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetAccountsCount, &utils.PaginatorWithTenant{}, &rplyCount); err != nil { + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetAccountsCount, &utils.PaginatorWithTenant{}, &rplyCount); err != nil { t.Fatal(err) } else if rplyCount != 0 { t.Fatal("Expected no accounts") } - if err := fltrRplInternalRPC.Call(utils.APIerSv2SetAccount, attrPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv2SetAccount, attrPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv2GetAccount, attrAC, &replyPrfl); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAC, &replyPrfl); err != nil { t.Fatal(err) } replyPrfl.BalanceMap = nil @@ -1376,18 +1377,18 @@ func testFltrRplAccount(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetAccountsCount, &utils.PaginatorWithTenant{}, &rplyCount); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetAccountsCount, &utils.PaginatorWithTenant{}, &rplyCount); err != nil { t.Fatal(err) } else if rplyCount != 0 { t.Fatal("Expected no accounts") } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetAccountsCount, &utils.PaginatorWithTenant{}, &rplyCount); err != nil { + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetAccountsCount, &utils.PaginatorWithTenant{}, &rplyCount); err != nil { t.Fatal(err) } else if rplyCount != 0 { t.Fatal("Expected no accounts") } - if err := fltrRplEngine1RPC.Call(utils.APIerSv2GetAccount, attrAC, &replyPrfl); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAC, &replyPrfl); err != nil { t.Fatal(err) } replyPrfl.BalanceMap = nil @@ -1401,12 +1402,12 @@ func testFltrRplAccount(t *testing.T) { replyPrfl = nil attrPrf.ExtraOptions[utils.Disabled] = false expPrf.Disabled = false - if err := fltrRplInternalRPC.Call(utils.APIerSv2SetAccount, attrPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv2SetAccount, attrPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv2GetAccount, attrAC, &replyPrfl); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAC, &replyPrfl); err != nil { t.Fatal(err) } replyPrfl.BalanceMap = nil @@ -1420,7 +1421,7 @@ func testFltrRplAccount(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetAccount, &utils.StringWithAPIOpts{ + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetAccount, &utils.StringWithAPIOpts{ Arg: expPrf.ID, }, &replyPrfl); err != nil { t.Fatal(err) @@ -1434,7 +1435,7 @@ func testFltrRplAccount(t *testing.T) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(expPrf), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetAccountsCount, &utils.PaginatorWithTenant{}, &rplyCount); err != nil { + if err := fltrRplEngine2RPC.Call(context.Background(), utils.APIerSv1GetAccountsCount, &utils.PaginatorWithTenant{}, &rplyCount); err != nil { t.Fatal(err) } else if rplyCount != 0 { t.Fatal("Expected no accounts") @@ -1461,29 +1462,29 @@ func testFltrRplDestination(t *testing.T) { var rplyIDs *engine.Destination var rplyIDs2 []string // empty - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetDestination, args, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, args, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetDestination, args, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, args, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetDestination, dstPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetDestination, dstPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetDestination, dstID, &replyPrfl); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetDestination, dstID, &replyPrfl); err != nil { t.Fatal(err) } if !reflect.DeepEqual(expPrf, replyPrfl) { @@ -1491,30 +1492,30 @@ func testFltrRplDestination(t *testing.T) { } replyPrfl = nil - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetDestination, args, &rplyIDs); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, args, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err == nil || + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetDestination, args, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, args, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetDestination, dstID, &replyPrfl); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetDestination, dstID, &replyPrfl); err != nil { t.Fatal(err) } if !reflect.DeepEqual(expPrf, replyPrfl) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(expPrf), utils.ToJSON(replyPrfl)) } - if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetReverseDestination, "dan", &rplyIDs2); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.APIerSv1GetReverseDestination, "dan", &rplyIDs2); err != nil { t.Fatal(err) } if !reflect.DeepEqual([]string{dstID}, rplyIDs2) { @@ -1525,12 +1526,12 @@ func testFltrRplDestination(t *testing.T) { dstPrf.Prefixes = []string{"dan2"} expPrf.Prefixes = []string{"dan2"} args2.Arg = "dan2" - if err := fltrRplInternalRPC.Call(utils.APIerSv1SetDestination, dstPrf, &result); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1SetDestination, dstPrf, &result); err != nil { t.Fatal(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRplInternalRPC.Call(utils.APIerSv1GetDestination, dstID, &replyPrfl); err != nil { + if err := fltrRplInternalRPC.Call(context.Background(), utils.APIerSv1GetDestination, dstID, &replyPrfl); err != nil { t.Fatal(err) } if !reflect.DeepEqual(expPrf, replyPrfl) { @@ -1539,26 +1540,26 @@ func testFltrRplDestination(t *testing.T) { replyPrfl = nil // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetDestination, args, &replyPrfl); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, args, &replyPrfl); err != nil { t.Fatal(err) } if !reflect.DeepEqual(expPrf, replyPrfl) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON(expPrf), utils.ToJSON(replyPrfl)) } // use replicator to see if the attribute was changed in the DB - if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err != nil { + if err := fltrRplEngine1RPC.Call(context.Background(), utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err != nil { t.Fatal(err) } if !reflect.DeepEqual([]string{dstID}, rplyIDs2) { t.Errorf("Expecting : %s, received: %s", utils.ToJSON([]string{dstID}), utils.ToJSON(rplyIDs2)) } - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetDestination, args, &rplyIDs); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetDestination, args, &rplyIDs); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Unexpected error: %v", err) } rplyIDs2 = nil - if err := fltrRplEngine2RPC.Call(utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err == nil || + if err := fltrRplEngine2RPC.Call(context.Background(), utils.ReplicatorSv1GetReverseDestination, args2, &rplyIDs2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Log(rplyIDs2) t.Fatalf("Unexpected error: %v", err) diff --git a/general_tests/filters_it_test.go b/general_tests/filters_it_test.go index 6f0ebad55..bd962c7d7 100644 --- a/general_tests/filters_it_test.go +++ b/general_tests/filters_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -38,7 +39,7 @@ import ( var ( fltrCfgPath string fltrCfg *config.CGRConfig - fltrRpc *rpc.Client + fltrRpc *birpc.Client fltrConfDIR string //run tests for specific configuration fltrDelay int fltrInternalRestart bool // to reset db on internal restart engine @@ -134,7 +135,7 @@ func testV1FltrRpcConn(t *testing.T) { func testV1FltrLoadTarrifPlans(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := fltrRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -155,7 +156,7 @@ func testV1FltrAddStats(t *testing.T) { utils.Cost: 10.0, }, } - if err := fltrRpc.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { + if err := fltrRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -172,7 +173,7 @@ func testV1FltrAddStats(t *testing.T) { utils.Cost: 10.5, }, } - if err := fltrRpc.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { + if err := fltrRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -189,7 +190,7 @@ func testV1FltrAddStats(t *testing.T) { utils.Cost: 12.5, }, } - if err := fltrRpc.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { + if err := fltrRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -206,7 +207,7 @@ func testV1FltrAddStats(t *testing.T) { utils.Cost: 17.5, }, } - if err := fltrRpc.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { + if err := fltrRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -223,7 +224,7 @@ func testV1FltrAddStats(t *testing.T) { utils.Cost: 12.5, }, } - if err := fltrRpc.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { + if err := fltrRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -241,7 +242,7 @@ func testV1FltrAddStats(t *testing.T) { utils.PDD: 12 * time.Second, }, } - if err := fltrRpc.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { + if err := fltrRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -259,7 +260,7 @@ func testV1FltrAddStats(t *testing.T) { utils.PDD: 15 * time.Second, }, } - if err := fltrRpc.Call(utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { + if err := fltrRpc.Call(context.Background(), utils.StatSv1ProcessEvent, &ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -284,7 +285,7 @@ func testV1FltrPopulateThreshold(t *testing.T) { } var result string - if err := fltrRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -294,7 +295,7 @@ func testV1FltrPopulateThreshold(t *testing.T) { attrsAA := &utils.AttrSetActions{ActionsId: "LOG", Actions: []*utils.TPAction{ {Identifier: utils.MetaLog}, }} - if err := fltrRpc.Call(utils.APIerSv2SetActions, attrsAA, &result); err != nil && err.Error() != utils.ErrExists.Error() { + if err := fltrRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &result); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if result != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", result) @@ -317,13 +318,13 @@ func testV1FltrPopulateThreshold(t *testing.T) { Async: true, }, } - if err := fltrRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var rcvTh *engine.ThresholdProfile - if err := fltrRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := fltrRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tPrfl.Tenant, ID: tPrfl.ID}, &rcvTh); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, rcvTh) { @@ -341,7 +342,7 @@ func testV1FltrGetThresholdForEvent(t *testing.T) { } var ids []string eIDs := []string{"TH_Stats1"} - if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err != nil { + if err := fltrRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -366,7 +367,7 @@ func testV1FltrGetThresholdForEvent2(t *testing.T) { } var result string - if err := fltrRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -388,7 +389,7 @@ func testV1FltrGetThresholdForEvent2(t *testing.T) { ActionIDs: []string{"LOG"}, }, } - if err := fltrRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -401,7 +402,7 @@ func testV1FltrGetThresholdForEvent2(t *testing.T) { utils.AccountField: "1010"}, } var ids []string - if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err == nil || + if err := fltrRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -421,14 +422,14 @@ func testV1FltrPopulateResources(t *testing.T) { } var result string - if err := fltrRpc.Call(utils.APIerSv1SetResourceProfile, &engine.ResourceProfileWithAPIOpts{ResourceProfile: rlsConfig}, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, &engine.ResourceProfileWithAPIOpts{ResourceProfile: rlsConfig}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.ResourceProfile - if err := fltrRpc.Call(utils.APIerSv1GetResourceProfile, + if err := fltrRpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, rlsConfig) { @@ -448,7 +449,7 @@ func testV1FltrPopulateResources(t *testing.T) { utils.OptsResourcesUnits: 3, }, } - if err := fltrRpc.Call(utils.ResourceSv1AllocateResources, + if err := fltrRpc.Call(context.Background(), utils.ResourceSv1AllocateResources, argsRU, &result); err != nil { t.Error(err) } @@ -469,7 +470,7 @@ func testV1FltrPopulateResources(t *testing.T) { }, } - if err := fltrRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -487,13 +488,13 @@ func testV1FltrPopulateResources(t *testing.T) { Async: true, }, } - if err := fltrRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var rcvTh *engine.ThresholdProfile - if err := fltrRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := fltrRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tPrfl.Tenant, ID: tPrfl.ID}, &rcvTh); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, rcvTh) { @@ -510,7 +511,7 @@ func testV1FltrPopulateResources(t *testing.T) { var ids []string eIDs := []string{"TH_ResTest"} - if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err != nil { + if err := fltrRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, eIDs) { t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) @@ -531,21 +532,21 @@ func testV1FltrPopulateResources(t *testing.T) { }, } - if err := fltrRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //Overwrite the threshold - if err := fltrRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //expect NotFound error because filter doesn't match - if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err == nil || + if err := fltrRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -565,14 +566,14 @@ func testV1FltrPopulateResourcesAvailableUnits(t *testing.T) { } var result string - if err := fltrRpc.Call(utils.APIerSv1SetResourceProfile, &engine.ResourceProfileWithAPIOpts{ResourceProfile: rlsConfig}, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, &engine.ResourceProfileWithAPIOpts{ResourceProfile: rlsConfig}, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.ResourceProfile - if err := fltrRpc.Call(utils.APIerSv1GetResourceProfile, + if err := fltrRpc.Call(context.Background(), utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, rlsConfig) { @@ -592,7 +593,7 @@ func testV1FltrPopulateResourcesAvailableUnits(t *testing.T) { utils.OptsResourcesUnits: 9, }, } - if err := fltrRpc.Call(utils.ResourceSv1AllocateResources, argsRU, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.ResourceSv1AllocateResources, argsRU, &result); err != nil { t.Error(err) } else if result != "Test_Available" { t.Error("Unexpected reply returned", result) @@ -619,7 +620,7 @@ func testV1FltrPopulateResourcesAvailableUnits(t *testing.T) { }, } - if err := fltrRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -634,14 +635,14 @@ func testV1FltrPopulateResourcesAvailableUnits(t *testing.T) { Weight: 50, }, } - if err := fltrRpc.Call(utils.APIerSv1SetStatQueueProfile, statsPrf, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetStatQueueProfile, statsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var replyStats *engine.StatQueueProfile - if err := fltrRpc.Call(utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", + if err := fltrRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "STATS_RES_TEST12"}, &replyStats); err != nil { t.Error(err) } else if !reflect.DeepEqual(statsPrf.StatQueueProfile, replyStats) { @@ -659,7 +660,7 @@ func testV1FltrPopulateResourcesAvailableUnits(t *testing.T) { } var ids []string expectedIDs := []string{"STATS_RES_TEST12", "Stat_1"} - if err := fltrRpc.Call(utils.StatSv1ProcessEvent, statsEv, &ids); err != nil { + if err := fltrRpc.Call(context.Background(), utils.StatSv1ProcessEvent, statsEv, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedIDs, ids) { t.Errorf("Expected %+v, received %+v", expectedIDs, ids) @@ -680,14 +681,14 @@ func testV1FltrPopulateResourcesAvailableUnits(t *testing.T) { }, } - if err := fltrRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } //overwrite the StatQueueProfile - if err := fltrRpc.Call(utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", + if err := fltrRpc.Call(context.Background(), utils.APIerSv1GetStatQueueProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "STATS_RES_TEST12"}, &replyStats); err != nil { t.Error(err) } else if !reflect.DeepEqual(statsPrf.StatQueueProfile, replyStats) { @@ -696,7 +697,7 @@ func testV1FltrPopulateResourcesAvailableUnits(t *testing.T) { //This filter won't match expectedIDs = []string{"Stat_1"} - if err := fltrRpc.Call(utils.StatSv1ProcessEvent, statsEv, &ids); err != nil { + if err := fltrRpc.Call(context.Background(), utils.StatSv1ProcessEvent, statsEv, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedIDs, ids) { t.Errorf("Expected %+v, received %+v", expectedIDs, ids) @@ -705,7 +706,7 @@ func testV1FltrPopulateResourcesAvailableUnits(t *testing.T) { func testV1FltrAccounts(t *testing.T) { var resp string - if err := fltrRpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := fltrRpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -729,7 +730,7 @@ func testV1FltrAccounts(t *testing.T) { } var result string - if err := fltrRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -738,7 +739,7 @@ func testV1FltrAccounts(t *testing.T) { attrsAA := &utils.AttrSetActions{ActionsId: "LOG", Actions: []*utils.TPAction{ {Identifier: utils.MetaLog}, }} - if err := fltrRpc.Call(utils.APIerSv2SetActions, attrsAA, &result); err != nil && err.Error() != utils.ErrExists.Error() { + if err := fltrRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &result); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if result != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", result) @@ -756,13 +757,13 @@ func testV1FltrAccounts(t *testing.T) { Async: true, }, } - if err := fltrRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var rcvTh *engine.ThresholdProfile - if err := fltrRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := fltrRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tPrfl.Tenant, ID: tPrfl.ID}, &rcvTh); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, rcvTh) { @@ -776,7 +777,7 @@ func testV1FltrAccounts(t *testing.T) { utils.AccountField: "1001"}, } var ids []string - if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err != nil { + if err := fltrRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, []string{"TH_Account"}) { t.Error("Unexpected reply returned", ids) @@ -798,13 +799,13 @@ func testV1FltrAccounts(t *testing.T) { }, } - if err := fltrRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err == nil || + if err := fltrRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -812,7 +813,7 @@ func testV1FltrAccounts(t *testing.T) { func testV1FltrAccountsExistsDynamicaly(t *testing.T) { var resp string - if err := fltrRpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := fltrRpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH_Account"}}, &resp); err != nil { if err.Error() != utils.ErrNotFound.Error() { // no error if the threshold is already removed t.Error(err) @@ -826,7 +827,7 @@ func testV1FltrAccountsExistsDynamicaly(t *testing.T) { attrsAA := &utils.AttrSetActions{ActionsId: "LOG", Actions: []*utils.TPAction{ {Identifier: utils.MetaLog}, }} - if err := fltrRpc.Call(utils.APIerSv2SetActions, attrsAA, &result); err != nil && err.Error() != utils.ErrExists.Error() { + if err := fltrRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &result); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } //Add a threshold with filter from above and an inline filter for Account 1010 @@ -842,13 +843,13 @@ func testV1FltrAccountsExistsDynamicaly(t *testing.T) { Async: true, }, } - if err := fltrRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var rcvTh *engine.ThresholdProfile - if err := fltrRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := fltrRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: tPrfl.Tenant, ID: tPrfl.ID}, &rcvTh); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, rcvTh) { @@ -862,7 +863,7 @@ func testV1FltrAccountsExistsDynamicaly(t *testing.T) { utils.AccountField: "1001"}, } var ids []string - if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err != nil { + if err := fltrRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, []string{"TH_AccountDinamic"}) { t.Error("Unexpected reply returned", ids) @@ -875,14 +876,14 @@ func testV1FltrAccountsExistsDynamicaly(t *testing.T) { utils.AccountField: "non"}, } ids = nil - if err := fltrRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := fltrRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, tEv, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } func testV1FltrChargerSuffix(t *testing.T) { var reply string - if err := fltrRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ + if err := fltrRpc.Call(context.Background(), utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{ CacheIDs: nil, }, &reply); err != nil { t.Error(err) @@ -900,7 +901,7 @@ func testV1FltrChargerSuffix(t *testing.T) { }, } var result string - if err := fltrRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -916,7 +917,7 @@ func testV1FltrChargerSuffix(t *testing.T) { Weight: 20, }, } - if err := fltrRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile2, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -954,7 +955,7 @@ func testV1FltrChargerSuffix(t *testing.T) { }, } var result2 []*engine.ChrgSProcessEventReply - if err := fltrRpc.Call(utils.ChargerSv1ProcessEvent, cgrEv, &result2); err != nil { + if err := fltrRpc.Call(context.Background(), utils.ChargerSv1ProcessEvent, cgrEv, &result2); err != nil { t.Error(err) } else if !reflect.DeepEqual(result2, processedEv) { t.Errorf("Expecting : %s, \n received: %s", utils.ToJSON(processedEv), utils.ToJSON(result2)) @@ -992,7 +993,7 @@ func testV1FltrChargerSuffix(t *testing.T) { utils.Destination: "999", }, } - if err := fltrRpc.Call(utils.ChargerSv1ProcessEvent, cgrEv, &result2); err != nil { + if err := fltrRpc.Call(context.Background(), utils.ChargerSv1ProcessEvent, cgrEv, &result2); err != nil { t.Error(err) } else if !reflect.DeepEqual(result2, processedEv) { t.Errorf("Expecting : %s, \n received: %s", utils.ToJSON(processedEv), utils.ToJSON(result2)) @@ -1018,7 +1019,7 @@ func testV1FltrAttributesPrefix(t *testing.T) { }, } var result string - if err := fltrRpc.Call(utils.APIerSv1SetAttributeProfile, chargerProfile, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1054,7 +1055,7 @@ func testV1FltrAttributesPrefix(t *testing.T) { }, } var result2 *engine.AttrSProcessEventReply - if err := fltrRpc.Call(utils.AttributeSv1ProcessEvent, cgrEv, &result2); err != nil { + if err := fltrRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, cgrEv, &result2); err != nil { t.Error(err) } else if !reflect.DeepEqual(result2, processedEv) { t.Errorf("Expecting : %s, \n received: %s", utils.ToJSON(processedEv), utils.ToJSON(result2)) @@ -1074,7 +1075,7 @@ func testV1FltrPopulateTimings(t *testing.T) { var reply string - if err := fltrRpc.Call(utils.APIerSv1SetTiming, timing, &reply); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetTiming, timing, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -1095,7 +1096,7 @@ func testV1FltrPopulateTimings(t *testing.T) { } var result string - if err := fltrRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetFilter, filter, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1117,7 +1118,7 @@ func testV1FltrPopulateTimings(t *testing.T) { }, } attrPrf.Compile() - if err := fltrRpc.Call(utils.APIerSv1SetAttributeProfile, attrPrf, &result); err != nil { + if err := fltrRpc.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -1151,7 +1152,7 @@ func testV1FltrPopulateTimings(t *testing.T) { } var rplyEv1 engine.AttrSProcessEventReply - if err := fltrRpc.Call(utils.AttributeSv1ProcessEvent, + if err := fltrRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv1); err != nil { t.Error(err) } else { @@ -1166,7 +1167,7 @@ func testV1FltrPopulateTimings(t *testing.T) { ev.Event[utils.AnswerTime] = "2021-04-29T13:35:00Z" var rplyEv2 engine.AttrSProcessEventReply - if err := fltrRpc.Call(utils.AttributeSv1ProcessEvent, + if err := fltrRpc.Call(context.Background(), utils.AttributeSv1ProcessEvent, ev, &rplyEv2); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error: %+v,%+v", err, utils.ErrNotFound) } diff --git a/general_tests/filters_test.go b/general_tests/filters_test.go index 9c6dfd13c..b1db4f285 100644 --- a/general_tests/filters_test.go +++ b/general_tests/filters_test.go @@ -22,11 +22,11 @@ import ( "testing" "time" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestFilterPassDestinations(t *testing.T) { @@ -35,13 +35,17 @@ func TestFilterPassDestinations(t *testing.T) { t.Errorf("Expecting: nil, received: %s", err) } config.CgrConfig().FilterSCfg().ApierSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier)} - internalAPIerSv1Chan := make(chan rpcclient.ClientConnector, 1) - connMgr := engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{ + internalAPIerSv1Chan := make(chan birpc.ClientConnector, 1) + connMgr := engine.NewConnManager(config.CgrConfig(), map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier): internalAPIerSv1Chan, }) data := engine.NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), connMgr) - internalAPIerSv1Chan <- &v1.APIerSv1{DataManager: dm} + srv, err := engine.NewService(&v1.APIerSv1{DataManager: dm}) + if err != nil { + t.Error(err) + } + internalAPIerSv1Chan <- srv engine.SetConnManager(connMgr) cd := &engine.CallDescriptor{ Category: "call", @@ -86,8 +90,8 @@ func TestFilterPassDestinations(t *testing.T) { func TestInlineFilterPassFiltersForEvent(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.FilterSCfg().ApierSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier)} - internalAPIerSv1Chan := make(chan rpcclient.ClientConnector, 1) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + internalAPIerSv1Chan := make(chan birpc.ClientConnector, 1) + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaApier): internalAPIerSv1Chan, }) data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -97,7 +101,12 @@ func TestInlineFilterPassFiltersForEvent(t *testing.T) { []string{"DE", "EU_LANDLINE"}, nil, true, ""); err != nil { t.Errorf("Expecting: nil, received: %s", err) } - internalAPIerSv1Chan <- &v1.APIerSv1{DataManager: dmFilterPass} + + apiSrv, err := engine.NewService(&v1.APIerSv1{DataManager: dmFilterPass}) + if err != nil { + t.Fatal(err) + } + internalAPIerSv1Chan <- apiSrv engine.SetConnManager(connMgr) failEvent := map[string]any{ utils.Destination: "+5086517174963", diff --git a/general_tests/fltr_sep_it_test.go b/general_tests/fltr_sep_it_test.go index 2d6259215..f25242355 100644 --- a/general_tests/fltr_sep_it_test.go +++ b/general_tests/fltr_sep_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -37,7 +38,7 @@ import ( var ( fltrSepCfgPath string fltrSepCfg *config.CGRConfig - fltrSepRPC *rpc.Client + fltrSepRPC *birpc.Client fltrSepDelay int fltrSepConfDIR string //run tests for specific configuration @@ -111,7 +112,7 @@ func testFltrSepRpcConn(t *testing.T) { func testFltrSepLoadTarrifPlans(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "fltr_sep")} - if err := fltrSepRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := fltrSepRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -151,7 +152,7 @@ func testFltrSepFilterSeparation(t *testing.T) { var attrReply *engine.AttributeProfile // first option of the first filter and the second filter match - if err := fltrSepRPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrSepRPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev, &attrReply); err != nil { t.Error(err) } else { @@ -167,7 +168,7 @@ func testFltrSepFilterSeparation(t *testing.T) { // third option of the first filter and the second filter match ev.Event[utils.AccountField] = "1003" - if err := fltrSepRPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrSepRPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev, &attrReply); err != nil { t.Error(err) } else { @@ -183,14 +184,14 @@ func testFltrSepFilterSeparation(t *testing.T) { // the second filter matches while none of the options from the first filter match ev.Event[utils.AccountField] = "1004" - if err := fltrSepRPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrSepRPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } // fourth option of the first filter matches while the second filter doesn't ev.Event[utils.AccountField] = "1101" - if err := fltrSepRPC.Call(utils.AttributeSv1GetAttributeForEvent, + if err := fltrSepRPC.Call(context.Background(), utils.AttributeSv1GetAttributeForEvent, ev, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrNotFound, err) } diff --git a/general_tests/fraud_detection_it_test.go b/general_tests/fraud_detection_it_test.go index c9adb3534..6f7e7b576 100644 --- a/general_tests/fraud_detection_it_test.go +++ b/general_tests/fraud_detection_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "os" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -37,7 +38,7 @@ import ( var ( fraudCfgPath string fraudCfg *config.CGRConfig - fraudRPC *rpc.Client + fraudRPC *birpc.Client fraudDelay int fraudConfDIR string @@ -250,7 +251,7 @@ cgrates.org,THD_FRD,*gte:~*req.*tcc:2,,-1,1,0,false,0,ACT_FRD_STOP;ACT_FRD_LOG,t var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: "/tmp/TestFraudIT"} - if err := fraudRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := fraudRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -281,7 +282,7 @@ func testFraudAuthorizeandProcess1(t *testing.T) { false, false, false, cgrEv, utils.Paginator{}, false, "") var rply sessions.V1AuthorizeReply - if err := fraudRPC.Call(utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { + if err := fraudRPC.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Error(err) } cgrEv = &utils.CGREvent{ @@ -302,7 +303,7 @@ func testFraudAuthorizeandProcess1(t *testing.T) { APIOpts: map[string]any{}, } var reply string - if err := fraudRPC.Call(utils.SessionSv1ProcessCDR, + if err := fraudRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, cgrEv, &reply); err == nil || err.Error() != utils.ErrPartiallyExecuted.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrPartiallyExecuted, err) } @@ -331,7 +332,7 @@ func testFraudAuthorizeandProcess2(t *testing.T) { false, false, false, cgrEv, utils.Paginator{}, false, "") var rply sessions.V1AuthorizeReply - if err := fraudRPC.Call(utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { + if err := fraudRPC.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Error(err) } cgrEv = &utils.CGREvent{ @@ -352,7 +353,7 @@ func testFraudAuthorizeandProcess2(t *testing.T) { APIOpts: map[string]any{}, } var reply string - if err := fraudRPC.Call(utils.SessionSv1ProcessCDR, + if err := fraudRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, cgrEv, &reply); err == nil || err.Error() != utils.ErrPartiallyExecuted.Error() { t.Errorf("expected: <%+v>, \nreceived: <%+v>", utils.ErrPartiallyExecuted, err) } @@ -381,7 +382,7 @@ func testFraudAuthorizeandProcess3(t *testing.T) { false, false, false, cgrEv, utils.Paginator{}, false, "") var rply sessions.V1AuthorizeReply - if err := fraudRPC.Call(utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { + if err := fraudRPC.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Error(err) } cgrEv = &utils.CGREvent{ @@ -402,7 +403,7 @@ func testFraudAuthorizeandProcess3(t *testing.T) { APIOpts: map[string]any{}, } var reply string - if err := fraudRPC.Call(utils.SessionSv1ProcessCDR, + if err := fraudRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, cgrEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -433,7 +434,7 @@ func testFraudFinalAuthorize(t *testing.T) { expErr := `RALS_ERROR:ACCOUNT_DISABLED` var rply sessions.V1AuthorizeReply - if err := fraudRPC.Call(utils.SessionSv1AuthorizeEvent, args, + if err := fraudRPC.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err == nil || err.Error() != expErr { t.Error(err) } diff --git a/general_tests/gocs_it_test.go b/general_tests/gocs_it_test.go index bfe6d6cb0..eff37da39 100644 --- a/general_tests/gocs_it_test.go +++ b/general_tests/gocs_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "os/exec" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/sessions" @@ -42,7 +43,7 @@ import ( var ( auCfgPath, usCfgPath, dspCfgPath string auCfg, usCfg, dspCfg *config.CGRConfig - auRPC, usRPC, dspRPC *rpc.Client + auRPC, usRPC, dspRPC *birpc.Client auEngine, usEngine, dspEngine *exec.Cmd sTestsGOCS = []func(t *testing.T){ testGOCSInitCfg, @@ -146,24 +147,24 @@ func testGOCSLoadData(t *testing.T) { }, } var result string - if err := usRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := usRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var rpl *engine.ChargerProfile - if err := usRPC.Call(utils.APIerSv1GetChargerProfile, + if err := usRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, rpl) { t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, rpl) } - if err := usRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := usRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := usRPC.Call(utils.APIerSv1GetChargerProfile, + if err := usRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}, &rpl); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, rpl) { @@ -205,13 +206,13 @@ func testGOCSLoadData(t *testing.T) { } // add a voice balance of 59 minutes var reply string - if err := usRPC.Call(utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { + if err := usRPC.Call(context.Background(), utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("received: %s", reply) } expectedVoice := 3540000000000.0 - if err := usRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := usRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != expectedVoice { t.Errorf("Expecting: %v, received: %v", expectedVoice, rply) @@ -241,7 +242,7 @@ func testGOCSAuthSession(t *testing.T) { }, } var rply sessions.V1AuthorizeReply - if err := dspRPC.Call(utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { + if err := dspRPC.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Fatal(err) } if rply.MaxUsage == nil || *rply.MaxUsage != authUsage { @@ -272,7 +273,7 @@ func testGOCSInitSession(t *testing.T) { }, } var rply sessions.V1InitSessionReply - if err := dspRPC.Call(utils.SessionSv1InitiateSession, + if err := dspRPC.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err != nil { t.Fatal(err) } @@ -283,7 +284,7 @@ func testGOCSInitSession(t *testing.T) { time.Sleep(10 * time.Millisecond) aSessions := make([]*sessions.ExternalSession, 0) - if err := auRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := auRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) @@ -294,7 +295,7 @@ func testGOCSInitSession(t *testing.T) { } aSessions = make([]*sessions.ExternalSession, 0) - if err := usRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := usRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) @@ -311,13 +312,13 @@ func testGOCSInitSession(t *testing.T) { } // 59 mins - 5 mins = 54 mins - if err := auRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := auRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 3240000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 3240000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) } - if err := usRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := usRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 3240000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 3240000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) @@ -351,12 +352,12 @@ func testGOCSUpdateSession(t *testing.T) { // right now dispatcher receive utils.ErrPartiallyExecuted // in case of of engines fails - if err := auRPC.Call(utils.SessionSv1UpdateSession, args, &rply); err != nil { + if err := auRPC.Call(context.Background(), utils.SessionSv1UpdateSession, args, &rply); err != nil { t.Errorf("Expecting : %+v, received: %+v", utils.ErrPartiallyExecuted, err) } aSessions := make([]*sessions.ExternalSession, 0) - if err := auRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := auRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) @@ -374,7 +375,7 @@ func testGOCSUpdateSession(t *testing.T) { // balanced changed in AU_SITE // 54 min - 5 mins = 49 min - if err := auRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := auRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 2940000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 2940000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) @@ -389,13 +390,13 @@ func testGOCSVerifyAccountsAfterStart(t *testing.T) { Account: "1001", } // because US_SITE was down we should notice a difference between balance from accounts from US_SITE and AU_SITE - if err := auRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := auRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 2940000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 2940000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) } - if err := usRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := usRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 3240000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 3240000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) @@ -427,14 +428,14 @@ func testGOCSUpdateSession2(t *testing.T) { var rply sessions.V1UpdateSessionReply // Update the session on both US_SITE and AU_SITE // With this update the account should be replicate from US_SITE to AU_SITE and forgot about the update than happens on AU_SITE - if err := dspRPC.Call(utils.SessionSv1UpdateSession, args, &rply); err != nil { + if err := dspRPC.Call(context.Background(), utils.SessionSv1UpdateSession, args, &rply); err != nil { t.Errorf("Expecting : %+v, received: %+v", nil, err) } else if rply.MaxUsage == nil || *rply.MaxUsage != reqUsage { t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) } aSessions := make([]*sessions.ExternalSession, 0) - if err := auRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := auRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions)) @@ -445,7 +446,7 @@ func testGOCSUpdateSession2(t *testing.T) { } aSessions = make([]*sessions.ExternalSession, 0) - if err := usRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := usRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions)) @@ -461,13 +462,13 @@ func testGOCSUpdateSession2(t *testing.T) { Account: "1001", } - if err := auRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := auRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 2940000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 2940000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) } - if err := usRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := usRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 2940000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 2940000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) @@ -498,7 +499,7 @@ func testGOCSTerminateSession(t *testing.T) { var rply string // we send terminate session with the correct usage, but because the US_SITE was down // this lost the previous session operations and will debit more - if err := dspRPC.Call(utils.SessionSv1TerminateSession, + if err := dspRPC.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } @@ -506,11 +507,11 @@ func testGOCSTerminateSession(t *testing.T) { t.Errorf("Unexpected reply: %s", rply) } aSessions := make([]*sessions.ExternalSession, 0) - if err := auRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || + if err := auRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error %s received error %v and reply %s", utils.ErrNotFound, err, utils.ToJSON(aSessions)) } - if err := usRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || + if err := usRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected error %s received error %v and reply %s", utils.ErrNotFound, err, utils.ToJSON(aSessions)) } @@ -521,13 +522,13 @@ func testGOCSTerminateSession(t *testing.T) { Account: "1001", } - if err := auRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := auRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 2640000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 2640000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) } - if err := usRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := usRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 2640000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 2640000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) @@ -556,7 +557,7 @@ func testGOCSProcessCDR(t *testing.T) { var rply string // process cdr should apply the correction because terminate was debited to much // 59 - 15 = 44 minutes - if err := usRPC.Call(utils.SessionSv1ProcessCDR, + if err := usRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, args, &rply); err != nil { t.Error(err) } @@ -570,13 +571,13 @@ func testGOCSProcessCDR(t *testing.T) { Account: "1001", } - if err := auRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := auRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 2640000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 2640000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) } - if err := usRPC.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := usRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 2640000000000.0 { t.Errorf("Expecting : %+v, received: %+v", 2640000000000.0, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) diff --git a/general_tests/lib_test.go b/general_tests/lib_test.go index d8944e709..722e4859d 100644 --- a/general_tests/lib_test.go +++ b/general_tests/lib_test.go @@ -20,27 +20,27 @@ package general_tests import ( "errors" "flag" - "net/rpc" - "net/rpc/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) var ( dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here") - waitRater = flag.Int("wait_rater", 100, "Number of milliseconds to wait for rater to start and cache") + waitRater = flag.Int("wait_rater", 500, "Number of milliseconds to wait for rater to start and cache") encoding = flag.String("rpc", utils.MetaJSON, "what encoding would be used for rpc communication") dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") err error ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/general_tests/libengine_it_test.go b/general_tests/libengine_it_test.go index 8b8689af0..5cb40489b 100644 --- a/general_tests/libengine_it_test.go +++ b/general_tests/libengine_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -34,7 +35,7 @@ import ( var ( libengCfg *config.CGRConfig - libengRpc *rpc.Client + libengRpc *birpc.Client libengCfgPath string libengConfigDIR string @@ -109,15 +110,18 @@ func testLibengITRPCConnection(t *testing.T) { Tenant: "cgrates.org", } var reply string - conn, err := engine.NewRPCConnection(cgrCfg, "", "", "", - cgrCfg.ConnectAttempts, cgrCfg.Reconnects, cgrCfg.ConnectTimeout, cgrCfg.ReplyTimeout, nil, false, nil, "*localhost", + conn, err := engine.NewRPCConnection(context.Background(), + cgrCfg, "", "", "", + cgrCfg.ConnectAttempts, cgrCfg.Reconnects, + cgrCfg.MaxReconnectInterval, cgrCfg.ConnectTimeout, + cgrCfg.ReplyTimeout, nil, false, "*localhost", "a4f3f", new(ltcache.Cache)) if err != nil { t.Error(err) } //We check if we get a reply timeout error when calling a sleep bigger than the reply timeout from connection config. errExpect := "REPLY_TIMEOUT" - if err := conn.Call(utils.CoreSv1Sleep, args, &reply); err.Error() != errExpect { + if err := conn.Call(context.Background(), utils.CoreSv1Sleep, args, &reply); err.Error() != errExpect { t.Errorf("Expected %v \n but received \n %v", errExpect, err.Error()) } diff --git a/general_tests/loader_nocontext_it_test.go b/general_tests/loader_nocontext_it_test.go index eb21e5985..e0e3b0fef 100644 --- a/general_tests/loader_nocontext_it_test.go +++ b/general_tests/loader_nocontext_it_test.go @@ -22,7 +22,6 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "os" "path" "reflect" @@ -30,6 +29,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -39,7 +40,7 @@ import ( var ( ldrCtxCfgPath string ldrCtxCfg *config.CGRConfig - ldrCtxRPC *rpc.Client + ldrCtxRPC *birpc.Client ldrCtxConfDIR string //run tests for specific configuration ldrCtxDelay int @@ -157,7 +158,7 @@ cgrates.org,DSP2,,,,,,ALL2,,10,,, func testLoaderNoContextLoadTariffPlans(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: "/tmp/TestLoaderNoContextIT"} - if err := ldrCtxRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := ldrCtxRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -172,7 +173,7 @@ func testLoaderNoContextGetFilterIndexesAfterLoad(t *testing.T) { "*string:*req.Field1:Value1:ATTR_1", } var result []string - if err := ldrCtxRPC.Call(utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ + if err := ldrCtxRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: "cgrates.org", Context: utils.MetaAny, @@ -190,7 +191,7 @@ func testLoaderNoContextGetFilterIndexesAfterLoad(t *testing.T) { "*none:*any:*any:DSP1", "*string:*req.Field1:Value1:DSP2", } - if err := ldrCtxRPC.Call(utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ + if err := ldrCtxRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ ItemType: utils.MetaDispatchers, Tenant: "cgrates.org", Context: utils.MetaAny, @@ -224,13 +225,13 @@ func testLoaderNoContextSetProfiles(t *testing.T) { } attrPrf.Compile() var reply string - if err := ldrCtxRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf, &reply); err != nil { + if err := ldrCtxRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, attrPrf, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) } var attrReply *engine.AttributeProfile - if err := ldrCtxRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := ldrCtxRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_3"}}, &attrReply); err != nil { t.Error(err) } else { @@ -254,7 +255,7 @@ func testLoaderNoContextSetProfiles(t *testing.T) { }, } - if err := ldrCtxRPC.Call(utils.APIerSv1SetDispatcherProfile, + if err := ldrCtxRPC.Call(context.Background(), utils.APIerSv1SetDispatcherProfile, dspPrf, &reply); err != nil { t.Error(err) @@ -263,7 +264,7 @@ func testLoaderNoContextSetProfiles(t *testing.T) { } var dspReply *engine.DispatcherProfile - if err := ldrCtxRPC.Call(utils.APIerSv1GetDispatcherProfile, + if err := ldrCtxRPC.Call(context.Background(), utils.APIerSv1GetDispatcherProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "DSP3"}, &dspReply); err != nil { t.Error(err) @@ -283,7 +284,7 @@ func testLoaderNoContextGetFilterIndexesAfterSet(t *testing.T) { "*string:*req.Field3:Value3:ATTR_3", } var result []string - if err := ldrCtxRPC.Call(utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ + if err := ldrCtxRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: "cgrates.org", Context: utils.MetaAny, @@ -302,7 +303,7 @@ func testLoaderNoContextGetFilterIndexesAfterSet(t *testing.T) { "*string:*req.Field1:Value1:DSP2", "*string:*req.RandomField:RandomValue:DSP3", } - if err := ldrCtxRPC.Call(utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ + if err := ldrCtxRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ ItemType: utils.MetaDispatchers, Tenant: "cgrates.org", Context: utils.MetaAny, diff --git a/general_tests/loaders_internal_indexes_it_test.go b/general_tests/loaders_internal_indexes_it_test.go index 52a168913..f3cd15044 100644 --- a/general_tests/loaders_internal_indexes_it_test.go +++ b/general_tests/loaders_internal_indexes_it_test.go @@ -21,13 +21,14 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -39,7 +40,7 @@ var ( loadersIDBIdxCfgPath string loadersIDBIdxCfgPathInternal = path.Join(*dataDir, "conf", "samples", "loaders_indexes_internal_db") loadersIDBIdxCfg, loadersIDBIdxCfgInternal *config.CGRConfig - loadersIDBIdxRPC, loadersIDBIdxRPCInternal *rpc.Client + loadersIDBIdxRPC, loadersIDBIdxRPCInternal *birpc.Client LoadersIDBIdxTests = []func(t *testing.T){ testLoadersIDBIdxItLoadConfig, @@ -111,7 +112,7 @@ func testLoadersIDBIdxItRPCConn(t *testing.T) { func testLoadersIDBIdxItLoad(t *testing.T) { var loadInst utils.LoadInstance - if err := loadersIDBIdxRPCInternal.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := loadersIDBIdxRPCInternal.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}, &loadInst); err != nil { t.Error(err) @@ -136,7 +137,7 @@ func testLoadersIDBIdxCheckAttributes(t *testing.T) { } var reply *engine.AttributeProfile - if err := loadersIDBIdxRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := loadersIDBIdxRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}}, &reply); err != nil { t.Error(err) @@ -152,7 +153,7 @@ func testLoadersIDBIdxCheckAttributesIndexes(t *testing.T) { "*string:*req.Account:1003:ATTR_1003_SIMPLEAUTH", } var indexes []string - if err := loadersIDBIdxRPC.Call(utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ + if err := loadersIDBIdxRPC.Call(context.Background(), utils.APIerSv1GetFilterIndexes, &v1.AttrGetFilterIndexes{ ItemType: utils.MetaAttributes, Tenant: "cgrates.org", FilterType: utils.MetaString, Context: "simpleauth"}, &indexes); err != nil { diff --git a/general_tests/oldtutorial_it_test.go b/general_tests/oldtutorial_it_test.go index a5299849c..6212522ca 100644 --- a/general_tests/oldtutorial_it_test.go +++ b/general_tests/oldtutorial_it_test.go @@ -39,7 +39,7 @@ package general_tests // var tutLocalCfgPath string // var tutFsLocalCfg *config.CGRConfig -// var tutLocalRpc *rpc.Client +// var tutLocalRpc *birpc.Client // var loadInst utils.LoadInstance // Share load information between tests // func TestTutITInitCfg(t *testing.T) { @@ -87,7 +87,7 @@ package general_tests // // Load the tariff plan, creating accounts and their balances // func TestTutITLoadTariffPlanFromFolder(t *testing.T) { // attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(**dataDir, "tariffplans", "oldtutorial")} -// if err := tutLocalRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { // t.Error(err) // } // time.Sleep(100*time.Millisecond + time.Duration(**waitRater)*time.Millisecond) // Give time for scheduler to execute topups @@ -108,7 +108,7 @@ package general_tests // ThresholdProfiles: 7, Filters: 16, SupplierProfiles: 3, AttributeProfiles: 1, // CdrStats: 0, Users: 0} // CdrStats and Users are 0 because deprecated. To be removed // var args utils.AttrCacheStats -// if err := tutLocalRpc.Call(utils.APIerSv1GetCacheStats, args, &rcvStats); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv1GetCacheStats, args, &rcvStats); err != nil { // t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error()) // } else if !reflect.DeepEqual(expectedStats, rcvStats) { // t.Errorf("Calling APIerSv1.GetCacheStats expected: %+v, received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats)) @@ -120,7 +120,7 @@ package general_tests // var rcvKeys utils.ArgsCache // argsAPI := utils.ArgsCacheKeys{ArgsCache: utils.ArgsCache{ // DestinationIDs: &[]string{}, RatingPlanIDs: &[]string{"RP_RETAIL1", "RP_GENERIC", "NONEXISTENT"}}} -// if err := tutLocalRpc.Call(utils.APIerSv1GetCacheKeys, argsAPI, &rcvKeys); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv1GetCacheKeys, argsAPI, &rcvKeys); err != nil { // t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error()) // } else { // if rcvKeys.DestinationIDs == nil { @@ -145,7 +145,7 @@ package general_tests // if err != nil { // t.Fatal(err) // } -// if err := tutLocalRpc.Call(utils.APIerSv1GetCacheStats, args, &rcvStats); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv1GetCacheStats, args, &rcvStats); err != nil { // t.Error("Got error on APIerSv1.GetCacheStats: ", err.Error()) // } else if !reflect.DeepEqual(expectedStats, rcvStats) { // t.Errorf("Calling APIerSv1.GetCacheStats expected: %+v, received: %+v", expectedStats, rcvStats) @@ -197,7 +197,7 @@ package general_tests // TimeEnd: tEnd, // } // var cc engine.CallCost -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 0.6 { // t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost) @@ -214,7 +214,7 @@ package general_tests // TimeEnd: tEnd, // ExtraFields: map[string]string{"Uuid": "388539dfd4f5cefee8f488b78c6c244b9e19138e"}, // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 0.6 { // t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost) @@ -231,7 +231,7 @@ package general_tests // TimeStart: tStart, // TimeEnd: tEnd, // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 0.6418 { // 0.01 first minute, 0.04 25 seconds with RT_20CNT // t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost) @@ -248,7 +248,7 @@ package general_tests // TimeStart: tStart, // TimeEnd: tEnd, // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 1 { // t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost) @@ -265,7 +265,7 @@ package general_tests // TimeStart: tStart, // TimeEnd: tEnd, // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 1.3 { // t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost) @@ -282,7 +282,7 @@ package general_tests // TimeStart: tStart, // TimeEnd: tEnd, // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 1 { // t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost) @@ -299,7 +299,7 @@ package general_tests // TimeStart: tStart, // TimeEnd: tEnd, // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 1.3 { // t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost) @@ -314,7 +314,7 @@ package general_tests // TimeStart: tStart, // TimeEnd: tStart.Add(50 * time.Second), // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 0.5 { // t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON()) @@ -328,7 +328,7 @@ package general_tests // TimeStart: tStart, // TimeEnd: tStart.Add(70 * time.Second), // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 0.62 { // t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost) @@ -342,7 +342,7 @@ package general_tests // TimeStart: tStart, // TimeEnd: tStart.Add(50 * time.Second), // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 0.5 { // t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON()) @@ -356,7 +356,7 @@ package general_tests // TimeStart: tStart, // TimeEnd: tStart.Add(70 * time.Second), // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 0.7 { // In case of *disconnect strategy, it will not be applied so we can go on negative costs // t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON()) @@ -370,7 +370,7 @@ package general_tests // TimeStart: time.Date(2016, 1, 6, 19, 0, 0, 0, time.UTC), // TimeEnd: time.Date(2016, 1, 6, 19, 1, 30, 0, time.UTC), // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 0.3249 { // // t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON()) @@ -384,7 +384,7 @@ package general_tests // TimeStart: time.Date(2016, 1, 6, 18, 31, 5, 0, time.UTC), // TimeEnd: time.Date(2016, 1, 6, 18, 32, 35, 0, time.UTC), // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 1.3 { // // t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON()) @@ -398,7 +398,7 @@ package general_tests // TimeStart: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC), // TimeEnd: time.Date(2014, 12, 7, 8, 44, 26, 0, time.UTC), // } -// if err := tutLocalRpc.Call(utils.ResponderGetCost, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderGetCost, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.Cost != 0.3498 { // // t.Errorf("Calling Responder.GetCost got callcost: %s", cc.AsJSON()) @@ -419,7 +419,7 @@ package general_tests // TimeEnd: tStart.Add(20 * time.Second), // } // var cc engine.CallCost -// if err := tutLocalRpc.Call(utils.ResponderMaxDebit, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderMaxDebit, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.GetDuration() == 20 { // t.Errorf("Calling Responder.MaxDebit got callcost: %v", cc.GetDuration()) @@ -434,7 +434,7 @@ package general_tests // TimeStart: tStart, // TimeEnd: tStart.Add(200 * time.Second), // } -// if err := tutLocalRpc.Call(utils.ResponderMaxDebit, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderMaxDebit, cd, &cc); err != nil { // t.Error("Got error on Responder.MaxDebit: ", err.Error()) // } else if cc.GetDuration() == 200 { // t.Errorf("Calling Responder.MaxDebit got duration: %v", cc.GetDuration()) @@ -450,7 +450,7 @@ package general_tests // TimeEnd: tStart.Add(120 * time.Second), // } // cd.CgrID = "1" -// if err := tutLocalRpc.Call(utils.ResponderMaxDebit, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderMaxDebit, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.GetDuration() == 120 { // t.Errorf("Calling Responder.MaxDebit got callcost: %v", cc.GetDuration()) @@ -466,7 +466,7 @@ package general_tests // TimeEnd: tStart.Add(120 * time.Second), // } // cd.CgrID = "2" -// if err := tutLocalRpc.Call(utils.ResponderMaxDebit, cd, &cc); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.ResponderMaxDebit, cd, &cc); err != nil { // t.Error("Got error on Responder.GetCost: ", err.Error()) // } else if cc.GetDuration() != 62*time.Second { // We have as strategy *dsconnect // t.Errorf("Calling Responder.MaxDebit got callcost: %v", cc.GetDuration()) @@ -586,7 +586,7 @@ package general_tests // var cdrs []*engine.ExternalCDR // req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, // Accounts: []string{"1004"}, DestinationPrefixes: []string{"1001"}} -// if err := tutLocalRpc.Call(utils.APIerSv2GetCDRs, req, &cdrs); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, req, &cdrs); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if len(cdrs) != 1 { // t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -646,7 +646,7 @@ package general_tests // time.Sleep(time.Duration(**waitRater) * time.Millisecond) // var cdrs []*engine.ExternalCDR // req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{cdr.Account}, DestinationPrefixes: []string{cdr.Destination}} -// if err := tutLocalRpc.Call(utils.APIerSv2GetCDRs, req, &cdrs); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, req, &cdrs); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if len(cdrs) != 1 { // t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -671,7 +671,7 @@ package general_tests // } // time.Sleep(time.Duration(**waitRater) * time.Millisecond) // Give time for CDR to be processed // req = utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{cdr2.Account}, DestinationPrefixes: []string{cdr2.Destination}} -// if err := tutLocalRpc.Call(utils.APIerSv2GetCDRs, req, &cdrs); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, req, &cdrs); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if len(cdrs) != 1 { // t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -696,7 +696,7 @@ package general_tests // } // time.Sleep(time.Duration(**waitRater) * time.Millisecond) // Give time for CDR to be processed // req = utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{cdr3.Account}, DestinationPrefixes: []string{cdr3.Destination}} -// if err := tutLocalRpc.Call(utils.APIerSv2GetCDRs, req, &cdrs); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, req, &cdrs); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if len(cdrs) != 1 { // t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -967,7 +967,7 @@ package general_tests // ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}} // var reply string // for _, cdr := range []*engine.CDR{testCdr1, testCdr2} { -// if err := tutLocalRpc.Call(utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if reply != utils.OK { // t.Error("Unexpected reply received: ", reply) @@ -1005,7 +1005,7 @@ package general_tests // Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004", // SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC), // Usage: 180 * time.Second} -// if err := tutLocalRpc.Call(utils.CDRsV1ProcessCDR, testCdr3, &reply); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, testCdr3, &reply); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if reply != utils.OK { // t.Error("Unexpected reply received: ", reply) @@ -1068,7 +1068,7 @@ package general_tests // SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC), // Usage: 60 * time.Second} // var reply string -// if err := tutLocalRpc.Call(utils.CDRsV1ProcessCDR, testCdr4, &reply); err != nil { // Should drop ACD under the 2m required by threshold, removing suppl2 from lcr +// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, testCdr4, &reply); err != nil { // Should drop ACD under the 2m required by threshold, removing suppl2 from lcr // t.Error("Unexpected error: ", err.Error()) // } else if reply != utils.OK { // t.Error("Unexpected reply received: ", reply) @@ -1131,7 +1131,7 @@ package general_tests // Tenant: "cgrates.org", Category: "call", Account: "1003", Subject: "1003", Destination: "1004", // SetupTime: time.Date(2014, 12, 7, 8, 42, 24, 0, time.UTC), AnswerTime: time.Date(2014, 12, 7, 8, 42, 26, 0, time.UTC), // Usage: time.Second} -// if err := tutLocalRpc.Call(utils.CDRsV1ProcessCDR, testCdr5, &reply); err != nil { // Should drop ACD under the 1m required by threshold, removing suppl2 from lcr +// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, testCdr5, &reply); err != nil { // Should drop ACD under the 1m required by threshold, removing suppl2 from lcr // t.Error("Unexpected error: ", err.Error()) // } else if reply != utils.OK { // t.Error("Unexpected reply received: ", reply) @@ -1158,7 +1158,7 @@ package general_tests // func TestTutITSetAccount(t *testing.T) { // var reply string // attrs := &v2.AttrSetAccount{Tenant: "cgrates.org", Account: "tutacnt1", ActionPlanIDs: &[]string{"PACKAGE_10"}, ActionTriggerIDs: &[]string{"STANDARD_TRIGGERS"}, ReloadScheduler: true} -// if err := tutLocalRpc.Call(utils.APIerSv2SetAccount, attrs, &reply); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2SetAccount, attrs, &reply); err != nil { // t.Error("Got error on APIerSv2.SetAccount: ", err.Error()) // } else if reply != utils.OK { // t.Errorf("Calling APIerSv2.SetAccount received: %s", reply) @@ -1196,7 +1196,7 @@ package general_tests // } // attrs = &v2.AttrSetAccount{Tenant: "cgrates.org", Account: "tutacnt1", ActionPlanIDs: &[]string{"PACKAGE_10"}, ActionTriggerIDs: &[]string{"STANDARD_TRIGGERS"}, AllowNegative: utils.BoolPointer(true), Disabled: utils.BoolPointer(true), ReloadScheduler: true} -// if err := tutLocalRpc.Call(utils.APIerSv2SetAccount, attrs, &reply); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2SetAccount, attrs, &reply); err != nil { // t.Error("Got error on APIerSv2.SetAccount: ", err.Error()) // } else if reply != utils.OK { // t.Errorf("Calling APIerSv2.SetAccount received: %s", reply) @@ -1226,7 +1226,7 @@ package general_tests // } // attrs = &v2.AttrSetAccount{Tenant: "cgrates.org", Account: "tutacnt1", ActionPlanIDs: &[]string{"PACKAGE_1001"}, ActionTriggerIDs: &[]string{"CDRST1_WARN"}, AllowNegative: utils.BoolPointer(true), Disabled: utils.BoolPointer(true), ReloadScheduler: true} -// if err := tutLocalRpc.Call(utils.APIerSv2SetAccount, attrs, &reply); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2SetAccount, attrs, &reply); err != nil { // t.Error("Got error on APIerSv2.SetAccount: ", err.Error()) // } else if reply != utils.OK { // t.Errorf("Calling APIerSv2.SetAccount received: %s", reply) @@ -1349,7 +1349,7 @@ package general_tests // } else if reply != utils.OK { // t.Error("Unexpected reply received: ", reply) // } -// if err := tutLocalRpc.Call(utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if reply != utils.OK { // t.Error("Unexpected reply received: ", reply) @@ -1357,7 +1357,7 @@ package general_tests // time.Sleep(time.Duration(**waitRater) * time.Millisecond) // Give time for CDR to be processed // var cdrs []*engine.ExternalCDR // req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, CGRIDs: []string{cdr.CGRID}} -// if err := tutLocalRpc.Call(utils.APIerSv2GetCDRs, req, &cdrs); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, req, &cdrs); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if len(cdrs) != 1 { // t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -1380,7 +1380,7 @@ package general_tests // Usage: 90 * time.Second, // ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}} // var reply string -// if err := tutLocalRpc.Call(utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if reply != utils.OK { // t.Error("Unexpected reply received: ", reply) @@ -1389,7 +1389,7 @@ package general_tests // time.Sleep(7000 * time.Millisecond) // Give time for CDR to be processed // var cdrs []*engine.ExternalCDR // req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, CGRIDs: []string{cdr.CGRID}} -// if err := tutLocalRpc.Call(utils.APIerSv2GetCDRs, req, &cdrs); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, req, &cdrs); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if len(cdrs) != 1 { // t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -1412,7 +1412,7 @@ package general_tests // ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}} // cdr.ComputeCGRID() // var reply string -// if err := tutLocalRpc.Call(utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.CDRsV1ProcessCDR, cdr, &reply); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if reply != utils.OK { // t.Error("Unexpected reply received: ", reply) @@ -1420,7 +1420,7 @@ package general_tests // time.Sleep(50 * time.Millisecond) // Give time for CDR to be processed // var cdrs []*engine.ExternalCDR // req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, CGRIDs: []string{cdr.CGRID}} -// if err := tutLocalRpc.Call(utils.APIerSv2GetCDRs, req, &cdrs); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv2GetCDRs, req, &cdrs); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if len(cdrs) != 1 { // t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -1438,7 +1438,7 @@ package general_tests // ExportFileName: utils.StringPointer("TestTutITExportCDR.csv"), // ExportTemplate: utils.StringPointer("TestTutITExportCDR"), // RPCCDRsFilter: utils.RPCCDRsFilter{CGRIDs: []string{cdr.CGRID}, NotRunIDs: []string{utils.MetaRaw}}} -// if err := tutLocalRpc.Call(utils.APIerSv1ExportCDRs, exportArgs, &replyExport); err != nil { +// if err := tutLocalRpc.Call(context.Background(),utils.APIerSv1ExportCDRs, exportArgs, &replyExport); err != nil { // t.Error(err) // } // eExportContent := `f0a92222a7d21b4d9f72744aabe82daef52e20d8,*default,testexportcdr1,*rated,cgrates.org,call,1001,1003,2016-11-30T18:06:04+01:00,98,1.33340,RETA diff --git a/general_tests/poster_it_test.go b/general_tests/poster_it_test.go index 2f0ad9352..d11ead890 100644 --- a/general_tests/poster_it_test.go +++ b/general_tests/poster_it_test.go @@ -23,12 +23,13 @@ package general_tests import ( "encoding/json" "fmt" - "net/rpc" "os" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/ees" "github.com/cgrates/cgrates/engine" @@ -37,7 +38,7 @@ import ( var ( pstrCfg *config.CGRConfig - pstrRpc *rpc.Client + pstrRpc *birpc.Client pstrCfgPath string pstrConfigDIR string @@ -145,7 +146,7 @@ func testPosterReadFolder(format string) (expEv *ees.ExportEvents, err error) { func testPosterITSetAccount(t *testing.T) { var reply string - if err := pstrRpc.Call(utils.APIerSv1SetAccount, pstrAccount, &reply); err != nil { + if err := pstrRpc.Call(context.Background(), utils.APIerSv1SetAccount, pstrAccount, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -160,13 +161,13 @@ func testPosterITAMQP(t *testing.T) { {Identifier: utils.MetaExport, ExtraParameters: "amqp_fail"}, }, } - if err := pstrRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := pstrRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: pstrAccount.Tenant, Account: pstrAccount.Account, ActionsId: attrsAA.ActionsId} - if err := pstrRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := pstrRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) @@ -198,13 +199,13 @@ func testPosterITAMQPv1(t *testing.T) { {Identifier: utils.MetaExport, ExtraParameters: "aws_fail"}, }, } - if err := pstrRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := pstrRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: pstrAccount.Tenant, Account: pstrAccount.Account, ActionsId: attrsAA.ActionsId} - if err := pstrRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := pstrRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) @@ -236,13 +237,13 @@ func testPosterITSQS(t *testing.T) { {Identifier: utils.MetaExport, ExtraParameters: "sqs_fail"}, }, } - if err := pstrRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := pstrRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: pstrAccount.Tenant, Account: pstrAccount.Account, ActionsId: attrsAA.ActionsId} - if err := pstrRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := pstrRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) @@ -274,13 +275,13 @@ func testPosterITS3(t *testing.T) { {Identifier: utils.MetaExport, ExtraParameters: "s3_fail"}, }, } - if err := pstrRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := pstrRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: pstrAccount.Tenant, Account: pstrAccount.Account, ActionsId: attrsAA.ActionsId} - if err := pstrRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := pstrRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) @@ -312,13 +313,13 @@ func testPosterITKafka(t *testing.T) { {Identifier: utils.MetaExport, ExtraParameters: "kafka_fail"}, }, } - if err := pstrRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := pstrRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) } attrsEA := &utils.AttrExecuteAction{Tenant: pstrAccount.Tenant, Account: pstrAccount.Account, ActionsId: attrsAA.ActionsId} - if err := pstrRpc.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { + if err := pstrRpc.Call(context.Background(), utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil { t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply) diff --git a/general_tests/redis_cluster_it_test.go b/general_tests/redis_cluster_it_test.go index 268538bd4..86255a61d 100644 --- a/general_tests/redis_cluster_it_test.go +++ b/general_tests/redis_cluster_it_test.go @@ -25,7 +25,6 @@ import ( "bytes" "flag" "fmt" - "net/rpc" "os" "os/exec" "path" @@ -33,6 +32,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -65,7 +66,7 @@ import ( var ( clsrConfig *config.CGRConfig - clsrRPC *rpc.Client + clsrRPC *birpc.Client clsrNodeCfgPath = path.Join(*dataDir, "redisCluster", "node%v.conf") clsrEngineCfgPath = path.Join(*dataDir, "conf", "samples", "redisCluster") @@ -203,13 +204,13 @@ func testClsrSetGetAttribute(t *testing.T) { } alsPrf.Compile() var result string - if err := clsrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := clsrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.AttributeProfile - if err := clsrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := clsrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ClsrTest"}, &reply); err != nil { t.Fatal(err) } @@ -243,7 +244,7 @@ func testClsrSetGetAttribute2(t *testing.T) { } alsPrf.Compile() var reply *engine.AttributeProfile - if err := clsrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := clsrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ClsrTest"}, &reply); err != nil { t.Fatal(err) } @@ -254,7 +255,7 @@ func testClsrSetGetAttribute2(t *testing.T) { // add another attribute alsPrf.ID += "2" var result string - if err := clsrRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := clsrRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -288,7 +289,7 @@ func testClsrGetAttribute(t *testing.T) { } alsPrf.Compile() var reply *engine.AttributeProfile - if err := clsrRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := clsrRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ClsrTest2"}, &reply); err != nil { t.Fatal(err) } diff --git a/general_tests/redis_tls_it_test.go b/general_tests/redis_tls_it_test.go index 39795178b..0cde03c82 100644 --- a/general_tests/redis_tls_it_test.go +++ b/general_tests/redis_tls_it_test.go @@ -23,11 +23,12 @@ package general_tests import ( "flag" - "net/rpc" "os/exec" "path" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" "github.com/cgrates/cgrates/config" @@ -39,7 +40,7 @@ var ( redisTLSServer *exec.Cmd redisTLSEngineCfg = path.Join(*dataDir, "conf", "samples", "redisTLS") redisTLSCfg *config.CGRConfig - redisTLSRPC *rpc.Client + redisTLSRPC *birpc.Client sTestsRedisTLS = []func(t *testing.T){ testRedisTLSStartServer, @@ -107,7 +108,7 @@ func testRedisTLSRPCCon(t *testing.T) { func testRedisTLSSetGetAttribute(t *testing.T) { // status command to check if the engine starts var rply map[string]any - if err := redisTLSRPC.Call(utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil { + if err := redisTLSRPC.Call(context.Background(), utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil { t.Error(err) } } diff --git a/general_tests/rerate_cdrs_it_test.go b/general_tests/rerate_cdrs_it_test.go index 56f1e949e..7fb743bd2 100644 --- a/general_tests/rerate_cdrs_it_test.go +++ b/general_tests/rerate_cdrs_it_test.go @@ -22,12 +22,13 @@ package general_tests import ( "math" - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( rrCdrsCfgPath string rrCdrsCfg *config.CGRConfig - rrCdrsRPC *rpc.Client + rrCdrsRPC *birpc.Client rrCdrsConfDIR string //run tests for specific configuration rrCdrsDelay int rrCdrsUUID = utils.GenUUID() @@ -121,7 +122,7 @@ func testRerateCDRsRPCConn(t *testing.T) { func testRerateCDRsLoadTP(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "reratecdrs")} - if err := rrCdrsRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := rrCdrsRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -146,7 +147,7 @@ func testRerateCDRsSetBalance(t *testing.T) { }, } var reply string - if err := rrCdrsRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := rrCdrsRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -167,7 +168,7 @@ func testRerateCDRsGetAccountAfterBalanceSet(t *testing.T) { } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := rrCdrsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := rrCdrsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else { expAcnt.UpdateTime = acnt.UpdateTime @@ -202,7 +203,7 @@ func testRerateCDRsProcessEventCDR1(t *testing.T) { }, } var reply string - if err := rrCdrsRPC.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := rrCdrsRPC.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -212,7 +213,7 @@ func testRerateCDRsProcessEventCDR1(t *testing.T) { func testRerateCDRsCheckCDRCostAfterProcessEvent1(t *testing.T) { var cdrs []*engine.CDR - if err := rrCdrsRPC.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := rrCdrsRPC.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{ RunIDs: []string{"run_1"}, }}, &cdrs); err != nil { @@ -244,7 +245,7 @@ func testRerateCDRsGetAccountAfterProcessEvent1(t *testing.T) { } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := rrCdrsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := rrCdrsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else { expAcnt.UpdateTime = acnt.UpdateTime @@ -281,7 +282,7 @@ func testRerateCDRsProcessEventCDR2(t *testing.T) { }, } var reply string - if err := rrCdrsRPC.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := rrCdrsRPC.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -291,7 +292,7 @@ func testRerateCDRsProcessEventCDR2(t *testing.T) { func testRerateCDRsCheckCDRCostAfterProcessEvent2(t *testing.T) { var cdrs []*engine.CDR - if err := rrCdrsRPC.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := rrCdrsRPC.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{ RunIDs: []string{"run_2"}, }}, &cdrs); err != nil { @@ -323,7 +324,7 @@ func testRerateCDRsGetAccountAfterProcessEvent2(t *testing.T) { } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := rrCdrsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := rrCdrsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else { expAcnt.UpdateTime = acnt.UpdateTime @@ -338,7 +339,7 @@ func testRerateCDRsGetAccountAfterProcessEvent2(t *testing.T) { func testRerateCDRsRerateCDRs(t *testing.T) { var reply string - if err := rrCdrsRPC.Call(utils.CDRsV1RateCDRs, &engine.ArgRateCDRs{ + if err := rrCdrsRPC.Call(context.Background(), utils.CDRsV1RateCDRs, &engine.ArgRateCDRs{ Flags: []string{utils.MetaRerate}, RPCCDRsFilter: utils.RPCCDRsFilter{ OrderBy: utils.AnswerTime, @@ -352,7 +353,7 @@ func testRerateCDRsRerateCDRs(t *testing.T) { func testRerateCDRsCheckCDRCostsAfterRerate(t *testing.T) { var cdrs []*engine.CDR - if err := rrCdrsRPC.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := rrCdrsRPC.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{ CGRIDs: []string{rrCdrsUUID}, OrderBy: utils.AnswerTime, @@ -385,7 +386,7 @@ func testRerateCDRsGetAccountAfterRerate(t *testing.T) { } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := rrCdrsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := rrCdrsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else { expAcnt.UpdateTime = acnt.UpdateTime diff --git a/general_tests/rerate_exp_it_test.go b/general_tests/rerate_exp_it_test.go index 3d2fe38ee..af1c23d0d 100644 --- a/general_tests/rerate_exp_it_test.go +++ b/general_tests/rerate_exp_it_test.go @@ -22,12 +22,13 @@ package general_tests import ( "math" - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ import ( var ( ng1CfgPath, ng2CfgPath string ng1Cfg, ng2Cfg *config.CGRConfig - ng1RPC, ng2RPC *rpc.Client + ng1RPC, ng2RPC *birpc.Client ng1ConfDIR, ng2ConfDIR string //run tests for specific configuration rrDelay int ng1UUID = utils.GenUUID() @@ -148,7 +149,7 @@ func testRerateExpRPCConn(t *testing.T) { func testRerateExpLoadTP(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "reratecdrs")} - if err := ng1RPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := ng1RPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -173,7 +174,7 @@ func testRerateExpSetBalance(t *testing.T) { }, } var reply string - if err := ng1RPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := ng1RPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -194,7 +195,7 @@ func testRerateExpGetAccountAfterBalanceSet(t *testing.T) { } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := ng1RPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := ng1RPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else { expAcnt.UpdateTime = acnt.UpdateTime @@ -229,7 +230,7 @@ func testRerateExpProcessEventCDR1(t *testing.T) { }, } var reply string - if err := ng1RPC.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := ng1RPC.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } time.Sleep(50 * time.Millisecond) @@ -237,7 +238,7 @@ func testRerateExpProcessEventCDR1(t *testing.T) { func testRerateExpCheckCDRCostAfterProcessEvent1(t *testing.T) { var cdrs []*engine.CDR - if err := ng2RPC.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := ng2RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{ RunIDs: []string{"run_1"}, }}, &cdrs); err != nil { @@ -269,7 +270,7 @@ func testRerateExpGetAccountAfterProcessEvent1(t *testing.T) { } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := ng1RPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := ng1RPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else { expAcnt.UpdateTime = acnt.UpdateTime @@ -306,7 +307,7 @@ func testRerateExpProcessEventCDR2(t *testing.T) { }, } var reply string - if err := ng1RPC.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := ng1RPC.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } time.Sleep(50 * time.Millisecond) @@ -314,7 +315,7 @@ func testRerateExpProcessEventCDR2(t *testing.T) { func testRerateExpCheckCDRCostAfterProcessEvent2(t *testing.T) { var cdrs []*engine.CDR - if err := ng2RPC.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := ng2RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{ RunIDs: []string{"run_2"}, }}, &cdrs); err != nil { @@ -346,7 +347,7 @@ func testRerateExpGetAccountAfterProcessEvent2(t *testing.T) { } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := ng1RPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := ng1RPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else { expAcnt.UpdateTime = acnt.UpdateTime @@ -382,7 +383,7 @@ func testRerateExpProcessEventCDR3(t *testing.T) { }, } var reply string - if err := ng2RPC.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { + if err := ng2RPC.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -391,7 +392,7 @@ func testRerateExpProcessEventCDR3(t *testing.T) { func testRerateExpCheckCDRCostAfterProcessEvent3(t *testing.T) { var cdrs []*engine.CDR - if err := ng2RPC.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := ng2RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{ RunIDs: []string{"run_2"}, }}, &cdrs); err != nil { @@ -423,7 +424,7 @@ func testRerateExpGetAccountAfterProcessEvent3(t *testing.T) { } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := ng1RPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := ng1RPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else { expAcnt.UpdateTime = acnt.UpdateTime @@ -438,7 +439,7 @@ func testRerateExpGetAccountAfterProcessEvent3(t *testing.T) { func testRerateExpRerateCDRs(t *testing.T) { var reply string - if err := ng2RPC.Call(utils.CDRsV1RateCDRs, &engine.ArgRateCDRs{ + if err := ng2RPC.Call(context.Background(), utils.CDRsV1RateCDRs, &engine.ArgRateCDRs{ Flags: []string{utils.MetaRerate}, RPCCDRsFilter: utils.RPCCDRsFilter{ OrderBy: utils.AnswerTime, @@ -452,7 +453,7 @@ func testRerateExpRerateCDRs(t *testing.T) { func testRerateExpCheckCDRCostsAfterRerate(t *testing.T) { var cdrs []*engine.CDR - if err := ng2RPC.Call(utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ + if err := ng2RPC.Call(context.Background(), utils.CDRsV1GetCDRs, &utils.RPCCDRsFilterWithAPIOpts{ RPCCDRsFilter: &utils.RPCCDRsFilter{ CGRIDs: []string{ng1UUID, ng2UUID}, OrderBy: utils.AnswerTime, @@ -487,7 +488,7 @@ func testRerateExpGetAccountAfterRerate(t *testing.T) { } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := ng1RPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := ng1RPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else { expAcnt.UpdateTime = acnt.UpdateTime diff --git a/general_tests/resourcesv1_it_test.go b/general_tests/resourcesv1_it_test.go index c365cedb0..b359a6e99 100644 --- a/general_tests/resourcesv1_it_test.go +++ b/general_tests/resourcesv1_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -34,7 +35,7 @@ import ( var ( rlsV1CfgPath string rlsV1Cfg *config.CGRConfig - rlsV1Rpc *rpc.Client + rlsV1Rpc *birpc.Client rlsV1ConfDIR string //run tests for specific configuration sTestsRLSV1 = []func(t *testing.T){ @@ -122,7 +123,7 @@ func testV1RsSetProfile(t *testing.T) { }, } var result string - if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rls, &result); err != nil { + if err := rlsV1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rls, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -143,7 +144,7 @@ func testV1RsAllocate(t *testing.T) { }, } var reply string - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, cgrEv, &reply); err != nil { t.Error(err) } else if reply != "Account1Channels" { @@ -162,7 +163,7 @@ func testV1RsAllocate(t *testing.T) { utils.OptsResourcesUnits: 1, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, cgrEv2, &reply); err != nil { t.Error(err) } else if reply != "Account1Channels" { @@ -183,7 +184,7 @@ func testV1RsAuthorize(t *testing.T) { utils.OptsResourcesUsageID: "RandomUsageID", }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { t.Error(err) } @@ -217,7 +218,7 @@ func testV1RsAuthorize(t *testing.T) { utils.OptsResourcesUnits: 1, }, } - if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, + if err := rlsV1Rpc.Call(context.Background(), utils.ResourceSv1AuthorizeResources, &cgrEv, &reply2); err.Error() != "RESOURCE_UNAUTHORIZED" { t.Error(err) } diff --git a/general_tests/route_it_test.go b/general_tests/route_it_test.go index 501288147..2cc791d69 100644 --- a/general_tests/route_it_test.go +++ b/general_tests/route_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -37,7 +38,7 @@ import ( var ( splSv1CfgPath string splSv1Cfg *config.CGRConfig - splSv1Rpc *rpc.Client + splSv1Rpc *birpc.Client splPrf *v1.RouteWithAPIOpts splSv1ConfDIR string //run tests for specific configuration @@ -121,7 +122,7 @@ func testV1SplSRpcConn(t *testing.T) { func testV1SplSFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := splSv1Rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -129,7 +130,7 @@ func testV1SplSFromFolder(t *testing.T) { func testV1SplSSetRouteProfilesWithoutRatingPlanIDs(t *testing.T) { var reply *engine.RouteProfile - if err := splSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE2"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -151,12 +152,12 @@ func testV1SplSSetRouteProfilesWithoutRatingPlanIDs(t *testing.T) { }, } var result string - if err := splSv1Rpc.Call(utils.APIerSv1SetRouteProfile, splPrf, &result); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, splPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := splSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE2"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(splPrf.RouteProfile, reply) { @@ -174,11 +175,11 @@ func testV1SplSSetRouteProfilesWithoutRatingPlanIDs(t *testing.T) { }, } var suplsReply engine.SortedRoutesList - if err := splSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := splSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err == nil || err.Error() != utils.NewErrServerError(utils.ErrAccountNotFound).Error() { t.Error(err) } - if err := splSv1Rpc.Call(utils.APIerSv1RemoveRouteProfile, utils.TenantID{ + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1RemoveRouteProfile, utils.TenantID{ Tenant: splPrf.Tenant, ID: splPrf.ID, }, &result); err != nil { @@ -190,7 +191,7 @@ func testV1SplSSetRouteProfilesWithoutRatingPlanIDs(t *testing.T) { func testV1SplSAddNewRoutePrf(t *testing.T) { var reply *engine.RouteProfile - if err := splSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ResourceTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -228,12 +229,12 @@ func testV1SplSAddNewRoutePrf(t *testing.T) { }, } var result string - if err := splSv1Rpc.Call(utils.APIerSv1SetRouteProfile, splPrf, &result); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, splPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := splSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ResourceTest"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(splPrf.RouteProfile, reply) { @@ -261,7 +262,7 @@ func testV1SplSAddNewResPrf(t *testing.T) { }, } - if err := splSv1Rpc.Call(utils.APIerSv1SetResourceProfile, rPrf, &result); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -284,7 +285,7 @@ func testV1SplSAddNewResPrf(t *testing.T) { }, } - if err := splSv1Rpc.Call(utils.APIerSv1SetResourceProfile, rPrf2, &result); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rPrf2, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -307,7 +308,7 @@ func testV1SplSAddNewResPrf(t *testing.T) { }, } - if err := splSv1Rpc.Call(utils.APIerSv1SetResourceProfile, rPrf3, &result); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rPrf3, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -330,7 +331,7 @@ func testV1SplSAddNewResPrf(t *testing.T) { }, } - if err := splSv1Rpc.Call(utils.APIerSv1SetResourceProfile, rPrf4, &result); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1SetResourceProfile, rPrf4, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -352,7 +353,7 @@ func testV1SplSPopulateResUsage(t *testing.T) { utils.OptsResourcesUnits: 4, }, } - if err := splSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := splSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, cgrEv, &reply); err != nil { t.Error(err) } @@ -374,7 +375,7 @@ func testV1SplSPopulateResUsage(t *testing.T) { utils.OptsResourcesUnits: 7, }, } - if err := splSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := splSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, cgrEv, &reply); err != nil { t.Error(err) } @@ -396,7 +397,7 @@ func testV1SplSPopulateResUsage(t *testing.T) { utils.OptsResourcesUnits: 7, }, } - if err := splSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := splSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, cgrEv, &reply); err != nil { t.Error(err) } @@ -418,7 +419,7 @@ func testV1SplSPopulateResUsage(t *testing.T) { utils.OptsResourcesUnits: 7, }, } - if err := splSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := splSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, cgrEv, &reply); err != nil { t.Error(err) } @@ -439,7 +440,7 @@ func testV1SplSGetSortedRoutes(t *testing.T) { } expSupplierIDs := []string{"route3", "route2", "route1"} var suplsReply engine.SortedRoutesList - if err := splSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := splSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { @@ -460,7 +461,7 @@ func testV1SplSGetSortedRoutes(t *testing.T) { func testV1SplSAddNewRoutePrf2(t *testing.T) { var reply *engine.RouteProfile - if err := splSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ResourceDescendent"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -498,12 +499,12 @@ func testV1SplSAddNewRoutePrf2(t *testing.T) { }, } var result string - if err := splSv1Rpc.Call(utils.APIerSv1SetRouteProfile, splPrf, &result); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1SetRouteProfile, splPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := splSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := splSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ResourceDescendent"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(splPrf.RouteProfile, reply) { @@ -521,7 +522,7 @@ func testV1SplSGetSortedRoutes2(t *testing.T) { } expSupplierIDs := []string{"route1", "route3", "route2"} var suplsReply engine.SortedRoutesList - if err := splSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := splSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { @@ -553,7 +554,7 @@ func testV1SplSPopulateStats(t *testing.T) { "StatID": "Stat_Supplier1", }, } - if err := splSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -568,7 +569,7 @@ func testV1SplSPopulateStats(t *testing.T) { "StatID": "Stat_Supplier1", }, } - if err := splSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -578,7 +579,7 @@ func testV1SplSPopulateStats(t *testing.T) { expectedMetrics := map[string]string{ utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + "LoadReq": "2", } - if err := splSv1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := splSv1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_Supplier1"}}, &metrics); err != nil { t.Error(err) @@ -595,7 +596,7 @@ func testV1SplSPopulateStats(t *testing.T) { "StatID": "Stat_Supplier2", }, } - if err := splSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -610,13 +611,13 @@ func testV1SplSPopulateStats(t *testing.T) { "StatID": "Stat_Supplier2", }, } - if err := splSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) } - if err := splSv1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := splSv1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_Supplier2"}}, &metrics); err != nil { t.Error(err) @@ -633,7 +634,7 @@ func testV1SplSPopulateStats(t *testing.T) { "StatID": "Stat_Supplier3", }, } - if err := splSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -648,7 +649,7 @@ func testV1SplSPopulateStats(t *testing.T) { "StatID": "Stat_Supplier3", }, } - if err := splSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -663,7 +664,7 @@ func testV1SplSPopulateStats(t *testing.T) { "StatID": "Stat_Supplier3", }, } - if err := splSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := splSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expected) { t.Errorf("Expecting: %+v, received: %+v", expected, reply) @@ -673,7 +674,7 @@ func testV1SplSPopulateStats(t *testing.T) { utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + "LoadReq": "3", } - if err := splSv1Rpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := splSv1Rpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_Supplier3"}}, &metrics); err != nil { t.Error(err) @@ -719,7 +720,7 @@ func testV1SplSGetSoredRoutesWithLoad(t *testing.T) { } var suplsReply engine.SortedRoutesList - if err := splSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := splSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &suplsReply); err != nil { t.Error(err) } else { diff --git a/general_tests/routes_cases_it_test.go b/general_tests/routes_cases_it_test.go index 0d3bb5bf0..a002e7afe 100644 --- a/general_tests/routes_cases_it_test.go +++ b/general_tests/routes_cases_it_test.go @@ -22,13 +22,14 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "sort" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -38,7 +39,7 @@ import ( var ( rtsCaseSv1CfgPath string rtsCaseSv1Cfg *config.CGRConfig - rtsCaseSv1Rpc *rpc.Client + rtsCaseSv1Rpc *birpc.Client rtsCasePrf *v1.RouteWithAPIOpts rtsCaseSv1ConfDIR string //run tests for specific configuration @@ -134,7 +135,7 @@ func testV1RtsCaseRpcConn(t *testing.T) { func testV1RtsCaseFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutroutes")} - if err := rtsCaseSv1Rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -171,7 +172,7 @@ func testV1RtsCaseGetRoutesAfterLoading(t *testing.T) { }, } var reply *engine.RouteProfile - if err := rtsCaseSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ID: "ROUTE_ACNT_1001", Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) @@ -217,7 +218,7 @@ func testV1RtsCaseGetRoutesAfterLoading(t *testing.T) { }, }, } - if err := rtsCaseSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ID: "ROUTE_ACNT_1002", Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) @@ -257,7 +258,7 @@ func testV1RtsCaseGetRoutesAfterLoading(t *testing.T) { }, }, } - if err := rtsCaseSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ID: "ROUTE_ACNT_1003", Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) @@ -298,7 +299,7 @@ func testV1RtsCaseGetRoutesAfterLoading(t *testing.T) { }, }, } - if err := rtsCaseSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ID: "ROUTE_ACNT_1004", Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) @@ -334,7 +335,7 @@ func testV1RtsCaseGetRoutesAfterLoading(t *testing.T) { }, }, } - if err := rtsCaseSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ID: "ROUTE_ACNT_1005", Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) @@ -379,7 +380,7 @@ func testV1RtsCaseGetRoutesAfterLoading(t *testing.T) { }, }, } - if err := rtsCaseSv1Rpc.Call(utils.APIerSv1GetRouteProfile, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.APIerSv1GetRouteProfile, &utils.TenantID{ID: "ROUTE_HC1", Tenant: "cgrates.org"}, &reply); err != nil { t.Error(err) @@ -422,7 +423,7 @@ func testV1RtsCasesSortingRoutesWeightAccountValue(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expSrtdRoutes, reply) { @@ -472,7 +473,7 @@ func testV1RtsCasesSortingRoutesWeightAllRoutes(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expSrtdRoutes, reply) { @@ -492,7 +493,7 @@ func testV1RtsCasesSortingRoutesWeightNotMatchingValue(t *testing.T) { }, } var result string - if err := rtsCaseSv1Rpc.Call(utils.APIerSv1SetBalance, attrBal, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.APIerSv1SetBalance, attrBal, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -534,7 +535,7 @@ func testV1RtsCasesSortingRoutesWeightNotMatchingValue(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expSrtdRoutes, reply) { @@ -579,7 +580,7 @@ func testV1RtsCasesSortingRoutesLowestCost(t *testing.T) { } var reply *engine.SortedRoutesList //gonna match one route because the totalUsage by ne-allocated resources is 0 - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expSrtdRoutes, reply) { @@ -633,7 +634,7 @@ func testV1RtsCasesSortingRoutesLowestCostDefaultUsage(t *testing.T) { } var reply *engine.SortedRoutesList //gonna match one route because the totalUsage by ne-allocated resources is 0 - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expSrtdRoutes, reply) { @@ -655,7 +656,7 @@ func testV1RtsCasesSortingRoutesLCSetStatsAndResForMatching(t *testing.T) { }, } var reply string - if err := rtsCaseSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } else if reply != "RES_GRP1" { @@ -676,7 +677,7 @@ func testV1RtsCasesSortingRoutesLCSetStatsAndResForMatching(t *testing.T) { utils.Cost: 1.0, }, } - if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &result); err != nil { + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &result); err != nil { t.Error(err) } else { sort.Strings(result) @@ -734,7 +735,7 @@ func testV1RtsCasesSortingRoutesLowestCostStats(t *testing.T) { } var reply *engine.SortedRoutesList //gonna match one route because the totalUsage by ne-allocated resources is 0 - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expSrtdRoutes, reply) { @@ -756,7 +757,7 @@ func testV1RtsCasesSortingRoutesLowestCosMatchingAllRoutes(t *testing.T) { }, } var result string - if err := rtsCaseSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, evRes, &result); err != nil { t.Error(err) } else if result != "RES_GRP1" { @@ -815,7 +816,7 @@ func testV1RtsCasesSortingRoutesLowestCosMatchingAllRoutes(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expSrtdRoutes, reply) { @@ -871,7 +872,7 @@ func testV1RtsCasesSortingRoutesLowestCosMaxCost(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expSrtdRoutes, reply) { @@ -895,7 +896,7 @@ func testV1RtsCasesSortingRoutesLowestCosMaxCostNotMatch(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err) } @@ -917,7 +918,7 @@ func testV1RtsCasesSortingRoutesProcessMetrics(t *testing.T) { }, } var result []string - if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &result); err != nil { + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &result); err != nil { t.Error(err) } else { sort.Strings(expected) @@ -926,7 +927,7 @@ func testV1RtsCasesSortingRoutesProcessMetrics(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", expected, result) } } - if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &result); err != nil { + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &result); err != nil { t.Error(err) } else { sort.Strings(expected) @@ -949,7 +950,7 @@ func testV1RtsCasesSortingRoutesProcessMetrics(t *testing.T) { utils.Cost: 1.0, }, } - if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &result); err != nil { + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &result); err != nil { t.Error(err) } else { sort.Strings(expected) @@ -958,7 +959,7 @@ func testV1RtsCasesSortingRoutesProcessMetrics(t *testing.T) { t.Errorf("Expecting: %+v, received: %+v", expected, result) } } - if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &result); err != nil { + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &result); err != nil { t.Error(err) } else { sort.Strings(expected) @@ -1014,7 +1015,7 @@ func testV1RtsCasesSortingRoutesQOS(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expSrtdRoutes) { @@ -1036,7 +1037,7 @@ func testV1RtsCasesSortingRoutesQOSAllRoutes(t *testing.T) { }, } var result []string - if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &result); err != nil { + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &result); err != nil { t.Error(err) } @@ -1095,7 +1096,7 @@ func testV1RtsCasesSortingRoutesQOSAllRoutes(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expSrtdRoutes) { @@ -1116,7 +1117,7 @@ func testV1RtsCasesSortingRoutesQOSNotFound(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err) } @@ -1135,7 +1136,7 @@ func testV1RtsCasesSortingRoutesAllocateResources(t *testing.T) { }, } var reply string - if err := rtsCaseSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } else if reply != "RES_GRP1" { @@ -1153,7 +1154,7 @@ func testV1RtsCasesSortingRoutesAllocateResources(t *testing.T) { utils.OptsResourcesUnits: 7, }, } - if err := rtsCaseSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, ev, &reply); err != nil { t.Error(err) } else if reply != "RES_GRP2" { @@ -1193,7 +1194,7 @@ func testV1RtsCasesSortingRoutesReasNotAllRoutes(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expSrtdRoutes) { @@ -1214,7 +1215,7 @@ func testV1RtsCasesSortingRoutesReasAllRoutes(t *testing.T) { }, } var replyStr string - if err := rtsCaseSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, evRs, &replyStr); err != nil { t.Error(err) } else if replyStr != "RES_GRP1" { @@ -1259,7 +1260,7 @@ func testV1RtsCasesSortingRoutesReasAllRoutes(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expSrtdRoutes) { @@ -1282,9 +1283,9 @@ func testV1RtsCasesRoutesProcessStatsForLoadRtsSorting(t *testing.T) { utils.Cost: 1.8, }, } - if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) - } else if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + } else if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else { sort.Strings(expected) @@ -1305,9 +1306,9 @@ func testV1RtsCasesRoutesProcessStatsForLoadRtsSorting(t *testing.T) { utils.Cost: 1.8, }, } - if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) - } else if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + } else if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else { sort.Strings(expected) @@ -1330,7 +1331,7 @@ func testV1RtsCasesRoutesProcessStatsForLoadRtsSorting(t *testing.T) { utils.Cost: 0.77, }, } - if err := rtsCaseSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil { + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.StatSv1ProcessEvent, ev1, &reply); err != nil { t.Error(err) } else { sort.Strings(expected) @@ -1383,7 +1384,7 @@ func testV1RtsCasesRoutesLoadRtsSorting(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expSrtdRoutes) { @@ -1429,7 +1430,7 @@ func testV1RtsCasesSortRoutesHigherCostV2V3(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expSrtdRoutes) { @@ -1452,7 +1453,7 @@ func testV1RtsCasesSortRoutesHigherCostAllocateRes(t *testing.T) { utils.OptsResourcesUnits: 7, }, } - if err := rtsCaseSv1Rpc.Call(utils.ResourceSv1ReleaseResources, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.ResourceSv1ReleaseResources, evRs, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -1470,7 +1471,7 @@ func testV1RtsCasesSortRoutesHigherCostAllocateRes(t *testing.T) { utils.OptsResourcesUnits: 7, }, } - if err := rtsCaseSv1Rpc.Call(utils.ResourceSv1ReleaseResources, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.ResourceSv1ReleaseResources, evRs, &result); err != nil { t.Error(err) } else if result != utils.OK { @@ -1488,7 +1489,7 @@ func testV1RtsCasesSortRoutesHigherCostAllocateRes(t *testing.T) { utils.OptsResourcesUnits: 1, }, } - if err := rtsCaseSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, evRs, &result); err != nil { t.Error(err) } else if result != "RES_GRP2" { @@ -1507,7 +1508,7 @@ func testV1RtsCasesSortRoutesHigherCostAllocateRes(t *testing.T) { utils.OptsResourcesUnits: 4, }, } - if err := rtsCaseSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, evRs, &result); err != nil { t.Error(err) } else if result != "RES_GRP1" { @@ -1553,7 +1554,7 @@ func testV1RtsCasesSortRoutesHigherCostV1V3(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expSrtdRoutes) { @@ -1574,7 +1575,7 @@ func testV1RtsCasesSortRoutesHigherCostAllRoutes(t *testing.T) { }, } var result string - if err := rtsCaseSv1Rpc.Call(utils.ResourceSv1AllocateResources, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.ResourceSv1AllocateResources, evRs, &result); err != nil { t.Error(err) } else if result != "RES_GRP1" { @@ -1626,7 +1627,7 @@ func testV1RtsCasesSortRoutesHigherCostAllRoutes(t *testing.T) { }, } var reply *engine.SortedRoutesList - if err := rtsCaseSv1Rpc.Call(utils.RouteSv1GetRoutes, + if err := rtsCaseSv1Rpc.Call(context.Background(), utils.RouteSv1GetRoutes, ev, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expSrtdRoutes) { diff --git a/general_tests/rpccaching_it_test.go b/general_tests/rpccaching_it_test.go index 583fc9bd5..a08c714a7 100644 --- a/general_tests/rpccaching_it_test.go +++ b/general_tests/rpccaching_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -37,7 +38,7 @@ import ( var ( rpcCfgPath string rpcCfg *config.CGRConfig - rpcRpc *rpc.Client + rpcRpc *birpc.Client rpcConfDIR string //run tests for specific configuration sTestsRPCMethods = []func(t *testing.T){ @@ -127,7 +128,7 @@ func testRPCMethodsRpcConn(t *testing.T) { func testRPCMethodsFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := rpcRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := rpcRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -135,7 +136,7 @@ func testRPCMethodsFromFolder(t *testing.T) { func testRPCMethodsAddData(t *testing.T) { var resp string - if err := rpcRpc.Call(utils.APIerSv1RemoveThresholdProfile, + if err := rpcRpc.Call(context.Background(), utils.APIerSv1RemoveThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { @@ -147,7 +148,7 @@ func testRPCMethodsAddData(t *testing.T) { {Identifier: utils.MetaDisableAccount}, {Identifier: utils.MetaLog}, }} - if err := rpcRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := rpcRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -157,7 +158,7 @@ func testRPCMethodsAddData(t *testing.T) { {Identifier: utils.MetaEnableAccount}, {Identifier: utils.MetaLog}, }} - if err := rpcRpc.Call(utils.APIerSv2SetActions, attrsAA2, &reply); err != nil && err.Error() != utils.ErrExists.Error() { + if err := rpcRpc.Call(context.Background(), utils.APIerSv2SetActions, attrsAA2, &reply); err != nil && err.Error() != utils.ErrExists.Error() { t.Error("Got error on APIerSv2.SetActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions received: %s", reply) @@ -175,7 +176,7 @@ func testRPCMethodsAddData(t *testing.T) { ActionIDs: []string{"DISABLE_LOG"}, }, } - if err := rpcRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { + if err := rpcRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -192,7 +193,7 @@ func testRPCMethodsAddData(t *testing.T) { ActionIDs: []string{"ENABLE_LOG"}, }, } - if err := rpcRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl2, &reply); err != nil { + if err := rpcRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl2, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error("Unexpected reply returned", reply) @@ -221,7 +222,7 @@ func testRPCMethodsAuthorizeSession(t *testing.T) { } //authorize the session var rplyFirst sessions.V1AuthorizeReply - if err := rpcRpc.Call(utils.SessionSv1AuthorizeEvent, args, &rplyFirst); err != nil { + if err := rpcRpc.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rplyFirst); err != nil { t.Fatal(err) } if rplyFirst.MaxUsage == nil || *rplyFirst.MaxUsage != authUsage { @@ -239,7 +240,7 @@ func testRPCMethodsAuthorizeSession(t *testing.T) { }, } //process event - if err := rpcRpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, []string{"THD_AccDisableAndLog"}) { t.Errorf("Expecting ids: %s, received: %s", []string{"THD_AccDisableAndLog"}, ids) @@ -251,7 +252,7 @@ func testRPCMethodsAuthorizeSession(t *testing.T) { Tenant: "cgrates.org", Account: "1001", } - if err := rpcRpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := rpcRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.Disabled != true { t.Errorf("Expecting: true, received: %v", acnt.Disabled) @@ -259,7 +260,7 @@ func testRPCMethodsAuthorizeSession(t *testing.T) { //authorize again session (should take the response from cache) var rply sessions.V1AuthorizeReply - if err := rpcRpc.Call(utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { + if err := rpcRpc.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Fatal(err) } else if !reflect.DeepEqual(rply, rplyFirst) { t.Errorf("Expecting: %+v, \n received: %+v", @@ -270,7 +271,7 @@ func testRPCMethodsAuthorizeSession(t *testing.T) { time.Sleep(time.Second) //authorize again session (this time we expect to receive an error) - if err := rpcRpc.Call(utils.SessionSv1AuthorizeEvent, args, &rply); err == nil || err.Error() != "RALS_ERROR:ACCOUNT_DISABLED" { + if err := rpcRpc.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err == nil || err.Error() != "RALS_ERROR:ACCOUNT_DISABLED" { t.Error("Unexpected error returned", err) } @@ -284,7 +285,7 @@ func testRPCMethodsAuthorizeSession(t *testing.T) { }, } //process event - if err := rpcRpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, []string{"THD_AccEnableAndLog"}) { t.Errorf("Expecting ids: %s, received: %s", []string{"THD_AccEnableAndLog"}, ids) @@ -313,7 +314,7 @@ func testRPCMethodsInitSession(t *testing.T) { }, } var rplyFirst sessions.V1InitSessionReply - if err := rpcRpc.Call(utils.SessionSv1InitiateSession, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rplyFirst); err != nil { t.Error(err) } @@ -332,7 +333,7 @@ func testRPCMethodsInitSession(t *testing.T) { }, } //process event - if err := rpcRpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, []string{"THD_AccDisableAndLog"}) { t.Errorf("Expecting ids: %s, received: %s", []string{"THD_AccDisableAndLog"}, ids) @@ -344,14 +345,14 @@ func testRPCMethodsInitSession(t *testing.T) { Tenant: "cgrates.org", Account: "1001", } - if err := rpcRpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := rpcRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.Disabled != true { t.Errorf("Expecting: true, received: %v", acnt.Disabled) } var rply sessions.V1InitSessionReply - if err := rpcRpc.Call(utils.SessionSv1InitiateSession, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rply, rplyFirst) { @@ -362,7 +363,7 @@ func testRPCMethodsInitSession(t *testing.T) { //give time to CGRateS to delete the response from cache time.Sleep(time.Second) - if err := rpcRpc.Call(utils.SessionSv1InitiateSession, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err == nil || !(err.Error() == "RALS_ERROR:ACCOUNT_DISABLED" || err.Error() == utils.ErrExists.Error()) { // ErrExist -> initSession twice t.Error("Unexpected error returned", err) @@ -378,7 +379,7 @@ func testRPCMethodsInitSession(t *testing.T) { }, } //process event - if err := rpcRpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, []string{"THD_AccEnableAndLog"}) { t.Errorf("Expecting ids: %s, received: %s", []string{"THD_AccEnableAndLog"}, ids) @@ -407,7 +408,7 @@ func testRPCMethodsUpdateSession(t *testing.T) { }, } var rplyFirst sessions.V1UpdateSessionReply - if err := rpcRpc.Call(utils.SessionSv1UpdateSession, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1UpdateSession, args, &rplyFirst); err != nil { t.Error(err) } @@ -426,7 +427,7 @@ func testRPCMethodsUpdateSession(t *testing.T) { }, } //process event - if err := rpcRpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, []string{"THD_AccDisableAndLog"}) { t.Errorf("Expecting ids: %s, received: %s", []string{"THD_AccDisableAndLog"}, ids) @@ -438,14 +439,14 @@ func testRPCMethodsUpdateSession(t *testing.T) { Tenant: "cgrates.org", Account: "1001", } - if err := rpcRpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := rpcRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.Disabled != true { t.Errorf("Expecting: true, received: %v", acnt.Disabled) } var rply sessions.V1UpdateSessionReply - if err := rpcRpc.Call(utils.SessionSv1UpdateSession, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1UpdateSession, args, &rply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rply, rplyFirst) { @@ -456,7 +457,7 @@ func testRPCMethodsUpdateSession(t *testing.T) { //give time to CGRateS to delete the response from cache time.Sleep(time.Second) - if err := rpcRpc.Call(utils.SessionSv1UpdateSession, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1UpdateSession, args, &rply); err == nil || err.Error() != "RALS_ERROR:ACCOUNT_DISABLED" { t.Error("Unexpected error returned", err) } @@ -471,7 +472,7 @@ func testRPCMethodsUpdateSession(t *testing.T) { }, } //process event - if err := rpcRpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, []string{"THD_AccEnableAndLog"}) { t.Errorf("Expecting ids: %s, received: %s", []string{"THD_AccEnableAndLog"}, ids) @@ -499,7 +500,7 @@ func testRPCMethodsTerminateSession(t *testing.T) { }, } var rply string - if err := rpcRpc.Call(utils.SessionSv1TerminateSession, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } else if rply != utils.OK { @@ -509,7 +510,7 @@ func testRPCMethodsTerminateSession(t *testing.T) { //replace event with empty args.CGREvent.Event = map[string]any{} - if err := rpcRpc.Call(utils.SessionSv1TerminateSession, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } else if rply != utils.OK { @@ -519,7 +520,7 @@ func testRPCMethodsTerminateSession(t *testing.T) { //give time to CGRateS to delete the response from cache time.Sleep(time.Second) - if err := rpcRpc.Call(utils.SessionSv1TerminateSession, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err == nil || err.Error() != "MANDATORY_IE_MISSING: [OriginID]" { t.Error(err) } @@ -544,7 +545,7 @@ func testRPCMethodsProcessCDR(t *testing.T) { }, } var rply string - if err := rpcRpc.Call(utils.SessionSv1ProcessCDR, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1ProcessCDR, args, &rply); err != nil { t.Error(err) } else if rply != utils.OK { @@ -554,7 +555,7 @@ func testRPCMethodsProcessCDR(t *testing.T) { //verify the CDR var cdrs []*engine.CDR argsCDR := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}}} - if err := rpcRpc.Call(utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -562,7 +563,7 @@ func testRPCMethodsProcessCDR(t *testing.T) { //change originID so CGRID be different args.Event[utils.OriginID] = "testRPCMethodsProcessCDR2" // we should get response from cache - if err := rpcRpc.Call(utils.SessionSv1ProcessCDR, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1ProcessCDR, args, &rply); err != nil { t.Error(err) } else if rply != utils.OK { @@ -570,7 +571,7 @@ func testRPCMethodsProcessCDR(t *testing.T) { } time.Sleep(100 * time.Millisecond) //verify the CDR - if err := rpcRpc.Call(utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -581,7 +582,7 @@ func testRPCMethodsProcessCDR(t *testing.T) { //change originID so CGRID be different args.Event[utils.OriginID] = "testRPCMethodsProcessCDR3" - if err := rpcRpc.Call(utils.SessionSv1ProcessCDR, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1ProcessCDR, args, &rply); err != nil { t.Error(err) } else if rply != utils.OK { @@ -589,7 +590,7 @@ func testRPCMethodsProcessCDR(t *testing.T) { } time.Sleep(100 * time.Millisecond) //verify the CDR - if err := rpcRpc.Call(utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 2 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -618,7 +619,7 @@ func testRPCMethodsProcessEvent(t *testing.T) { }, } var rplyFirst sessions.V1ProcessMessageReply - if err := rpcRpc.Call(utils.SessionSv1ProcessMessage, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rplyFirst); err != nil { t.Error(err) } else if rplyFirst.MaxUsage == nil || *rplyFirst.MaxUsage != initUsage { @@ -636,7 +637,7 @@ func testRPCMethodsProcessEvent(t *testing.T) { }, } //process event - if err := rpcRpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, []string{"THD_AccDisableAndLog"}) { t.Errorf("Expecting ids: %s, received: %s", []string{"THD_AccDisableAndLog"}, ids) @@ -648,7 +649,7 @@ func testRPCMethodsProcessEvent(t *testing.T) { Tenant: "cgrates.org", Account: "1001", } - if err := rpcRpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { + if err := rpcRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil { t.Error(err) } else if acnt.Disabled != true { t.Errorf("Expecting: true, received: %v", acnt.Disabled) @@ -656,7 +657,7 @@ func testRPCMethodsProcessEvent(t *testing.T) { //get response from cache var rply sessions.V1ProcessMessageReply - if err := rpcRpc.Call(utils.SessionSv1ProcessMessage, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Error(err) } else if !reflect.DeepEqual(rply, rplyFirst) { @@ -667,7 +668,7 @@ func testRPCMethodsProcessEvent(t *testing.T) { //give time to CGRateS to delete the response from cache time.Sleep(time.Second) - if err := rpcRpc.Call(utils.SessionSv1ProcessMessage, + if err := rpcRpc.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rplyFirst); err == nil || err.Error() != "RALS_ERROR:ACCOUNT_DISABLED" { t.Error("Unexpected error returned", err) } @@ -682,7 +683,7 @@ func testRPCMethodsProcessEvent(t *testing.T) { }, } //process event - if err := rpcRpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil { t.Error(err) } else if !reflect.DeepEqual(ids, []string{"THD_AccEnableAndLog"}) { t.Errorf("Expecting ids: %s, received: %s", []string{"THD_AccEnableAndLog"}, ids) @@ -711,7 +712,7 @@ func testRPCMethodsCdrsProcessCDR(t *testing.T) { } var reply string - if err := rpcRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -720,7 +721,7 @@ func testRPCMethodsCdrsProcessCDR(t *testing.T) { //verify the CDR var cdrs []*engine.CDR argsCDR := utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}}} - if err := rpcRpc.Call(utils.CDRsV1GetCDRs, &argsCDR, &cdrs); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &argsCDR, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -728,14 +729,14 @@ func testRPCMethodsCdrsProcessCDR(t *testing.T) { //change originID so CGRID be different args.Event[utils.OriginID] = "testRPCMethodsProcessCDR2" // we should get response from cache - if err := rpcRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } time.Sleep(100 * time.Millisecond) //verify the CDR - if err := rpcRpc.Call(utils.CDRsV1GetCDRs, &argsCDR, &cdrs); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &argsCDR, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -745,14 +746,14 @@ func testRPCMethodsCdrsProcessCDR(t *testing.T) { time.Sleep(time.Second) //change originID so CGRID be different args.Event[utils.OriginID] = "testRPCMethodsProcessCDR4" - if err := rpcRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) } time.Sleep(150 * time.Millisecond) // Give time for CDR to be rated //verify the CDR - if err := rpcRpc.Call(utils.CDRsV1GetCDRs, &argsCDR, &cdrs); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV1GetCDRs, &argsCDR, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 2 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -783,7 +784,7 @@ func testRPCMethodsCdrsStoreSessionCost(t *testing.T) { } var reply string - if err := rpcRpc.Call(utils.CDRsV2StoreSessionCost, args, &reply); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV2StoreSessionCost, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -793,7 +794,7 @@ func testRPCMethodsCdrsStoreSessionCost(t *testing.T) { //change originID so CGRID be different args.Cost.CGRID = "testRPCMethodsCdrsStoreSessionCost" // we should get response from cache - if err := rpcRpc.Call(utils.CDRsV2StoreSessionCost, args, &reply); err != nil { + if err := rpcRpc.Call(context.Background(), utils.CDRsV2StoreSessionCost, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -803,7 +804,7 @@ func testRPCMethodsCdrsStoreSessionCost(t *testing.T) { time.Sleep(time.Second) //change originID so CGRID be different args.Cost.CGRID = "testRPCMethodsCdrsStoreSessionCost" - if err := rpcRpc.Call(utils.CDRsV2StoreSessionCost, args, + if err := rpcRpc.Call(context.Background(), utils.CDRsV2StoreSessionCost, args, &reply); err == nil || err.Error() != "SERVER_ERROR: EXISTS" { t.Error("Unexpected error: ", err.Error()) } @@ -812,7 +813,7 @@ func testRPCMethodsCdrsStoreSessionCost(t *testing.T) { // Load the tariff plan, creating accounts and their balances func testRPCMethodsLoadData(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testtp")} - if err := rpcRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &tpLoadInst); err != nil { + if err := rpcRpc.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &tpLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -834,7 +835,7 @@ func testRPCMethodsResponderDebit(t *testing.T) { } var cc engine.CallCost //cache the response - if err := rpcRpc.Call(utils.ResponderDebit, cd, &cc); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ResponderDebit, cd, &cc); err != nil { t.Error(err) } else if cc.GetDuration() != 15*time.Second { t.Errorf("Expecting: %+v, \n received: %+v", @@ -850,7 +851,7 @@ func testRPCMethodsResponderDebit(t *testing.T) { } var ccCache engine.CallCost //cache the response - if err := rpcRpc.Call(utils.ResponderDebit, cd2, &ccCache); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ResponderDebit, cd2, &ccCache); err != nil { t.Error(err) } else if !reflect.DeepEqual(ccCache, cc) { t.Errorf("Expecting: %+v, \n received: %+v", @@ -858,7 +859,7 @@ func testRPCMethodsResponderDebit(t *testing.T) { } //give time to CGRateS to delete the response from cache time.Sleep(time.Second) - if err := rpcRpc.Call(utils.ResponderDebit, cd2, &cc); err == nil || err.Error() != "ACCOUNT_NOT_FOUND" { + if err := rpcRpc.Call(context.Background(), utils.ResponderDebit, cd2, &cc); err == nil || err.Error() != "ACCOUNT_NOT_FOUND" { t.Error("Unexpected error returned", err) } } @@ -880,7 +881,7 @@ func testRPCMethodsResponderMaxDebit(t *testing.T) { } var cc engine.CallCost //cache the response - if err := rpcRpc.Call(utils.ResponderMaxDebit, cd, &cc); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ResponderMaxDebit, cd, &cc); err != nil { t.Error(err) } else if cc.GetDuration() != 15*time.Second { t.Errorf("Expecting: %+v, \n received: %+v", @@ -896,7 +897,7 @@ func testRPCMethodsResponderMaxDebit(t *testing.T) { } var ccCache engine.CallCost //cache the response - if err := rpcRpc.Call(utils.ResponderMaxDebit, cd2, &ccCache); err != nil { + if err := rpcRpc.Call(context.Background(), utils.ResponderMaxDebit, cd2, &ccCache); err != nil { t.Error(err) } else if !reflect.DeepEqual(ccCache, cc) { t.Errorf("Expecting: %+v, \n received: %+v", @@ -904,7 +905,7 @@ func testRPCMethodsResponderMaxDebit(t *testing.T) { } //give time to CGRateS to delete the response from cache time.Sleep(time.Second) - if err := rpcRpc.Call(utils.ResponderMaxDebit, cd2, &cc); err == nil || err.Error() != "ACCOUNT_NOT_FOUND" { + if err := rpcRpc.Call(context.Background(), utils.ResponderMaxDebit, cd2, &cc); err == nil || err.Error() != "ACCOUNT_NOT_FOUND" { t.Error("Unexpected error returned", err) } } diff --git a/general_tests/rpcclient_it_test.go b/general_tests/rpcclient_it_test.go index 504c8d97c..f620f405c 100644 --- a/general_tests/rpcclient_it_test.go +++ b/general_tests/rpcclient_it_test.go @@ -29,6 +29,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -119,14 +120,14 @@ func testRPCITLclStartSecondEngine(t *testing.T) { // Connect rpc client to rater func testRPCITLclRpcConnPoolFirst(t *testing.T) { rpcPoolFirst = rpcclient.NewRPCPool(rpcclient.PoolFirst, 0) - rpcRAL1, err = rpcclient.NewRPCClient(utils.TCP, rpcITCfg1.ListenCfg().RPCJSONListen, false, "", "", "", 3, 1, - time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) + rpcRAL1, err = rpcclient.NewRPCClient(context.Background(), utils.TCP, rpcITCfg1.ListenCfg().RPCJSONListen, false, "", "", "", 3, 1, + 0, utils.FibDuration, time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) if err == nil { t.Fatal("Should receive cannot connect error here") } rpcPoolFirst.AddClient(rpcRAL1) - rpcRAL2, err = rpcclient.NewRPCClient(utils.TCP, rpcITCfg2.ListenCfg().RPCJSONListen, false, "", "", "", 3, 1, - time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) + rpcRAL2, err = rpcclient.NewRPCClient(context.Background(), utils.TCP, rpcITCfg2.ListenCfg().RPCJSONListen, false, "", "", "", 3, 1, + 0, utils.FibDuration, time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) if err != nil { t.Fatal(err) } @@ -136,12 +137,12 @@ func testRPCITLclRpcConnPoolFirst(t *testing.T) { // Connect rpc client to rater func testRPCITLclStatusSecondEngine(t *testing.T) { var status map[string]any - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") } - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // Make sure second time we land on the same instance + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // Make sure second time we land on the same instance t.Error(err) } else if status[utils.NodeID].(string) != node2 { t.Errorf("Expecting:\n%s\nReceived:\n%s", node2, status[utils.NodeID].(string)) @@ -158,14 +159,14 @@ func testRPCITLclStartFirstEngine(t *testing.T) { // Connect rpc client to rater func testRPCITLclStatusFirstInitial(t *testing.T) { var status map[string]any - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") } else if status[utils.NodeID].(string) == node2 { t.Fatalf("Should receive ralID different than second one, got: %s", status[utils.NodeID].(string)) } - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // Make sure second time we land on the same instance + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // Make sure second time we land on the same instance t.Error(err) } else if status[utils.NodeID].(string) != node1 { t.Errorf("Expecting:\n%s\nReceived:\n%s", node1, status[utils.NodeID].(string)) @@ -179,14 +180,14 @@ func testRPCITLclStatusFirstFailover(t *testing.T) { } time.Sleep(time.Duration(*waitRater) * time.Millisecond) var status map[string]any - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") } else if status[utils.NodeID].(string) == node1 { t.Fatalf("Should receive ralID different than first one, got: %s", status[utils.NodeID].(string)) } - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // Make sure second time we land on the same instance + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // Make sure second time we land on the same instance t.Error(err) } else if status[utils.NodeID].(string) != node2 { t.Errorf("Expecting:\n%s\nReceived:\n%s", node2, status[utils.NodeID].(string)) @@ -198,12 +199,12 @@ func testRPCITLclStatusFirstFailback(t *testing.T) { t.Fatal(err) } var status map[string]any - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == node2 { t.Error("Should receive new ID") } - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // Make sure second time we land on the same instance + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // Make sure second time we land on the same instance t.Error(err) } else if status[utils.NodeID].(string) != node1 { t.Errorf("Expecting:\n%s\nReceived:\n%s", node2, status[utils.NodeID].(string)) @@ -213,14 +214,14 @@ func testRPCITLclStatusFirstFailback(t *testing.T) { // Make sure it executes on the first node supporting the command func testRPCITLclTDirectedRPC(t *testing.T) { var sessions []*sessions.ExternalSession - if err := rpcPoolFirst.Call(utils.SessionSv1GetActiveSessions, utils.SessionFilter{}, &sessions); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := rpcPoolFirst.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{}, &sessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } } // func testRPCITLclTimeout(t *testing.T) { // var status map[string]any -// if err := rpcPoolFirst.Call(utils.CoreSv1Status, "10s", &status); err == nil { +// if err := rpcPoolFirst.Call(context.Background(),utils.CoreSv1Status, "10s", &status); err == nil { // t.Error("Expecting timeout") // } else if err.Error() != rpcclient.ErrReplyTimeout.Error() { // t.Error(err) @@ -236,12 +237,12 @@ func testRPCITLclRpcConnPoolBcast(t *testing.T) { func testRPCITLclBcastStatusInitial(t *testing.T) { var status map[string]any - if err := rpcPoolBroadcast.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolBroadcast.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") } - if err := rpcPoolBroadcast.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolBroadcast.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") @@ -254,12 +255,12 @@ func testRPCITLclBcastStatusNoRals1(t *testing.T) { } time.Sleep(time.Duration(*waitRater) * time.Millisecond) var status map[string]any - if err := rpcPoolBroadcast.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolBroadcast.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") } - if err := rpcPoolBroadcast.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolBroadcast.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") @@ -272,7 +273,7 @@ func testRPCITLclBcastStatusBcastNoRals(t *testing.T) { } time.Sleep(time.Duration(*waitRater) * time.Millisecond) var status map[string]any - if err := rpcPoolBroadcast.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err == nil { + if err := rpcPoolBroadcast.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err == nil { t.Error("Should get error") } } @@ -282,12 +283,12 @@ func testRPCITLclBcastStatusRALs2Up(t *testing.T) { t.Fatal(err) } var status map[string]any - if err := rpcPoolBroadcast.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolBroadcast.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") } - if err := rpcPoolBroadcast.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolBroadcast.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") @@ -299,12 +300,12 @@ func testRPCITLclStatusBcastRALs1Up(t *testing.T) { t.Fatal(err) } var status map[string]any - if err := rpcPoolBroadcast.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolBroadcast.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty InstanceID received") } - if err := rpcPoolBroadcast.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolBroadcast.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty InstanceID received") @@ -314,30 +315,30 @@ func testRPCITLclStatusBcastRALs1Up(t *testing.T) { /* func TestRPCITStatusBcastCmd(t *testing.T) { var stats utils.CacheStats - if err := rpcRAL1.Call(utils.APIerSv2GetCacheStats, utils.AttrCacheStats{}, &stats); err != nil { + if err := rpcRAL1.Call(context.Background(),utils.APIerSv2GetCacheStats, utils.AttrCacheStats{}, &stats); err != nil { t.Error(err) } else if stats.LastRatingLoadID != utils.NotAvailable || stats.LastAccountingLoadID != utils.NotAvailable { t.Errorf("Received unexpected stats: %+v", stats) } var loadInst utils.LoadInstance attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(**dataDir, "tariffplans", "oldtutorial")} - if err := rpcRAL1.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := rpcRAL1.Call(context.Background(),utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } else if loadInst.RatingLoadID == "" || loadInst.AccountingLoadID == "" { t.Errorf("Empty loadId received, loadInstance: %+v", loadInst) } var reply string - if err := rpcPoolBroadcast.Call(utils.APIerSv1ReloadCache, utils.AttrReloadCache{}, &reply); err != nil { + if err := rpcPoolBroadcast.Call(context.Background(),utils.APIerSv1ReloadCache, utils.AttrReloadCache{}, &reply); err != nil { t.Error("Got error on APIerSv1.ReloadCache: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.ReloadCache got reply: ", reply) } - if err := rpcRAL1.Call(utils.APIerSv2GetCacheStats, utils.AttrCacheStats{}, &stats); err != nil { + if err := rpcRAL1.Call(context.Background(),utils.APIerSv2GetCacheStats, utils.AttrCacheStats{}, &stats); err != nil { t.Error(err) } else if stats.LastRatingLoadID != loadInst.RatingLoadID { t.Errorf("Received unexpected stats: %+v vs %+v", stats, loadInst) } - if err := rpcRAL2.Call(utils.APIerSv2GetCacheStats, utils.AttrCacheStats{}, &stats); err != nil { + if err := rpcRAL2.Call(context.Background(),utils.APIerSv2GetCacheStats, utils.AttrCacheStats{}, &stats); err != nil { t.Error(err) } else if stats.LastRatingLoadID != loadInst.RatingLoadID { t.Errorf("Received unexpected stats: %+v vs %+v", stats, loadInst) @@ -353,14 +354,14 @@ func TestRPCITRmtRpcConnPool(t *testing.T) { return } rpcPoolFirst = rpcclient.NewRPCPool(rpcclient.PoolFirst, 0) - rpcRALRmt, err := rpcclient.NewRPCClient(utils.TCP, RemoteRALsAddr1, false, "", "", "", 1, 1, - time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) + rpcRALRmt, err := rpcclient.NewRPCClient(context.Background(), utils.TCP, RemoteRALsAddr1, false, "", "", "", 1, 1, + 0, utils.FibDuration, time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) if err != nil { t.Fatal(err) } rpcPoolFirst.AddClient(rpcRALRmt) - rpcRAL1, err = rpcclient.NewRPCClient(utils.TCP, RemoteRALsAddr2, false, "", "", "", 1, 1, - time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) + rpcRAL1, err = rpcclient.NewRPCClient(context.Background(), utils.TCP, RemoteRALsAddr2, false, "", "", "", 1, 1, + 0, utils.FibDuration, time.Second, 2*time.Second, rpcclient.JSONrpc, nil, false, nil) if err != nil { t.Fatal(err) } @@ -372,12 +373,12 @@ func TestRPCITRmtStatusFirstInitial(t *testing.T) { return } var status map[string]any - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") } - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // Make sure second time we land on the same instance + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // Make sure second time we land on the same instance t.Error(err) } else if status[utils.NodeID].(string) != node1 { t.Errorf("Expecting:\n%s\nReceived:\n%s", node1, status[utils.NodeID].(string)) @@ -396,14 +397,14 @@ func TestRPCITRmtStatusFirstFailover(t *testing.T) { } fmt.Println("\n\nExecuting query ...") var status map[string]any - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") } else if status[utils.NodeID].(string) == node1 { t.Fatal("Did not failover") } - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") @@ -424,14 +425,14 @@ func TestRPCITRmtStatusFirstFailback(t *testing.T) { } fmt.Println("\n\nExecuting query ...") var status map[string]any - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") } else if status[utils.NodeID].(string) == node2 { t.Fatal("Did not do failback") } - if err := rpcPoolFirst.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { + if err := rpcPoolFirst.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { t.Error(err) } else if status[utils.NodeID].(string) == "" { t.Error("Empty NodeID received") diff --git a/general_tests/sentinel_it_test.go b/general_tests/sentinel_it_test.go index ba3756e38..fda87c25a 100644 --- a/general_tests/sentinel_it_test.go +++ b/general_tests/sentinel_it_test.go @@ -23,7 +23,6 @@ package general_tests import ( "flag" - "net/rpc" "os" "os/exec" "path" @@ -31,6 +30,8 @@ import ( "strconv" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -43,7 +44,7 @@ var ( sentinel2ConfigPath = path.Join(*dataDir, "redisSentinel", "sentinel2.conf") engineConfigPath = path.Join(*dataDir, "conf", "samples", "redisSentinel") sentinelConfig *config.CGRConfig - sentinelRPC *rpc.Client + sentinelRPC *birpc.Client node1Exec *exec.Cmd node2Exec *exec.Cmd stlExec1 *exec.Cmd @@ -154,13 +155,13 @@ func testRedisSentinelSetGetAttribute(t *testing.T) { } alsPrf.Compile() var result string - if err := sentinelRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := sentinelRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } var reply *engine.AttributeProfile - if err := sentinelRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := sentinelRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil { t.Fatal(err) } @@ -190,7 +191,7 @@ func testRedisSentinelInsertion(t *testing.T) { var result string addFunc := func(t *testing.T, nrFail *int) { alsPrf.ID = orgiginID + strconv.Itoa(index) - if err := sentinelRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { + if err := sentinelRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil { if err.Error() == "SERVER_ERROR: EOF" { *nrFail = *nrFail + 1 } else { @@ -280,7 +281,7 @@ func testRedisSentinelGetAttrAfterFailover(t *testing.T) { } alsPrf.Compile() var reply *engine.AttributeProfile - if err := sentinelRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := sentinelRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil { t.Fatal(err) } diff --git a/general_tests/session2_it_test.go b/general_tests/session2_it_test.go index 918ec0310..da52de941 100644 --- a/general_tests/session2_it_test.go +++ b/general_tests/session2_it_test.go @@ -22,11 +22,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -37,7 +38,7 @@ var ( ses2CfgDir string ses2CfgPath string ses2Cfg *config.CGRConfig - ses2RPC *rpc.Client + ses2RPC *birpc.Client ses2Tests = []func(t *testing.T){ testSes2ItLoadConfig, @@ -110,7 +111,7 @@ func testSes2ItRPCConn(t *testing.T) { func testSes2ItLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := ses2RPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := ses2RPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -128,7 +129,7 @@ func testSes2ItInitSession(t *testing.T) { }, } var reply string - if err := ses2RPC.Call(utils.APIerSv2SetBalance, + if err := ses2RPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Fatal(err) } @@ -154,7 +155,7 @@ func testSes2ItInitSession(t *testing.T) { }, } var initRpl *sessions.V1InitSessionReply - if err := ses2RPC.Call(utils.SessionSv1InitiateSession, + if err := ses2RPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Fatal(err) } @@ -163,14 +164,14 @@ func testSes2ItInitSession(t *testing.T) { func testSes2ItAsActiveSessions(t *testing.T) { var count int - if err := ses2RPC.Call(utils.SessionSv1GetActiveSessionsCount, utils.SessionFilter{ + if err := ses2RPC.Call(context.Background(), utils.SessionSv1GetActiveSessionsCount, utils.SessionFilter{ Filters: []string{"*string:~*req.Account:1001"}, }, &count); err != nil { t.Fatal(err) } else if count != 2 { // 2 chargers t.Errorf("Expected 2 session received %v session(s)", count) } - if err := ses2RPC.Call(utils.SessionSv1GetActiveSessionsCount, utils.SessionFilter{ + if err := ses2RPC.Call(context.Background(), utils.SessionSv1GetActiveSessionsCount, utils.SessionFilter{ Filters: []string{"*string:~*req.Account:1002"}, }, &count); err != nil { t.Fatal(err) @@ -207,20 +208,20 @@ func testSes2StirAuthenticate(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := ses2RPC.Call(utils.SessionSv1ProcessEvent, + if err := ses2RPC.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { // no error verificated with success t.Error(err) } // altered originator args.APIOpts[utils.OptsStirOriginatorTn] = "1005" - if err := ses2RPC.Call(utils.SessionSv1ProcessEvent, + if err := ses2RPC.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err == nil || err.Error() != "*stir_authenticate: wrong originatorTn" { t.Errorf("Expected error :%q ,receved: %v", "*stir_authenticate: wrong originatorTn", err) } // altered identity args.APIOpts[utils.OptsStirIdentity] = "eyJhbGciOiJFUzI1NiIsInBwdCI6InNoYWtlbiIsInR5cCI6InBhc3Nwb3J0IiwieDV1IjoiL3Vzci9zaGFyZS9jZ3JhdGVzL3N0aXIvc3Rpcl9wdWJrZXkucGVtIn0.eyJhdHRlc3QiOiJBIiwiZGVzdCI6eyJ0biI6WyIxMDAyIl19LCJpYXQiOjE1ODcwMzg4MDIsIm9yaWciOnsidG4iOiIxMDA1In0sIm9yaWdpZCI6IjEyMzQ1NiJ9.cMEMlFnfyTu8uxfeU4RoZTamA7ifFT9Ibwrvi1_LKwL2xAU6fZ_CSIxKbtyOpNhM_sV03x7CfA_v0T4sHkifzg;info=;ppt=shaken" - if err := ses2RPC.Call(utils.SessionSv1ProcessEvent, + if err := ses2RPC.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err == nil || err.Error() != "*stir_authenticate: crypto/ecdsa: verification error" { t.Errorf("Expected error :%q ,receved: %v", "*stir_authenticate: crypto/ecdsa: verification error", err) } @@ -249,7 +250,7 @@ func testSes2StirInit(t *testing.T) { }, } var rply sessions.V1ProcessEventReply - if err := ses2RPC.Call(utils.SessionSv1ProcessEvent, + if err := ses2RPC.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { // no error verificated with success t.Error(err) } @@ -260,7 +261,7 @@ func testSes2StirInit(t *testing.T) { func testSes2STIRAuthenticate(t *testing.T) { var rply string - if err := ses2RPC.Call(utils.SessionSv1STIRAuthenticate, + if err := ses2RPC.Call(context.Background(), utils.SessionSv1STIRAuthenticate, &sessions.V1STIRAuthenticateArgs{ Attest: []string{"A"}, PayloadMaxDuration: "-1", @@ -288,7 +289,7 @@ func testSes2STIRIdentity(t *testing.T) { OverwriteIAT: true, } var rply string - if err := ses2RPC.Call(utils.SessionSv1STIRIdentity, + if err := ses2RPC.Call(context.Background(), utils.SessionSv1STIRIdentity, args, &rply); err != nil { t.Error(err) } diff --git a/general_tests/session3_it_test.go b/general_tests/session3_it_test.go index 8329e41e1..2ddacfe3d 100644 --- a/general_tests/session3_it_test.go +++ b/general_tests/session3_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -38,7 +39,7 @@ var ( ses3CfgDir string ses3CfgPath string ses3Cfg *config.CGRConfig - ses3RPC *rpc.Client + ses3RPC *birpc.Client ses3Tests = []func(t *testing.T){ testSes3ItLoadConfig, @@ -117,7 +118,7 @@ func testSes3ItRPCConn(t *testing.T) { func testSes3ItLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := ses3RPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := ses3RPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -153,7 +154,7 @@ func testSes3ItProcessEvent(t *testing.T) { }, } var rply sessions.V1ProcessMessageReply - if err := ses3RPC.Call(utils.SessionSv1ProcessMessage, + if err := ses3RPC.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -208,7 +209,7 @@ func testSes3ItProcessEvent(t *testing.T) { func testSes3ItThreshold1002After(t *testing.T) { var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1001", Hits: 1} - if err := ses3RPC.Call(utils.ThresholdSv1GetThreshold, + if err := ses3RPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd.Tenant, td.Tenant) { @@ -228,7 +229,7 @@ func testSes3ItStatMetricsAfter(t *testing.T) { utils.MetaTCD: "5m0s", } - if err := ses3RPC.Call(utils.StatSv1GetQueueStringMetrics, + if err := ses3RPC.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_1"}}, &metrics); err != nil { t.Error(err) } @@ -240,7 +241,7 @@ func testSes3ItStatMetricsAfter(t *testing.T) { func testSes3ItThreshold1002After2(t *testing.T) { var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1001", Hits: 2} - if err := ses3RPC.Call(utils.ThresholdSv1GetThreshold, + if err := ses3RPC.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd.Tenant, td.Tenant) { @@ -260,7 +261,7 @@ func testSes3ItStatMetricsAfter2(t *testing.T) { utils.MetaTCD: "10m0s", } - if err := ses3RPC.Call(utils.StatSv1GetQueueStringMetrics, + if err := ses3RPC.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_1"}}, &metrics); err != nil { t.Error(err) } @@ -281,7 +282,7 @@ func testSes3ItAddVoiceBalance(t *testing.T) { }, } var reply string - if err := ses3RPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := ses3RPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -291,7 +292,7 @@ func testSes3ItAddVoiceBalance(t *testing.T) { Tenant: "cgrates.org", Account: "1002", } - if err := ses3RPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := ses3RPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != float64(5*time.Second) { t.Errorf("Expecting: %v, received: %v", @@ -323,7 +324,7 @@ func testSes3ItTerminatWithoutInit(t *testing.T) { }, } var rply string - if err := ses3RPC.Call(utils.SessionSv1TerminateSession, + if err := ses3RPC.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } @@ -354,7 +355,7 @@ func testSes3ItTerminatWithoutInit(t *testing.T) { }, } var rply1 sessions.V1InitSessionReply - if err := ses3RPC.Call(utils.SessionSv1InitiateSession, + if err := ses3RPC.Call(context.Background(), utils.SessionSv1InitiateSession, args1, &rply1); err != nil { t.Error(err) return @@ -363,7 +364,7 @@ func testSes3ItTerminatWithoutInit(t *testing.T) { } time.Sleep(5 * time.Millisecond) aSessions := make([]*sessions.ExternalSession, 0) - if err := ses3RPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || + if err := ses3RPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -375,7 +376,7 @@ func testSes3ItBalance(t *testing.T) { Tenant: "cgrates.org", Account: "1002", } - if err := ses3RPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := ses3RPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != float64(3*time.Second) { t.Errorf("Expecting: %v, received: %v", @@ -385,7 +386,7 @@ func testSes3ItBalance(t *testing.T) { func testSes3ItCDRs(t *testing.T) { var reply string - if err := ses3RPC.Call(utils.SessionSv1ProcessCDR, &utils.CGREvent{ + if err := ses3RPC.Call(context.Background(), utils.SessionSv1ProcessCDR, &utils.CGREvent{ Tenant: "cgrates.org", ID: "TestSesItProccesCDR", Event: map[string]any{ @@ -410,7 +411,7 @@ func testSes3ItCDRs(t *testing.T) { var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, Accounts: []string{"1002"}} - if err := ses3RPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := ses3RPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) diff --git a/general_tests/session4_it_test.go b/general_tests/session4_it_test.go index 98f3539b2..f66e3dfde 100644 --- a/general_tests/session4_it_test.go +++ b/general_tests/session4_it_test.go @@ -22,11 +22,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ var ( ses4CfgDir string ses4CfgPath string ses4Cfg *config.CGRConfig - ses4RPC *rpc.Client + ses4RPC *birpc.Client ses4Tests = []func(t *testing.T){ testSes4ItLoadConfig, @@ -107,7 +108,7 @@ func testSes4ItRPCConn(t *testing.T) { func testSes4ItLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := ses4RPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := ses4RPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -116,7 +117,7 @@ func testSes4ItLoadFromFolder(t *testing.T) { func testSes4SetAccount(t *testing.T) { var reply string attrs := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "dan7"} - if err := ses4RPC.Call(utils.APIerSv1SetAccount, attrs, &reply); err != nil { + if err := ses4RPC.Call(context.Background(), utils.APIerSv1SetAccount, attrs, &reply); err != nil { t.Error("Got error on APIerSv1.SetAccount: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv1.SetAccount received: %s", reply) @@ -149,7 +150,7 @@ func testSes4CDRsProcessCDR(t *testing.T) { // Process and store the given CDR. var reply string - if err := ses4RPC.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := ses4RPC.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -157,7 +158,7 @@ func testSes4CDRsProcessCDR(t *testing.T) { // Process the CDR again, after adding the *rerate flag. args.Flags = append(args.Flags, utils.MetaRerate) - if err := ses4RPC.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil { + if err := ses4RPC.Call(context.Background(), utils.CDRsV1ProcessEvent, args, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) diff --git a/general_tests/session_graceful_shutdown_it_test.go b/general_tests/session_graceful_shutdown_it_test.go index 5339042d7..b9d3af41d 100644 --- a/general_tests/session_graceful_shutdown_it_test.go +++ b/general_tests/session_graceful_shutdown_it_test.go @@ -21,7 +21,6 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "os/exec" "path" "reflect" @@ -29,6 +28,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/sessions" @@ -43,7 +44,7 @@ var ( smgRplcCfgPath1, smgRplcCfgPath2 string smgRplcCfgDIR1, smgRplcCfgDIR2 string smgRplCfg1, smgRplCfg2 *config.CGRConfig - smgRplcRPC1, smgRplcRPC2 *rpc.Client + smgRplcRPC1, smgRplcRPC2 *birpc.Client testEngine1, testEngine2 *exec.Cmd sTestsSession1 = []func(t *testing.T){ testSessionSRplcInitCfg, @@ -129,11 +130,11 @@ func testSessionSRplcApierRpcConn(t *testing.T) { func testSessionSRplcApierGetActiveSessionsNotFound(t *testing.T) { aSessions1 := make([]*sessions.ExternalSession, 0) expected := "NOT_FOUND" - if err := smgRplcRPC1.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions1); err == nil || err.Error() != expected { + if err := smgRplcRPC1.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions1); err == nil || err.Error() != expected { t.Error(err) } aSessions2 := make([]*sessions.ExternalSession, 0) - if err := smgRplcRPC2.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions2); err == nil || err.Error() != expected { + if err := smgRplcRPC2.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions2); err == nil || err.Error() != expected { t.Error(err) } } @@ -149,7 +150,7 @@ func testSessionSRplcApierSetChargerS(t *testing.T) { }, } var result1 string - if err := smgRplcRPC1.Call(utils.APIerSv1SetChargerProfile, chargerProfile1, &result1); err != nil { + if err := smgRplcRPC1.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile1, &result1); err != nil { t.Error(err) } else if result1 != utils.OK { t.Error("Unexpected reply returned", result1) @@ -165,7 +166,7 @@ func testSessionSRplcApierSetChargerS(t *testing.T) { }, } var result2 string - if err := smgRplcRPC2.Call(utils.APIerSv1SetChargerProfile, chargerProfile2, &result2); err != nil { + if err := smgRplcRPC2.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile2, &result2); err != nil { t.Error(err) } else if result2 != utils.OK { t.Error("Unexpected reply returned", result2) @@ -187,7 +188,7 @@ func testSessionSRplcApierGetInitateSessions(t *testing.T) { }, } var rply sessions.V1InitSessionReply - if err := smgRplcRPC2.Call(utils.SessionSv1InitiateSession, + if err := smgRplcRPC2.Call(context.Background(), utils.SessionSv1InitiateSession, args, &rply); err != nil { t.Error(err) } @@ -223,7 +224,7 @@ func testSessionSRplcApierGetActiveSessions(t *testing.T) { }, } aSessions2 := make([]*sessions.ExternalSession, 0) - if err := smgRplcRPC2.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions2); err != nil { + if err := smgRplcRPC2.Call(context.Background(), utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions2); err != nil { t.Error(err) } if !reflect.DeepEqual(&aSessions2, &expected) { @@ -262,7 +263,7 @@ func testSessionSRplcApierGetPassiveSessions(t *testing.T) { }, } aSessions2 := make([]*sessions.ExternalSession, 0) - if err := smgRplcRPC1.Call(utils.SessionSv1GetPassiveSessions, &utils.SessionFilter{}, &aSessions2); err != nil { + if err := smgRplcRPC1.Call(context.Background(), utils.SessionSv1GetPassiveSessions, &utils.SessionFilter{}, &aSessions2); err != nil { t.Error(err) } if !reflect.DeepEqual(&aSessions2, &expected) { @@ -312,7 +313,7 @@ func testSessionSRplcApierGetPassiveSessionsAfterStop(t *testing.T) { }, } aSessions2 := make([]*sessions.ExternalSession, 0) - if err := smgRplcRPC1.Call(utils.SessionSv1GetPassiveSessions, &utils.SessionFilter{}, &aSessions2); err != nil { + if err := smgRplcRPC1.Call(context.Background(), utils.SessionSv1GetPassiveSessions, &utils.SessionFilter{}, &aSessions2); err != nil { t.Error(err) } if !reflect.DeepEqual(&aSessions2, &expected) { diff --git a/general_tests/session_it_test.go b/general_tests/session_it_test.go index c3aadbe90..936e486a2 100644 --- a/general_tests/session_it_test.go +++ b/general_tests/session_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -36,7 +37,7 @@ var ( sesCfgPath string sesCfgDIR string sesCfg *config.CGRConfig - sesRPC *rpc.Client + sesRPC *birpc.Client sesAccount = "refundAcc" sesTenant = "cgrates.org" @@ -109,7 +110,7 @@ func testSesItRPCConn(t *testing.T) { func testSesItLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := sesRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := sesRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -121,7 +122,7 @@ func testAccountBalance2(t *testing.T, sracc, srten, balType string, expected fl Tenant: srten, Account: sracc, } - if err := sesRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sesRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[balType].GetTotalValue(); rply != expected { t.Errorf("Expecting: %v, received: %v", @@ -141,7 +142,7 @@ func testSesItAddVoiceBalance(t *testing.T) { }, } var reply string - if err := sesRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sesRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -171,7 +172,7 @@ func testSesItInitSession(t *testing.T) { }, } var rply1 sessions.V1InitSessionReply - if err := sesRPC.Call(utils.SessionSv1InitiateSession, + if err := sesRPC.Call(context.Background(), utils.SessionSv1InitiateSession, args1, &rply1); err != nil { t.Error(err) return @@ -203,7 +204,7 @@ func testSesItTerminateSession(t *testing.T) { }, } var rply string - if err := sesRPC.Call(utils.SessionSv1TerminateSession, + if err := sesRPC.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } @@ -211,7 +212,7 @@ func testSesItTerminateSession(t *testing.T) { t.Errorf("Unexpected reply: %s", rply) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sesRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || + if err := sesRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/general_tests/session_money_rating_subject_it_test.go b/general_tests/session_money_rating_subject_it_test.go index 90268c1a2..79195a8d1 100644 --- a/general_tests/session_money_rating_subject_it_test.go +++ b/general_tests/session_money_rating_subject_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -36,7 +37,7 @@ var ( sesMRSCfgPath string sesMRSCfgDIR string sesMRSCfg *config.CGRConfig - sesMRSRPC *rpc.Client + sesMRSRPC *birpc.Client sesMRSAccount = "refundAcc" sesMRSTenant = "cgrates.org" @@ -134,7 +135,7 @@ func testSesMRSItLoadFromFolder(t *testing.T) { Weight: 20, } var result string - if err := sesMRSRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := sesMRSRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -153,7 +154,7 @@ func testSesMRSItAddVoiceBalance(t *testing.T) { }, } var reply string - if err := sesMRSRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sesMRSRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -170,14 +171,14 @@ func testSesMRSItAddVoiceBalance(t *testing.T) { utils.Weight: 10, }, } - if err := sesMRSRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sesMRSRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } var acnt engine.Account - if err := sesMRSRPC.Call(utils.APIerSv2GetAccount, + if err := sesMRSRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: sesMRSTenant, Account: sesMRSAccount, @@ -197,7 +198,7 @@ func testSesMRSItAddVoiceBalance(t *testing.T) { func testSesMRSItInitSession(t *testing.T) { sesMRSCgrEv.Event[utils.Usage] = time.Second var rply sessions.V1InitSessionReply - if err := sesMRSRPC.Call(utils.SessionSv1InitiateSession, + if err := sesMRSRPC.Call(context.Background(), utils.SessionSv1InitiateSession, &sessions.V1InitSessionArgs{ InitSession: true, CGREvent: sesMRSCgrEv, @@ -213,7 +214,7 @@ func testSesMRSItInitSession(t *testing.T) { func testSesMRSItTerminateSession(t *testing.T) { sesMRSCgrEv.Event[utils.Usage] = 10 * time.Second var rply string - if err := sesMRSRPC.Call(utils.SessionSv1TerminateSession, + if err := sesMRSRPC.Call(context.Background(), utils.SessionSv1TerminateSession, &sessions.V1TerminateSessionArgs{ TerminateSession: true, CGREvent: sesMRSCgrEv, @@ -224,13 +225,13 @@ func testSesMRSItTerminateSession(t *testing.T) { t.Errorf("Unexpected reply: %s", rply) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sesMRSRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || + if err := sesMRSRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } var acnt engine.Account - if err := sesMRSRPC.Call(utils.APIerSv2GetAccount, + if err := sesMRSRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: sesMRSTenant, Account: sesMRSAccount, diff --git a/general_tests/session_nonereq_it_test.go b/general_tests/session_nonereq_it_test.go index e0a6b6dda..8be52e971 100644 --- a/general_tests/session_nonereq_it_test.go +++ b/general_tests/session_nonereq_it_test.go @@ -22,11 +22,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -38,7 +39,7 @@ var ( sesNoneReqTypeCfgDir string sesNoneReqTypeCfgPath string sesNoneReqTypeCfg *config.CGRConfig - sesNoneReqTypeRPC *rpc.Client + sesNoneReqTypeRPC *birpc.Client sesNoneReqTypeTests = []func(t *testing.T){ testSesNoneReqTypeItLoadConfig, @@ -117,7 +118,7 @@ func testSesNoneReqTypeItAddChargerS(t *testing.T) { }, } var result string - if err := sesNoneReqTypeRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := sesNoneReqTypeRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -148,7 +149,7 @@ func testSesNoneReqTypeItInit(t *testing.T) { }, } var rply1 sessions.V1InitSessionReply - if err := sesNoneReqTypeRPC.Call(utils.SessionSv1InitiateSession, + if err := sesNoneReqTypeRPC.Call(context.Background(), utils.SessionSv1InitiateSession, args1, &rply1); err != nil { t.Error(err) return diff --git a/general_tests/session_refund_expired_it_test.go b/general_tests/session_refund_expired_it_test.go index 5912e27ed..2adfb7417 100644 --- a/general_tests/session_refund_expired_it_test.go +++ b/general_tests/session_refund_expired_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -36,7 +37,7 @@ var ( sesExpCfgPath string sesExpCfgDIR string sesExpCfg *config.CGRConfig - sesExpRPC *rpc.Client + sesExpRPC *birpc.Client sesExpAccount = "refundAcc" sesExpTenant = "cgrates.org" @@ -137,7 +138,7 @@ func testSesExpItLoadFromFolder(t *testing.T) { Weight: 20, } var result string - if err := sesExpRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := sesExpRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) @@ -156,7 +157,7 @@ func testSesExpItAddVoiceBalance(t *testing.T) { }, } var reply string - if err := sesExpRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sesExpRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -173,14 +174,14 @@ func testSesExpItAddVoiceBalance(t *testing.T) { utils.Weight: 100, }, } - if err := sesExpRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sesExpRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } var acnt engine.Account - if err := sesExpRPC.Call(utils.APIerSv2GetAccount, + if err := sesExpRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: sesExpTenant, Account: sesExpAccount, @@ -196,7 +197,7 @@ func testSesExpItAddVoiceBalance(t *testing.T) { func testSesExpItInitSession(t *testing.T) { sesExpCgrEv.Event[utils.Usage] = time.Second var rply sessions.V1InitSessionReply - if err := sesExpRPC.Call(utils.SessionSv1InitiateSession, + if err := sesExpRPC.Call(context.Background(), utils.SessionSv1InitiateSession, &sessions.V1InitSessionArgs{ InitSession: true, CGREvent: sesExpCgrEv, @@ -212,7 +213,7 @@ func testSesExpItInitSession(t *testing.T) { func testSesExpItTerminateSession(t *testing.T) { sesExpCgrEv.Event[utils.Usage] = 10 * time.Second var rply string - if err := sesExpRPC.Call(utils.SessionSv1TerminateSession, + if err := sesExpRPC.Call(context.Background(), utils.SessionSv1TerminateSession, &sessions.V1TerminateSessionArgs{ TerminateSession: true, CGREvent: sesExpCgrEv, @@ -223,13 +224,13 @@ func testSesExpItTerminateSession(t *testing.T) { t.Errorf("Unexpected reply: %s", rply) } aSessions := make([]*sessions.ExternalSession, 0) - if err := sesExpRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || + if err := sesExpRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } var acnt engine.Account - if err := sesExpRPC.Call(utils.APIerSv2GetAccount, + if err := sesExpRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: sesExpTenant, Account: sesExpAccount, @@ -244,7 +245,7 @@ func testSesExpItTerminateSession(t *testing.T) { func testSesExpItProcessCDR(t *testing.T) { var reply string - if err := sesExpRPC.Call(utils.SessionSv1ProcessCDR, + if err := sesExpRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, sesExpCgrEv, &reply); err != nil { t.Error(err) } else if reply != utils.OK { @@ -253,7 +254,7 @@ func testSesExpItProcessCDR(t *testing.T) { time.Sleep(20 * time.Millisecond) var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Accounts: []string{sesExpAccount}} - if err := sesExpRPC.Call(utils.APIerSv2GetCDRs, req, &cdrs); err != nil { + if err := sesExpRPC.Call(context.Background(), utils.APIerSv2GetCDRs, req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Fatal("Wrong number of CDRs") @@ -267,7 +268,7 @@ func testSesExpItRerate(t *testing.T) { var reply string sesExpCgrEv.Event[utils.Usage] = time.Second sesExpCgrEv.Event[utils.RequestType] = utils.MetaPostpaid // change the request type in order to not wait 12s to check the cost for a closed session - if err := sesExpRPC.Call(utils.CDRsV1ProcessEvent, + if err := sesExpRPC.Call(context.Background(), utils.CDRsV1ProcessEvent, &engine.ArgV1ProcessEvent{ Flags: []string{utils.MetaRerate}, CGREvent: *sesExpCgrEv, @@ -277,7 +278,7 @@ func testSesExpItRerate(t *testing.T) { t.Error("Unexpected reply received: ", reply) } var acnt engine.Account - if err := sesExpRPC.Call(utils.APIerSv2GetAccount, + if err := sesExpRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: sesExpTenant, Account: sesExpAccount, diff --git a/general_tests/session_replications_automaticdebit_it_test.go b/general_tests/session_replications_automaticdebit_it_test.go index 2e5136439..70bb83d5d 100644 --- a/general_tests/session_replications_automaticdebit_it_test.go +++ b/general_tests/session_replications_automaticdebit_it_test.go @@ -22,12 +22,13 @@ package general_tests import ( "fmt" - "net/rpc" "os/exec" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -38,7 +39,7 @@ var ( smgRplcMasterCfgPath, smgRplcSlaveCfgPath string smgRplcMasterCfgDIR, smgRplcSlaveCfgDIR string smgRplcMasterCfg, smgRplcSlaveCfg *config.CGRConfig - smgRplcMstrRPC, smgRplcSlvRPC *rpc.Client + smgRplcMstrRPC, smgRplcSlvRPC *birpc.Client masterEngine *exec.Cmd sTestsSession = []func(t *testing.T){ testSessionSRplInitCfg, @@ -89,7 +90,7 @@ func testSessionSRplAddVoiceBalance(t *testing.T) { }, } var reply string - if err := smgRplcMstrRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -100,7 +101,7 @@ func testSessionSRplAddVoiceBalance(t *testing.T) { Account: "1005", } //get balance - if err := smgRplcMstrRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != float64(5*time.Second) { t.Errorf("Expecting: %v, received: %v", @@ -155,7 +156,7 @@ func testSessionSRplApierRpcConn(t *testing.T) { func testSessionSRplTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance - if err := smgRplcMstrRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -164,11 +165,11 @@ func testSessionSRplTPFromFolder(t *testing.T) { func testSessionSRplInitiate(t *testing.T) { var aSessions []*sessions.ExternalSession //make sure we don't have active sessions on master and passive on slave - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -196,7 +197,7 @@ func testSessionSRplInitiate(t *testing.T) { } var initRpl sessions.V1InitSessionReply - if err := smgRplcMstrRPC.Call(utils.SessionSv1InitiateSession, + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1InitiateSession, argsInit, &initRpl); err != nil { t.Error(err) } @@ -208,7 +209,7 @@ func testSessionSRplInitiate(t *testing.T) { //check active session time.Sleep(10 * time.Millisecond) - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123451"), @@ -225,7 +226,7 @@ func testSessionSRplInitiate(t *testing.T) { var autoDebit1, autoDebit2 time.Time var pSessions []*sessions.ExternalSession - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123451"), @@ -242,7 +243,7 @@ func testSessionSRplInitiate(t *testing.T) { //check active session (II) time.Sleep(12 * time.Millisecond) - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123451"), @@ -257,7 +258,7 @@ func testSessionSRplInitiate(t *testing.T) { } //check passive session (II) - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123451"), @@ -280,7 +281,7 @@ func testSessionSRplInitiate(t *testing.T) { Tenant: "cgrates.org", Account: "1005", } - if err := smgRplcMstrRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) // a tolerance of +/- 5ms is acceptable } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply < float64(5*time.Second-25*time.Millisecond) || rply > float64(5*time.Second-15*time.Millisecond) { @@ -295,14 +296,14 @@ func testSessionSRplActivateSlave(t *testing.T) { } // activate sessions on slave var rplActivate string - if err := smgRplcSlvRPC.Call(utils.SessionSv1ActivateSessions, &utils.SessionIDsWithArgsDispatcher{}, &rplActivate); err != nil { + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1ActivateSessions, &utils.SessionIDsWithArgsDispatcher{}, &rplActivate); err != nil { t.Error(err) } time.Sleep(7 * time.Millisecond) //check if the active session is on slave now var aSessions []*sessions.ExternalSession var autoDebit1, autoDebit2 time.Time - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("Unexpected number of sessions received: %+v", utils.ToIJSON(aSessions)) @@ -318,7 +319,7 @@ func testSessionSRplActivateSlave(t *testing.T) { t.Fatal(err) } time.Sleep(20 * time.Millisecond) - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions2); err != nil { + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions2); err != nil { t.Error(err) } else if len(aSessions2) != 1 { t.Errorf("Unexpected number of sessions received: %+v", utils.ToIJSON(aSessions2)) @@ -342,7 +343,7 @@ func testSessionSRplCheckAccount(t *testing.T) { } expectedBal := 5*time.Second - 40*time.Millisecond - if err := smgRplcSlvRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := smgRplcSlvRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) // a tolerance of +/- 10ms is acceptable } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply < float64(expectedBal-10*time.Millisecond) || @@ -374,20 +375,20 @@ func testSessionSRplTerminate(t *testing.T) { }, } var reply string - if err := smgRplcSlvRPC.Call(utils.SessionSv1TerminateSession, args, &reply); err != nil { + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1TerminateSession, args, &reply); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Wait for the sessions to be populated var aSessions []*sessions.ExternalSession //check if the session was terminated on slave - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetActiveSessions, + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error: %v with len(aSessions)=%v , session : %+v", err, len(aSessions), utils.ToIJSON(aSessions)) } // check to don't have passive session on slave var pSessions []*sessions.ExternalSession - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error: %v with len(pSessions)=%v , session : %+v", err, len(pSessions), utils.ToIJSON(pSessions)) } @@ -398,7 +399,7 @@ func testSessionSRplTerminate(t *testing.T) { Account: "1005", } - if err := smgRplcSlvRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := smgRplcSlvRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) // a tolerance of +/- 5ms is acceptable } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != float64(3*time.Second) { diff --git a/general_tests/session_rounding_it_test.go b/general_tests/session_rounding_it_test.go index 8f3489730..f52c353db 100644 --- a/general_tests/session_rounding_it_test.go +++ b/general_tests/session_rounding_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -37,7 +38,7 @@ var ( sesRndCfgPath string sesRndCfgDIR string sesRndCfg *config.CGRConfig - sesRndRPC *rpc.Client + sesRndRPC *birpc.Client sesRndAccount = "testAccount" sesRndTenant = "cgrates.org" @@ -185,7 +186,7 @@ func testSesRndItRPCConn(t *testing.T) { func testSesRndItLoadRating(t *testing.T) { var reply string - if err := sesRndRPC.Call(utils.APIerSv1SetTPRate, &utils.TPRateRALs{ + if err := sesRndRPC.Call(context.Background(), utils.APIerSv1SetTPRate, &utils.TPRateRALs{ TPid: utils.TestSQL, ID: "RT1", RateSlots: []*utils.RateSlot{ @@ -204,14 +205,14 @@ func testSesRndItLoadRating(t *testing.T) { {DestinationId: utils.MetaAny, RateId: "RT1", RoundingMethod: utils.MetaRoundingUp, RoundingDecimals: 1}, }, } - if err := sesRndRPC.Call(utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil { + if err := sesRndRPC.Call(context.Background(), utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPDestinationRate: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPDestinationRate: ", reply) } dr.ID = "DR_DOWN" dr.DestinationRates[0].RoundingMethod = utils.MetaRoundingDown - if err := sesRndRPC.Call(utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil { + if err := sesRndRPC.Call(context.Background(), utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPDestinationRate: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPDestinationRate: ", reply) @@ -224,14 +225,14 @@ func testSesRndItLoadRating(t *testing.T) { {DestinationRatesId: "DR_UP", TimingId: utils.MetaAny, Weight: 10}, }, } - if err := sesRndRPC.Call(utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil { + if err := sesRndRPC.Call(context.Background(), utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply) } rp.ID = "RP_DOWN" rp.RatingPlanBindings[0].DestinationRatesId = "DR_DOWN" - if err := sesRndRPC.Call(utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil { + if err := sesRndRPC.Call(context.Background(), utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply) @@ -248,26 +249,26 @@ func testSesRndItLoadRating(t *testing.T) { FallbackSubjects: utils.EmptyString, }}, } - if err := sesRndRPC.Call(utils.APIerSv1SetTPRatingProfile, rpf, &reply); err != nil { + if err := sesRndRPC.Call(context.Background(), utils.APIerSv1SetTPRatingProfile, rpf, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingProfile: ", reply) } rpf.Subject = "down" rpf.RatingPlanActivations[0].RatingPlanId = "RP_DOWN" - if err := sesRndRPC.Call(utils.APIerSv1SetTPRatingProfile, rpf, &reply); err != nil { + if err := sesRndRPC.Call(context.Background(), utils.APIerSv1SetTPRatingProfile, rpf, &reply); err != nil { t.Error("Got error on APIerSv1.SetTPRatingProfile: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingProfile: ", reply) } - if err := sesRndRPC.Call(utils.APIerSv1LoadRatingPlan, &v1.AttrLoadRatingPlan{TPid: utils.TestSQL}, &reply); err != nil { + if err := sesRndRPC.Call(context.Background(), utils.APIerSv1LoadRatingPlan, &v1.AttrLoadRatingPlan{TPid: utils.TestSQL}, &reply); err != nil { t.Error("Got error on APIerSv1.LoadRatingPlan: ", err.Error()) } else if reply != utils.OK { t.Error("Calling APIerSv1.LoadRatingPlan got reply: ", reply) } - if err := sesRndRPC.Call(utils.APIerSv1LoadRatingProfile, &utils.TPRatingProfile{ + if err := sesRndRPC.Call(context.Background(), utils.APIerSv1LoadRatingProfile, &utils.TPRatingProfile{ TPid: utils.TestSQL, LoadId: utils.TestSQL, Tenant: sesRndTenant, Category: utils.Call}, &reply); err != nil { t.Error("Got error on APIerSv1.LoadRatingProfile: ", err.Error()) @@ -280,7 +281,7 @@ func testSesRndItLoadRating(t *testing.T) { func testSesRndItAddCharger(t *testing.T) { //add a default charger var result string - if err := sesRndRPC.Call(utils.APIerSv1SetChargerProfile, &engine.ChargerProfile{ + if err := sesRndRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, &engine.ChargerProfile{ Tenant: sesRndTenant, ID: "default", RunID: utils.MetaDefault, @@ -295,7 +296,7 @@ func testSesRndItAddCharger(t *testing.T) { func testSesRndItAddVoiceBalance(t *testing.T) { var reply string - if err := sesRndRPC.Call(utils.APIerSv2SetBalance, utils.AttrSetBalance{ + if err := sesRndRPC.Call(context.Background(), utils.APIerSv2SetBalance, utils.AttrSetBalance{ Tenant: sesRndTenant, Account: sesRndAccount, BalanceType: utils.MetaMonetary, @@ -310,7 +311,7 @@ func testSesRndItAddVoiceBalance(t *testing.T) { } var acnt engine.Account - if err := sesRndRPC.Call(utils.APIerSv2GetAccount, + if err := sesRndRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: sesRndTenant, Account: sesRndAccount, @@ -325,7 +326,7 @@ func testSesRndItAddVoiceBalance(t *testing.T) { func testSesRndItPrepareCDRs(t *testing.T) { var reply sessions.V1InitSessionReply - if err := sesRndRPC.Call(utils.SessionSv1InitiateSession, + if err := sesRndRPC.Call(context.Background(), utils.SessionSv1InitiateSession, &sessions.V1InitSessionArgs{ InitSession: true, CGREvent: sesRndCgrEv, @@ -338,7 +339,7 @@ func testSesRndItPrepareCDRs(t *testing.T) { time.Sleep(50 * time.Millisecond) var rply string - if err := sesRndRPC.Call(utils.SessionSv1TerminateSession, + if err := sesRndRPC.Call(context.Background(), utils.SessionSv1TerminateSession, &sessions.V1TerminateSessionArgs{ TerminateSession: true, CGREvent: sesRndCgrEv, @@ -348,7 +349,7 @@ func testSesRndItPrepareCDRs(t *testing.T) { t.Errorf("Unexpected reply: %s", rply) } - if err := sesRndRPC.Call(utils.SessionSv1ProcessCDR, + if err := sesRndRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, sesRndCgrEv, &rply); err != nil { t.Error(err) } else if rply != utils.OK { @@ -360,7 +361,7 @@ func testSesRndItPrepareCDRs(t *testing.T) { func testSesRndItCheckCdrs(t *testing.T) { var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Accounts: []string{sesRndAccount}, OriginIDs: []string{utils.IfaceAsString(sesRndCgrEv.Event[utils.OriginID])}} - if err := sesRndRPC.Call(utils.APIerSv2GetCDRs, req, &cdrs); err != nil { + if err := sesRndRPC.Call(context.Background(), utils.APIerSv2GetCDRs, req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Fatal("Wrong number of CDRs") @@ -378,7 +379,7 @@ func testSesRndItCheckCdrs(t *testing.T) { t.Errorf("Unexpected AccountSummary: %v", utils.ToJSON(cd.AccountSummary)) } var acnt engine.Account - if err := sesRndRPC.Call(utils.APIerSv2GetAccount, + if err := sesRndRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: sesRndTenant, Account: sesRndAccount, diff --git a/general_tests/session_rpl_prepaid_it_test.go b/general_tests/session_rpl_prepaid_it_test.go index 86331338d..016097809 100644 --- a/general_tests/session_rpl_prepaid_it_test.go +++ b/general_tests/session_rpl_prepaid_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -36,7 +37,7 @@ var ( sesRplPrePaidCfgPath string sesRplPrePaidCfgDIR string sesRplPrePaidCfg *config.CGRConfig - sesRplPrePaidRPC *rpc.Client + sesRplPrePaidRPC *birpc.Client sesRplPrePaidTests = []func(t *testing.T){ testSeSRplPrepaidInitCfg, @@ -99,7 +100,7 @@ func testSeSRplPrepaidApierRpcConn(t *testing.T) { // Load the tariff plan, creating accounts and their balances func testSeSRplPrepaidTPFromFolder(t *testing.T) { var result string - if err := sesRplPrePaidRPC.Call(utils.APIerSv1SetChargerProfile, &engine.ChargerProfile{ + if err := sesRplPrePaidRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, &engine.ChargerProfile{ Tenant: "cgrates.org", ID: "Default", RunID: utils.MetaRaw, @@ -121,14 +122,14 @@ func testSeSRplPrepaidTPFromFolder(t *testing.T) { }, } var reply string - if err := sesRplPrePaidRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sesRplPrePaidRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } var acnt *engine.Account //get balance - if err := sesRplPrePaidRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{ + if err := sesRplPrePaidRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: "cgrates.org", Account: "1005", }, &acnt); err != nil { @@ -141,7 +142,7 @@ func testSeSRplPrepaidTPFromFolder(t *testing.T) { func testSeSRplPrepaidActivateSessions(t *testing.T) { var reply string - if err = sesRplPrePaidRPC.Call(utils.SessionSv1SetPassiveSession, sessions.Session{ + if err = sesRplPrePaidRPC.Call(context.Background(), utils.SessionSv1SetPassiveSession, sessions.Session{ CGRID: "ede927f8e42318a8db02c0f74adc2d9e16770339", Tenant: "cgrates.org", ResourceID: "testSeSRplPrepaidActivateSessions", @@ -244,19 +245,19 @@ func testSeSRplPrepaidActivateSessions(t *testing.T) { } var aSessions []*sessions.ExternalSession // Activate first session (with ID: ede927f8e42318a8db02c0f74adc2d9e16770339) - if err := sesRplPrePaidRPC.Call(utils.SessionSv1ActivateSessions, &utils.SessionIDsWithArgsDispatcher{}, &reply); err != nil { + if err := sesRplPrePaidRPC.Call(context.Background(), utils.SessionSv1ActivateSessions, &utils.SessionIDsWithArgsDispatcher{}, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Unexpected reply %s", reply) } - if err := sesRplPrePaidRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sesRplPrePaidRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("Expecting: 1 session, received: %+v sessions", len(aSessions)) } time.Sleep(10 * time.Millisecond) var acnt *engine.Account - if err := sesRplPrePaidRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{ + if err := sesRplPrePaidRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: "cgrates.org", Account: "1005", }, &acnt); err != nil { diff --git a/general_tests/sessionpause_it_test.go b/general_tests/sessionpause_it_test.go index 3f2021e20..3c5ed6361 100644 --- a/general_tests/sessionpause_it_test.go +++ b/general_tests/sessionpause_it_test.go @@ -23,12 +23,13 @@ package general_tests import ( "encoding/json" - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -39,7 +40,7 @@ var ( sesPauseCfgDir string sesPauseCfgPath string sesPauseCfg *config.CGRConfig - sesPauseRPC *rpc.Client + sesPauseRPC *birpc.Client sesPauseTests = []func(t *testing.T){ testSesPauseItLoadConfig, @@ -112,7 +113,7 @@ func testSesPauseItRPCConn(t *testing.T) { func testSesPauseItLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := sesPauseRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := sesPauseRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -143,7 +144,7 @@ func testSesPauseItInitSession(t *testing.T, cgrID string, chargeable bool, usag }, } var rply1 sessions.V1InitSessionReply - if err := sesPauseRPC.Call(utils.SessionSv1InitiateSession, + if err := sesPauseRPC.Call(context.Background(), utils.SessionSv1InitiateSession, args1, &rply1); err != nil { t.Error(err) return @@ -177,7 +178,7 @@ func testSesPauseItUpdateSession(t *testing.T, cgrID string, chargeable bool, us } var updtRpl sessions.V1UpdateSessionReply - if err := sesPauseRPC.Call(utils.SessionSv1UpdateSession, updtArgs, &updtRpl); err != nil { + if err := sesPauseRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updtArgs, &updtRpl); err != nil { t.Error(err) } if updtRpl.MaxUsage == nil || *updtRpl.MaxUsage != usage { @@ -209,14 +210,14 @@ func testSesPauseItTerminateSession(t *testing.T, cgrID string, chargeable bool, }, } var rply string - if err := sesPauseRPC.Call(utils.SessionSv1TerminateSession, + if err := sesPauseRPC.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } if rply != utils.OK { t.Errorf("Unexpected reply: %s", rply) } - if err := sesPauseRPC.Call(utils.SessionSv1ProcessCDR, &utils.CGREvent{ + if err := sesPauseRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, &utils.CGREvent{ Tenant: "cgrates.org", ID: "testSesPauseItProccesCDR", Event: map[string]any{ @@ -247,7 +248,7 @@ func testSesPauseItAllPause(t *testing.T) { time.Sleep(20 * time.Millisecond) var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RequestTypes: []string{utils.MetaPrepaid}, CGRIDs: []string{cgrID}} - if err := sesPauseRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sesPauseRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } @@ -383,7 +384,7 @@ func testSesPauseItInitPause(t *testing.T) { time.Sleep(20 * time.Millisecond) var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RequestTypes: []string{utils.MetaPrepaid}, CGRIDs: []string{cgrID}} - if err := sesPauseRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sesPauseRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } @@ -569,7 +570,7 @@ func testSesPauseItInitUpdatePause(t *testing.T) { time.Sleep(20 * time.Millisecond) var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RequestTypes: []string{utils.MetaPrepaid}, CGRIDs: []string{cgrID}} - if err := sesPauseRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sesPauseRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } @@ -765,7 +766,7 @@ func testSesPauseItUpdatePause(t *testing.T) { time.Sleep(20 * time.Millisecond) var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RequestTypes: []string{utils.MetaPrepaid}, CGRIDs: []string{cgrID}} - if err := sesPauseRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sesPauseRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } diff --git a/general_tests/sessionrefund_it_test.go b/general_tests/sessionrefund_it_test.go index be06059fc..ac6484dc7 100644 --- a/general_tests/sessionrefund_it_test.go +++ b/general_tests/sessionrefund_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -36,7 +37,7 @@ var ( srCfgPath string srCfgDIR string srCfg *config.CGRConfig - srrpc *rpc.Client + srrpc *birpc.Client sraccount = "refundAcc" srtenant = "cgrates.org" @@ -111,7 +112,7 @@ func testSrItRPCConn(t *testing.T) { func testSrItLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} - if err := srrpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := srrpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -123,7 +124,7 @@ func testAccountBalance(t *testing.T, sracc, srten, balType string, expected flo Tenant: srten, Account: sracc, } - if err := srrpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := srrpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if rply := acnt.BalanceMap[balType].GetTotalValue(); rply != expected { t.Errorf("Expecting: %v, received: %v", @@ -143,7 +144,7 @@ func testSrItAddVoiceBalance(t *testing.T) { }, } var reply string - if err := srrpc.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := srrpc.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -176,7 +177,7 @@ func testSrItInitSession(t *testing.T) { }, } var rply1 sessions.V1InitSessionReply - if err := srrpc.Call(utils.SessionSv1InitiateSession, + if err := srrpc.Call(context.Background(), utils.SessionSv1InitiateSession, args1, &rply1); err != nil { t.Error(err) return @@ -210,7 +211,7 @@ func testSrItTerminateSession(t *testing.T) { }, } var rply string - if err := srrpc.Call(utils.SessionSv1TerminateSession, + if err := srrpc.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } @@ -218,7 +219,7 @@ func testSrItTerminateSession(t *testing.T) { t.Errorf("Unexpected reply: %s", rply) } aSessions := make([]*sessions.ExternalSession, 0) - if err := srrpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || + if err := srrpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -239,7 +240,7 @@ func testSrItAddMonetaryBalance(t *testing.T) { }, } var reply string - if err := srrpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil { + if err := srrpc.Call(context.Background(), utils.APIerSv2SetBalance, attrs, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -270,7 +271,7 @@ func testSrItInitSession2(t *testing.T) { }, } var rply1 sessions.V1InitSessionReply - if err := srrpc.Call(utils.SessionSv1InitiateSession, + if err := srrpc.Call(context.Background(), utils.SessionSv1InitiateSession, args1, &rply1); err != nil { t.Error(err) return @@ -303,7 +304,7 @@ func testSrItTerminateSession2(t *testing.T) { }, } var rply string - if err := srrpc.Call(utils.SessionSv1TerminateSession, + if err := srrpc.Call(context.Background(), utils.SessionSv1TerminateSession, args, &rply); err != nil { t.Error(err) } @@ -311,7 +312,7 @@ func testSrItTerminateSession2(t *testing.T) { t.Errorf("Unexpected reply: %s", rply) } aSessions := make([]*sessions.ExternalSession, 0) - if err := srrpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || + if err := srrpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/general_tests/sessionroutes_it_test.go b/general_tests/sessionroutes_it_test.go index 57ba3059d..518f19403 100644 --- a/general_tests/sessionroutes_it_test.go +++ b/general_tests/sessionroutes_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -38,7 +39,7 @@ var ( sesRoutesCfgDir string sesRoutesCfgPath string sesRoutesCfg *config.CGRConfig - sesRoutesRPC *rpc.Client + sesRoutesRPC *birpc.Client sesRoutesTests = []func(t *testing.T){ testSesRoutesItLoadConfig, @@ -110,7 +111,7 @@ func testSesRoutesItRPCConn(t *testing.T) { func testSesRoutesItLoadFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := sesRoutesRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := sesRoutesRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -139,7 +140,7 @@ func testSesRoutesAuthorizeEvent(t *testing.T) { true, false, false, cgrEv, utils.Paginator{}, false, "") var rply sessions.V1AuthorizeReply - if err := sesRoutesRPC.Call(utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1AuthorizeEvent, args, &rply); err != nil { t.Fatal(err) } expected := sessions.V1AuthorizeReply{ @@ -183,7 +184,7 @@ func testSesRoutesAuthorizeEvent(t *testing.T) { true, false, false, cgrEv, utils.Paginator{}, false, "2") rply = sessions.V1AuthorizeReply{} - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessMessage, + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -223,7 +224,7 @@ func testSesRoutesAuthorizeEvent(t *testing.T) { true, false, false, cgrEv, utils.Paginator{}, false, "1") rply = sessions.V1AuthorizeReply{} - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessMessage, + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -237,7 +238,7 @@ func testSesRoutesAuthorizeEvent(t *testing.T) { true, false, true, cgrEv, utils.Paginator{}, false, "") rply = sessions.V1AuthorizeReply{} - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessMessage, + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -272,7 +273,7 @@ func testSesRoutesProcessMessage(t *testing.T) { true, false, false, cgrEv, utils.Paginator{}, false, "") var rply sessions.V1ProcessMessageReply - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessMessage, + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -318,7 +319,7 @@ func testSesRoutesProcessMessage(t *testing.T) { true, false, false, cgrEv, utils.Paginator{}, false, "2") rply = sessions.V1ProcessMessageReply{} - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessMessage, + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -358,7 +359,7 @@ func testSesRoutesProcessMessage(t *testing.T) { true, false, false, cgrEv, utils.Paginator{}, false, "1") rply = sessions.V1ProcessMessageReply{} - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessMessage, + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -372,7 +373,7 @@ func testSesRoutesProcessMessage(t *testing.T) { true, false, true, cgrEv, utils.Paginator{}, false, "") rply = sessions.V1ProcessMessageReply{} - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessMessage, + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessMessage, args, &rply); err != nil { t.Fatal(err) } @@ -409,7 +410,7 @@ func testSesRoutesProcessEvent(t *testing.T) { } var rply sessions.V1ProcessEventReply - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessEvent, args, &rply); err != nil { + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Fatal(err) } expected := sessions.V1ProcessEventReply{ @@ -458,7 +459,7 @@ func testSesRoutesProcessEvent(t *testing.T) { } rply = sessions.V1ProcessEventReply{} - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessEvent, + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Fatal(err) } @@ -502,7 +503,7 @@ func testSesRoutesProcessEvent(t *testing.T) { } args.CGREvent.APIOpts[utils.OptsRoutesMaxCost] = "1" rply = sessions.V1ProcessEventReply{} - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessEvent, + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Fatal(err) } @@ -518,7 +519,7 @@ func testSesRoutesProcessEvent(t *testing.T) { } rply = sessions.V1ProcessEventReply{} - if err := sesRoutesRPC.Call(utils.SessionSv1ProcessEvent, + if err := sesRoutesRPC.Call(context.Background(), utils.SessionSv1ProcessEvent, args, &rply); err != nil { t.Fatal(err) } diff --git a/general_tests/sessions_benchmark_it_test.go b/general_tests/sessions_benchmark_it_test.go index 1eb0ccb4b..ce7b41df0 100644 --- a/general_tests/sessions_benchmark_it_test.go +++ b/general_tests/sessions_benchmark_it_test.go @@ -23,12 +23,13 @@ package general_tests import ( "fmt" - "net/rpc" "os/exec" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -40,7 +41,7 @@ var ( sesPCfgDir string sesPCfgPath string sesPCfg *config.CGRConfig - sesPRPC *rpc.Client + sesPRPC *birpc.Client sesPTests = []func(t *testing.T){ testSesPItLoadConfig, @@ -130,7 +131,7 @@ func getAccounts(ids []string) (accounts *[]any, err error) { Tenant: "cgrates.org", AccountIDs: ids, } - err = sesPRPC.Call("APIerSv1.GetAccounts", attr, &reply) + err = sesPRPC.Call(context.Background(), "APIerSv1.GetAccounts", attr, &reply) if err != nil { return } @@ -151,7 +152,7 @@ func setAccBalance(acc string) (err error) { } var reply string - err = sesPRPC.Call(utils.APIerSv1SetBalance, args, &reply) + err = sesPRPC.Call(context.Background(), utils.APIerSv1SetBalance, args, &reply) return err } @@ -193,7 +194,7 @@ func initSes(n int) (err error) { for i := 0; i < n; i++ { initArgs.CGREvent.Event[utils.AccountField] = accIDs[i] initArgs.CGREvent.Event[utils.OriginID] = utils.UUIDSha1Prefix() - if err = sesPRPC.Call(utils.SessionSv1InitiateSession, + if err = sesPRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { return } @@ -214,7 +215,7 @@ func testSesPItBenchmark(t *testing.T) { }, APIOpts: map[string]any{}, } - if err := sesPRPC.Call(utils.APIerSv1SetChargerProfile, args, &reply); err != nil { + if err := sesPRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, args, &reply); err != nil { t.Error(err) } else if reply != "OK" { t.Error("Expected OK") @@ -230,7 +231,7 @@ func testSesPItBenchmark(t *testing.T) { APIOpts: map[string]any{}, } - if err := sesPRPC.Call(utils.APIerSv1SetChargerProfile, args2, &reply); err != nil { + if err := sesPRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, args2, &reply); err != nil { t.Error(err) } else if reply != "OK" { t.Error("Expected OK") @@ -247,7 +248,7 @@ func testSesPItBenchmark(t *testing.T) { } var statusRpl map[string]any - if err := sesPRPC.Call(utils.CoreSv1Status, nil, &statusRpl); err != nil { + if err := sesPRPC.Call(context.Background(), utils.CoreSv1Status, nil, &statusRpl); err != nil { t.Error(err) } fmt.Println(statusRpl) diff --git a/general_tests/sessions_concur_test.go b/general_tests/sessions_concur_test.go index 0db15741d..e9283d17a 100644 --- a/general_tests/sessions_concur_test.go +++ b/general_tests/sessions_concur_test.go @@ -20,337 +20,338 @@ along with this program. If not, see */ package general_tests -import ( - "flag" - "fmt" - "net/rpc" - "path" - "sync" - "testing" - "time" +// import ( +// "flag" +// "fmt" +// "path" +// "sync" +// "testing" +// "time" - v1 "github.com/cgrates/cgrates/apier/v1" - v2 "github.com/cgrates/cgrates/apier/v2" - "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/sessions" - "github.com/cgrates/cgrates/utils" -) +// "github.com/cgrates/birpc" +// "github.com/cgrates/birpc/context" +// v1 "github.com/cgrates/cgrates/apier/v1" +// v2 "github.com/cgrates/cgrates/apier/v2" +// "github.com/cgrates/cgrates/config" +// "github.com/cgrates/cgrates/engine" +// "github.com/cgrates/cgrates/sessions" +// "github.com/cgrates/cgrates/utils" +// ) -var ( - sCncrCfgDIR, sCncrCfgPath string - sCncrCfg *config.CGRConfig - sCncrRPC *rpc.Client +// var ( +// sCncrCfgDIR, sCncrCfgPath string +// sCncrCfg *config.CGRConfig +// sCncrRPC *birpc.Client - sCncrSessions = flag.Int("sessions", 100000, "maximum concurrent sessions created") - sCncrCps = flag.Int("cps", 50000, "maximum requests per second sent out") +// sCncrSessions = flag.Int("sessions", 100000, "maximum concurrent sessions created") +// sCncrCps = flag.Int("cps", 50000, "maximum requests per second sent out") - cpsPool = make(chan struct{}, *sCncrCps) - acntIDs = make(chan string, 1) - wg sync.WaitGroup -) +// cpsPool = make(chan struct{}, *sCncrCps) +// acntIDs = make(chan string, 1) +// wg sync.WaitGroup +// ) -// Tests starting here -func TestSCncrInternal(t *testing.T) { - sCncrCfgDIR = "sessinternal" - for _, tst := range sTestsSCncrIT { - t.Run("InternalConn", tst) - } -} +// // Tests starting here +// func TestSCncrInternal(t *testing.T) { +// sCncrCfgDIR = "sessinternal" +// for _, tst := range sTestsSCncrIT { +// t.Run("InternalConn", tst) +// } +// } -// Tests starting here -func TestSCncrJSON(t *testing.T) { - sCncrCfgDIR = "sessintjson" - for _, tst := range sTestsSCncrIT { - t.Run("JSONConn", tst) - } -} +// // Tests starting here +// func TestSCncrJSON(t *testing.T) { +// sCncrCfgDIR = "sessintjson" +// for _, tst := range sTestsSCncrIT { +// t.Run("JSONConn", tst) +// } +// } -// subtests to be executed -var sTestsSCncrIT = []func(t *testing.T){ - testSCncrInitConfig, - testSCncrInitDataDB, - testSCncrInitStorDB, - testSCncrStartEngine, - testSCncrRPCConn, - testSCncrLoadTP, - testSCncrRunSessions, - testSCncrKillEngine, -} +// // subtests to be executed +// var sTestsSCncrIT = []func(t *testing.T){ +// testSCncrInitConfig, +// testSCncrInitDataDB, +// testSCncrInitStorDB, +// testSCncrStartEngine, +// testSCncrRPCConn, +// testSCncrLoadTP, +// testSCncrRunSessions, +// testSCncrKillEngine, +// } -func testSCncrInitConfig(t *testing.T) { - sCncrCfgPath = path.Join(*dataDir, "conf", "samples", sCncrCfgDIR) - if sCncrCfg, err = config.NewCGRConfigFromPath(sCncrCfgPath); err != nil { - t.Fatal(err) - } -} +// func testSCncrInitConfig(t *testing.T) { +// sCncrCfgPath = path.Join(*dataDir, "conf", "samples", sCncrCfgDIR) +// if sCncrCfg, err = config.NewCGRConfigFromPath(sCncrCfgPath); err != nil { +// t.Fatal(err) +// } +// } -func testSCncrInitDataDB(t *testing.T) { - if err := engine.InitDataDb(sCncrCfg); err != nil { - t.Fatal(err) - } -} +// func testSCncrInitDataDB(t *testing.T) { +// if err := engine.InitDataDb(sCncrCfg); err != nil { +// t.Fatal(err) +// } +// } -// InitDb so we can rely on count -func testSCncrInitStorDB(t *testing.T) { - if err := engine.InitStorDb(sCncrCfg); err != nil { - t.Fatal(err) - } -} +// // InitDb so we can rely on count +// func testSCncrInitStorDB(t *testing.T) { +// if err := engine.InitStorDb(sCncrCfg); err != nil { +// t.Fatal(err) +// } +// } -func testSCncrStartEngine(t *testing.T) { - if _, err := engine.StopStartEngine(sCncrCfgPath, *waitRater); err != nil { - t.Fatal(err) - } -} +// func testSCncrStartEngine(t *testing.T) { +// if _, err := engine.StopStartEngine(sCncrCfgPath, *waitRater); err != nil { +// t.Fatal(err) +// } +// } -// Connect rpc client to rater -func testSCncrRPCConn(t *testing.T) { - var err error - sCncrRPC, err = newRPCClient(sCncrCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed - if err != nil { - t.Fatal("Could not connect to rater: ", err.Error()) - } -} +// // Connect rpc client to rater +// func testSCncrRPCConn(t *testing.T) { +// var err error +// sCncrRPC, err = newRPCClient(sCncrCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed +// if err != nil { +// t.Fatal("Could not connect to rater: ", err.Error()) +// } +// } -func testSCncrKillEngine(t *testing.T) { - if err := engine.KillEngine(*waitRater); err != nil { - t.Error(err) - } -} +// func testSCncrKillEngine(t *testing.T) { +// if err := engine.KillEngine(*waitRater); err != nil { +// t.Error(err) +// } +// } -func testSCncrLoadTP(t *testing.T) { - var loadInst string - if err := sCncrRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, - &utils.AttrLoadTpFromFolder{FolderPath: path.Join( - *dataDir, "tariffplans", "tp1cnt")}, &loadInst); err != nil { - t.Error(err) - } - attrPrfl := &v2.AttributeWithAPIOpts{ - ExternalAttributeProfile: &engine.ExternalAttributeProfile{ - Tenant: "cgrates.org", - ID: "AttrConcurrentSessions", - Contexts: []string{utils.MetaAny}, - Attributes: []*engine.ExternalAttribute{ - { - Path: utils.MetaReq + utils.NestingSep + "TestType", - Value: "ConcurrentSessions", - }, - }, - Weight: 20, - }, - } - var resAttrSet string - if err := sCncrRPC.Call(utils.APIerSv2SetAttributeProfile, attrPrfl, &resAttrSet); err != nil { - t.Error(err) - } else if resAttrSet != utils.OK { - t.Errorf("unexpected reply returned: <%s>", resAttrSet) - } -} +// func testSCncrLoadTP(t *testing.T) { +// var loadInst string +// if err := sCncrRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, +// &utils.AttrLoadTpFromFolder{FolderPath: path.Join( +// *dataDir, "tariffplans", "tp1cnt")}, &loadInst); err != nil { +// t.Error(err) +// } +// attrPrfl := &v2.AttributeWithAPIOpts{ +// ExternalAttributeProfile: &engine.ExternalAttributeProfile{ +// Tenant: "cgrates.org", +// ID: "AttrConcurrentSessions", +// Contexts: []string{utils.MetaAny}, +// Attributes: []*engine.ExternalAttribute{ +// { +// Path: utils.MetaReq + utils.NestingSep + "TestType", +// Value: "ConcurrentSessions", +// }, +// }, +// Weight: 20, +// }, +// } +// var resAttrSet string +// if err := sCncrRPC.Call(context.Background(), utils.APIerSv2SetAttributeProfile, attrPrfl, &resAttrSet); err != nil { +// t.Error(err) +// } else if resAttrSet != utils.OK { +// t.Errorf("unexpected reply returned: <%s>", resAttrSet) +// } +// } -func testSCncrRunSessions(t *testing.T) { - acntIDsSet := utils.NewStringSet(nil) - bufferTopup := 8760 * time.Hour - for i := 0; i < *sCncrSessions; i++ { - acntID := fmt.Sprintf("100%d", utils.RandomInteger(100, 200)) - if !acntIDsSet.Has(acntID) { - // Special balance BUFFER to cover concurrency on MAIN one - argsAddBalance := &v1.AttrAddBalance{ - Tenant: "cgrates.org", - Account: acntID, - BalanceType: utils.MetaVoice, - Value: float64(bufferTopup.Nanoseconds()), - Balance: map[string]any{ - utils.ID: "BUFFER", - }, - } - var addBlcRply string - if err = sCncrRPC.Call(utils.APIerSv1AddBalance, argsAddBalance, &addBlcRply); err != nil { - t.Error(err) - } else if addBlcRply != utils.OK { - t.Errorf("received: <%s>", addBlcRply) - } - acntIDsSet.Add(acntID) - } - acntIDs <- acntID - wg.Add(1) - go t.Run(fmt.Sprintf("RunSession#%d", i), testRunSession) - } - wg.Wait() - for acntID := range acntIDsSet.Data() { - // make sure the account was properly refunded - var acnt *engine.Account - acntAttrs := &utils.AttrGetAccount{ - Tenant: "cgrates.org", - Account: acntID} - if err = sCncrRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { - return - } else if vcBlnc := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); float64(bufferTopup.Nanoseconds())-vcBlnc > 1000000.0 { // eliminate rounding errors - t.Errorf("unexpected voice balance received: %+v", utils.ToIJSON(acnt)) - } else if mnBlnc := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); mnBlnc != 0 { - t.Errorf("unexpected monetary balance received: %+v", utils.ToIJSON(acnt)) - } - } -} +// func testSCncrRunSessions(t *testing.T) { +// acntIDsSet := utils.NewStringSet(nil) +// bufferTopup := 8760 * time.Hour +// for i := 0; i < *sCncrSessions; i++ { +// acntID := fmt.Sprintf("100%d", utils.RandomInteger(100, 200)) +// if !acntIDsSet.Has(acntID) { +// // Special balance BUFFER to cover concurrency on MAIN one +// argsAddBalance := &v1.AttrAddBalance{ +// Tenant: "cgrates.org", +// Account: acntID, +// BalanceType: utils.MetaVoice, +// Value: float64(bufferTopup.Nanoseconds()), +// Balance: map[string]any{ +// utils.ID: "BUFFER", +// }, +// } +// var addBlcRply string +// if err = sCncrRPC.Call(context.Background(), utils.APIerSv1AddBalance, argsAddBalance, &addBlcRply); err != nil { +// t.Error(err) +// } else if addBlcRply != utils.OK { +// t.Errorf("received: <%s>", addBlcRply) +// } +// acntIDsSet.Add(acntID) +// } +// acntIDs <- acntID +// wg.Add(1) +// go t.Run(fmt.Sprintf("RunSession#%d", i), testRunSession) +// } +// wg.Wait() +// for acntID := range acntIDsSet.Data() { +// // make sure the account was properly refunded +// var acnt *engine.Account +// acntAttrs := &utils.AttrGetAccount{ +// Tenant: "cgrates.org", +// Account: acntID} +// if err = sCncrRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { +// return +// } else if vcBlnc := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); float64(bufferTopup.Nanoseconds())-vcBlnc > 1000000.0 { // eliminate rounding errors +// t.Errorf("unexpected voice balance received: %+v", utils.ToIJSON(acnt)) +// } else if mnBlnc := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); mnBlnc != 0 { +// t.Errorf("unexpected monetary balance received: %+v", utils.ToIJSON(acnt)) +// } +// } +// } -// runSession runs one session -func testRunSession(t *testing.T) { - defer wg.Done() // decrease group counter one out from test - cpsPool <- struct{}{} // push here up to cps - go func() { // allow more requests after a second - time.Sleep(time.Second) - <-cpsPool - }() - acntID := <-acntIDs - originID := utils.GenUUID() // each test with it's own OriginID - // topup as much as we know we need for one session - mainTopup := 90 * time.Second - var addBlcRply string - argsAddBalance := &v1.AttrAddBalance{ - Tenant: "cgrates.org", - Account: acntID, - BalanceType: utils.MetaVoice, - Value: float64(mainTopup.Nanoseconds()), - Balance: map[string]any{ - utils.ID: "MAIN", - utils.Weight: 10, - }, - } - if err = sCncrRPC.Call(utils.APIerSv1AddBalance, argsAddBalance, &addBlcRply); err != nil { - t.Error(err) - } else if addBlcRply != utils.OK { - t.Errorf("received: <%s> to APIerSv1.AddBalance", addBlcRply) - } - time.Sleep(time.Duration( - utils.RandomInteger(0, 100)) * time.Millisecond) // randomize between tests +// // runSession runs one session +// func testRunSession(t *testing.T) { +// defer wg.Done() // decrease group counter one out from test +// cpsPool <- struct{}{} // push here up to cps +// go func() { // allow more requests after a second +// time.Sleep(time.Second) +// <-cpsPool +// }() +// acntID := <-acntIDs +// originID := utils.GenUUID() // each test with it's own OriginID +// // topup as much as we know we need for one session +// mainTopup := 90 * time.Second +// var addBlcRply string +// argsAddBalance := &v1.AttrAddBalance{ +// Tenant: "cgrates.org", +// Account: acntID, +// BalanceType: utils.MetaVoice, +// Value: float64(mainTopup.Nanoseconds()), +// Balance: map[string]any{ +// utils.ID: "MAIN", +// utils.Weight: 10, +// }, +// } +// if err = sCncrRPC.Call(context.Background(), utils.APIerSv1AddBalance, argsAddBalance, &addBlcRply); err != nil { +// t.Error(err) +// } else if addBlcRply != utils.OK { +// t.Errorf("received: <%s> to APIerSv1.AddBalance", addBlcRply) +// } +// time.Sleep(time.Duration( +// utils.RandomInteger(0, 100)) * time.Millisecond) // randomize between tests - // Auth the session - authDur := 5 * time.Minute - authArgs := &sessions.V1AuthorizeArgs{ - GetMaxUsage: true, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: fmt.Sprintf("TestSCncrAuth%s", originID), - Event: map[string]any{ - utils.Tenant: "cgrates.org", - utils.OriginID: originID, - utils.RequestType: utils.MetaPrepaid, - utils.AccountField: acntID, - utils.Destination: fmt.Sprintf("%s%s", acntID, acntID), - utils.SetupTime: time.Now(), - utils.Usage: authDur, - }, - }, - } - var rplyAuth sessions.V1AuthorizeReply - if err := sCncrRPC.Call(utils.SessionSv1AuthorizeEvent, authArgs, &rplyAuth); err != nil { - t.Error(err) - } - time.Sleep(time.Duration( - utils.RandomInteger(0, 100)) * time.Millisecond) +// // Auth the session +// authDur := 5 * time.Minute +// authArgs := &sessions.V1AuthorizeArgs{ +// GetMaxUsage: true, +// CGREvent: &utils.CGREvent{ +// Tenant: "cgrates.org", +// ID: fmt.Sprintf("TestSCncrAuth%s", originID), +// Event: map[string]any{ +// utils.Tenant: "cgrates.org", +// utils.OriginID: originID, +// utils.RequestType: utils.MetaPrepaid, +// utils.AccountField: acntID, +// utils.Destination: fmt.Sprintf("%s%s", acntID, acntID), +// utils.SetupTime: time.Now(), +// utils.Usage: authDur, +// }, +// }, +// } +// var rplyAuth sessions.V1AuthorizeReply +// if err := sCncrRPC.Call(context.Background(), utils.SessionSv1AuthorizeEvent, authArgs, &rplyAuth); err != nil { +// t.Error(err) +// } +// time.Sleep(time.Duration( +// utils.RandomInteger(0, 100)) * time.Millisecond) - // Init the session - initUsage := time.Minute - initArgs := &sessions.V1InitSessionArgs{ - InitSession: true, - GetAttributes: true, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: fmt.Sprintf("TestSCncrInit%s", originID), - Event: map[string]any{ - utils.OriginID: originID, - utils.RequestType: utils.MetaPrepaid, - utils.AccountField: acntID, - utils.Destination: fmt.Sprintf("%s%s", acntID, acntID), - utils.AnswerTime: time.Now(), - utils.Usage: initUsage, - }, - }, - } - var rplyInit sessions.V1InitSessionReply - if err := sCncrRPC.Call(utils.SessionSv1InitiateSession, - initArgs, &rplyInit); err != nil { - t.Error(err) - } else if rplyInit.MaxUsage == 0 { - t.Errorf("unexpected MaxUsage at init: %v", rplyInit.MaxUsage) - } - time.Sleep(time.Duration( - utils.RandomInteger(0, 100)) * time.Millisecond) +// // Init the session +// initUsage := time.Minute +// initArgs := &sessions.V1InitSessionArgs{ +// InitSession: true, +// GetAttributes: true, +// CGREvent: &utils.CGREvent{ +// Tenant: "cgrates.org", +// ID: fmt.Sprintf("TestSCncrInit%s", originID), +// Event: map[string]any{ +// utils.OriginID: originID, +// utils.RequestType: utils.MetaPrepaid, +// utils.AccountField: acntID, +// utils.Destination: fmt.Sprintf("%s%s", acntID, acntID), +// utils.AnswerTime: time.Now(), +// utils.Usage: initUsage, +// }, +// }, +// } +// var rplyInit sessions.V1InitSessionReply +// if err := sCncrRPC.Call(context.Background(), utils.SessionSv1InitiateSession, +// initArgs, &rplyInit); err != nil { +// t.Error(err) +// } else if rplyInit.MaxUsage == 0 { +// t.Errorf("unexpected MaxUsage at init: %v", rplyInit.MaxUsage) +// } +// time.Sleep(time.Duration( +// utils.RandomInteger(0, 100)) * time.Millisecond) - // Update the session with relocate - initOriginID := originID - originID = utils.GenUUID() - updtUsage := time.Minute - updtArgs := &sessions.V1UpdateSessionArgs{ - GetAttributes: true, - UpdateSession: true, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: fmt.Sprintf("TestSCncrUpdate%s", originID), - Event: map[string]any{ - utils.OriginID: originID, - utils.InitialOriginID: initOriginID, - utils.Usage: updtUsage, - }, - }, - } - var rplyUpdt sessions.V1UpdateSessionReply - if err := sCncrRPC.Call(utils.SessionSv1UpdateSession, - updtArgs, &rplyUpdt); err != nil { - t.Error(err) - } else if rplyUpdt.MaxUsage == 0 { - t.Errorf("unexpected MaxUsage at update: %v", rplyUpdt.MaxUsage) - } - time.Sleep(time.Duration( - utils.RandomInteger(0, 100)) * time.Millisecond) +// // Update the session with relocate +// initOriginID := originID +// originID = utils.GenUUID() +// updtUsage := time.Minute +// updtArgs := &sessions.V1UpdateSessionArgs{ +// GetAttributes: true, +// UpdateSession: true, +// CGREvent: &utils.CGREvent{ +// Tenant: "cgrates.org", +// ID: fmt.Sprintf("TestSCncrUpdate%s", originID), +// Event: map[string]any{ +// utils.OriginID: originID, +// utils.InitialOriginID: initOriginID, +// utils.Usage: updtUsage, +// }, +// }, +// } +// var rplyUpdt sessions.V1UpdateSessionReply +// if err := sCncrRPC.Call(context.Background(), utils.SessionSv1UpdateSession, +// updtArgs, &rplyUpdt); err != nil { +// t.Error(err) +// } else if rplyUpdt.MaxUsage == 0 { +// t.Errorf("unexpected MaxUsage at update: %v", rplyUpdt.MaxUsage) +// } +// time.Sleep(time.Duration( +// utils.RandomInteger(0, 100)) * time.Millisecond) - // Terminate the session - trmntArgs := &sessions.V1TerminateSessionArgs{ - TerminateSession: true, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: fmt.Sprintf("TestSCncrTerminate%s", originID), - Event: map[string]any{ - utils.OriginID: originID, - utils.Usage: 90 * time.Second, - }, - }, - } - var rplyTrmnt string - if err := sCncrRPC.Call(utils.SessionSv1TerminateSession, - trmntArgs, &rplyTrmnt); err != nil { - t.Error(err) - } else if rplyTrmnt != utils.OK { - t.Errorf("received: <%s> to SessionSv1.Terminate", rplyTrmnt) - } - time.Sleep(time.Duration( - utils.RandomInteger(0, 100)) * time.Millisecond) +// // Terminate the session +// trmntArgs := &sessions.V1TerminateSessionArgs{ +// TerminateSession: true, +// CGREvent: &utils.CGREvent{ +// Tenant: "cgrates.org", +// ID: fmt.Sprintf("TestSCncrTerminate%s", originID), +// Event: map[string]any{ +// utils.OriginID: originID, +// utils.Usage: 90 * time.Second, +// }, +// }, +// } +// var rplyTrmnt string +// if err := sCncrRPC.Call(context.Background(), utils.SessionSv1TerminateSession, +// trmntArgs, &rplyTrmnt); err != nil { +// t.Error(err) +// } else if rplyTrmnt != utils.OK { +// t.Errorf("received: <%s> to SessionSv1.Terminate", rplyTrmnt) +// } +// time.Sleep(time.Duration( +// utils.RandomInteger(0, 100)) * time.Millisecond) - // processCDR - argsCDR := &utils.CGREventWithOpts{ - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: fmt.Sprintf("TestSCncrCDR%s", originID), - Event: map[string]any{ - utils.OriginID: originID, - }, - }, - } - var rplyCDR string - if err := sCncrRPC.Call(utils.SessionSv1ProcessCDR, - argsCDR, &rplyCDR); err != nil { - t.Error(err) - } else if rplyCDR != utils.OK { - t.Errorf("received: <%s> to ProcessCDR", rplyCDR) - } - time.Sleep(20 * time.Millisecond) - var cdrs []*engine.ExternalCDR - argCDRs := utils.RPCCDRsFilter{OriginIDs: []string{originID}} - if err := sCncrRPC.Call(utils.APIerSv2GetCDRs, &argCDRs, &cdrs); err != nil { - t.Error(err) - } else if len(cdrs) != 1 { - t.Errorf("unexpected number of CDRs returned: %d", len(cdrs)) - } else if cdrs[0].Usage != "1m30s" { - t.Errorf("unexpected usage of CDR: %+v", cdrs[0]) - } -} +// // processCDR +// argsCDR := &utils.CGREventWithOpts{ +// CGREvent: &utils.CGREvent{ +// Tenant: "cgrates.org", +// ID: fmt.Sprintf("TestSCncrCDR%s", originID), +// Event: map[string]any{ +// utils.OriginID: originID, +// }, +// }, +// } +// var rplyCDR string +// if err := sCncrRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, +// argsCDR, &rplyCDR); err != nil { +// t.Error(err) +// } else if rplyCDR != utils.OK { +// t.Errorf("received: <%s> to ProcessCDR", rplyCDR) +// } +// time.Sleep(20 * time.Millisecond) +// var cdrs []*engine.ExternalCDR +// argCDRs := utils.RPCCDRsFilter{OriginIDs: []string{originID}} +// if err := sCncrRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &argCDRs, &cdrs); err != nil { +// t.Error(err) +// } else if len(cdrs) != 1 { +// t.Errorf("unexpected number of CDRs returned: %d", len(cdrs)) +// } else if cdrs[0].Usage != "1m30s" { +// t.Errorf("unexpected usage of CDR: %+v", cdrs[0]) +// } +// } diff --git a/general_tests/sessions_message_it_test.go b/general_tests/sessions_message_it_test.go index 52d02de15..e7eaaf815 100644 --- a/general_tests/sessions_message_it_test.go +++ b/general_tests/sessions_message_it_test.go @@ -22,11 +22,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -37,7 +38,7 @@ var ( sesMFDCfgDir string sesMFDCfgPath string sesMFDCfg *config.CGRConfig - sesMFDRPC *rpc.Client + sesMFDRPC *birpc.Client sesMFDTests = []func(t *testing.T){ testSesMFDItLoadConfig, @@ -107,7 +108,7 @@ func testSesMFDItRPCConn(t *testing.T) { func testSesMFDItSetChargers(t *testing.T) { //add a default charger var result string - if err := sesMFDRPC.Call(utils.APIerSv1SetChargerProfile, &engine.ChargerProfile{ + if err := sesMFDRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, &engine.ChargerProfile{ Tenant: "cgrates.org", ID: "default", RunID: utils.MetaDefault, @@ -118,7 +119,7 @@ func testSesMFDItSetChargers(t *testing.T) { } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := sesMFDRPC.Call(utils.APIerSv1SetChargerProfile, &engine.ChargerProfile{ + if err := sesMFDRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, &engine.ChargerProfile{ Tenant: "cgrates.org", ID: "default2", RunID: "default2", @@ -133,7 +134,7 @@ func testSesMFDItSetChargers(t *testing.T) { func testSesMFDItAddVoiceBalance(t *testing.T) { var reply string - if err := sesMFDRPC.Call(utils.APIerSv2SetBalance, utils.AttrSetBalance{ + if err := sesMFDRPC.Call(context.Background(), utils.APIerSv2SetBalance, utils.AttrSetBalance{ Tenant: "cgrates.org", Account: "1001", BalanceType: utils.MetaSMS, @@ -149,7 +150,7 @@ func testSesMFDItAddVoiceBalance(t *testing.T) { } var acnt engine.Account - if err := sesMFDRPC.Call(utils.APIerSv2GetAccount, + if err := sesMFDRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: "cgrates.org", Account: "1001", @@ -163,7 +164,7 @@ func testSesMFDItAddVoiceBalance(t *testing.T) { } func testSesMFDItProcessMessage(t *testing.T) { var initRpl *sessions.V1ProcessMessageReply - if err := sesMFDRPC.Call(utils.SessionSv1ProcessMessage, + if err := sesMFDRPC.Call(context.Background(), utils.SessionSv1ProcessMessage, &sessions.V1ProcessMessageArgs{ Debit: true, ForceDuration: true, @@ -191,7 +192,7 @@ func testSesMFDItProcessMessage(t *testing.T) { func testSesMFDItGetAccountAfter(t *testing.T) { var acnt engine.Account - if err := sesMFDRPC.Call(utils.APIerSv2GetAccount, + if err := sesMFDRPC.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{ Tenant: "cgrates.org", Account: "1001", diff --git a/general_tests/sessions_race_test.go b/general_tests/sessions_race_test.go index 04904f14e..94f84d312 100644 --- a/general_tests/sessions_race_test.go +++ b/general_tests/sessions_race_test.go @@ -26,12 +26,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) var ( @@ -44,11 +45,11 @@ var ( resp *engine.Responder ) -// this structure will iplement rpcclient.ClientConnector +// this structure will iplement birpc.ClientConnector // and will read forever the Event map type raceConn struct{} -func (_ raceConn) Call(serviceMethod string, args any, reply any) (err error) { +func (_ raceConn) Call(_ *context.Context, serviceMethod string, args any, reply any) (err error) { cgrev := args.(*utils.CGREvent) for { for k := range cgrev.Event { @@ -77,11 +78,11 @@ func TestSessionSRace(t *testing.T) { utils.Logger.SetLogLevel(7) // connManager - raceChan := make(chan rpcclient.ClientConnector, 1) - chargerSChan := make(chan rpcclient.ClientConnector, 1) - respChan := make(chan rpcclient.ClientConnector, 1) + raceChan := make(chan birpc.ClientConnector, 1) + chargerSChan := make(chan birpc.ClientConnector, 1) + respChan := make(chan birpc.ClientConnector, 1) raceChan <- new(raceConn) - connMgr = engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr = engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): raceChan, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chargerSChan, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResponder): respChan, @@ -131,52 +132,54 @@ func TestSessionSRace(t *testing.T) { // the race2 rply := new(sessions.V1InitSessionReply) - if err = sS.BiRPCv1InitiateSession(nil, &sessions.V1InitSessionArgs{ - InitSession: true, - ProcessThresholds: true, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "testSSv1ItProcessEventInitiateSession", - Event: map[string]any{ - utils.Tenant: "cgrates.org", - utils.ToR: utils.MetaVoice, - utils.OriginID: "testSSv1ItProcessEvent", - utils.RequestType: utils.MetaPrepaid, - utils.AccountField: "1001", - // utils.RatingSubject: "*zero1ms", - // utils.CGRDebitInterval: 10, - utils.Destination: "1002", - utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC), - utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC), - utils.Usage: 0, + if err = sS.BiRPCv1InitiateSession(context.Background(), + &sessions.V1InitSessionArgs{ + InitSession: true, + ProcessThresholds: true, + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "testSSv1ItProcessEventInitiateSession", + Event: map[string]any{ + utils.Tenant: "cgrates.org", + utils.ToR: utils.MetaVoice, + utils.OriginID: "testSSv1ItProcessEvent", + utils.RequestType: utils.MetaPrepaid, + utils.AccountField: "1001", + // utils.RatingSubject: "*zero1ms", + // utils.CGRDebitInterval: 10, + utils.Destination: "1002", + utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC), + utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC), + utils.Usage: 0, + }, }, - }, - }, rply); err != utils.ErrPartiallyExecuted { + }, rply); err != utils.ErrPartiallyExecuted { t.Fatal(err) } // the race1 rply2 := new(sessions.V1ProcessEventReply) - if err = sS.BiRPCv1ProcessEvent(nil, &sessions.V1ProcessEventArgs{ - Flags: []string{utils.ConcatenatedKey(utils.MetaRALs, utils.MetaInitiate), - utils.MetaThresholds}, - CGREvent: &utils.CGREvent{ - Tenant: "cgrates.org", - ID: "testSSv1ItProcessEventInitiateSession", - Event: map[string]any{ - utils.Tenant: "cgrates.org", - utils.ToR: utils.MetaVoice, - utils.OriginID: "testSSv1ItProcessEvent", - utils.RequestType: utils.MetaPrepaid, - utils.AccountField: "1001", - // utils.RatingSubject: "*zero1ms", - // utils.CGRDebitInterval: 10, - utils.Destination: "1002", - utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC), - utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC), - utils.Usage: 0, + if err = sS.BiRPCv1ProcessEvent(context.Background(), + &sessions.V1ProcessEventArgs{ + Flags: []string{utils.ConcatenatedKey(utils.MetaRALs, utils.MetaInitiate), + utils.MetaThresholds}, + CGREvent: &utils.CGREvent{ + Tenant: "cgrates.org", + ID: "testSSv1ItProcessEventInitiateSession", + Event: map[string]any{ + utils.Tenant: "cgrates.org", + utils.ToR: utils.MetaVoice, + utils.OriginID: "testSSv1ItProcessEvent", + utils.RequestType: utils.MetaPrepaid, + utils.AccountField: "1001", + // utils.RatingSubject: "*zero1ms", + // utils.CGRDebitInterval: 10, + utils.Destination: "1002", + utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC), + utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC), + utils.Usage: 0, + }, }, - }, - }, rply2); err != utils.ErrPartiallyExecuted { + }, rply2); err != utils.ErrPartiallyExecuted { t.Fatal(err) } } diff --git a/general_tests/sessions_tnt_change_cdr_it_test.go b/general_tests/sessions_tnt_change_cdr_it_test.go index f731d2919..50c810cf5 100644 --- a/general_tests/sessions_tnt_change_cdr_it_test.go +++ b/general_tests/sessions_tnt_change_cdr_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -39,7 +40,7 @@ var ( sesTntChngCdrsCfgDir string sesTntChngCdrsCfgPath string sesTntChngCdrsCfg *config.CGRConfig - sesTntChngCdrsRPC *rpc.Client + sesTntChngCdrsRPC *birpc.Client sesTntChngCdrsTests = []func(t *testing.T){ testSesTntChngCdrsLoadConfig, @@ -107,7 +108,7 @@ func testSesTntChngCdrsRPCConn(t *testing.T) { func testSesTntChngCdrsSetChargerProfile1(t *testing.T) { var reply *engine.ChargerProfile - if err := sesTntChngRPC.Call(utils.APIerSv1GetChargerProfile, + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Charger1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -122,13 +123,13 @@ func testSesTntChngCdrsSetChargerProfile1(t *testing.T) { } var result string - if err := sesTntChngRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := sesTntChngRPC.Call(utils.APIerSv1GetChargerProfile, + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Charger1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) { @@ -138,7 +139,7 @@ func testSesTntChngCdrsSetChargerProfile1(t *testing.T) { func testSesTntChngCdrsSetChargerProfile2(t *testing.T) { var reply *engine.ChargerProfile - if err := sesTntChngRPC.Call(utils.APIerSv1GetChargerProfile, + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Charger2"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -153,13 +154,13 @@ func testSesTntChngCdrsSetChargerProfile2(t *testing.T) { } var result string - if err := sesTntChngRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := sesTntChngRPC.Call(utils.APIerSv1GetChargerProfile, + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Charger2"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) { @@ -179,7 +180,7 @@ func testChargerSCdrsAuthProcessEventAuth(t *testing.T) { }, } var reply string - if err := sesTntChngRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -196,7 +197,7 @@ func testChargerSCdrsAuthProcessEventAuth(t *testing.T) { }, } var reply2 string - if err := sesTntChngRPC.Call(utils.APIerSv2SetBalance, attrSetBalance2, &reply2); err != nil { + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance2, &reply2); err != nil { t.Error(err) } else if reply2 != utils.OK { t.Errorf("Received: %s", reply2) @@ -218,7 +219,7 @@ func testChargerSCdrsAuthProcessEventAuth(t *testing.T) { }, } var rply sessions.V1AuthorizeReply - if err := sesTntChngRPC.Call(utils.CDRsV1ProcessEvent, ev, &rply); err != nil { + if err := sesTntChngRPC.Call(context.Background(), utils.CDRsV1ProcessEvent, ev, &rply); err != nil { t.Fatal(err) } expected := &sessions.V1AuthorizeReply{ diff --git a/general_tests/sessions_tnt_change_it_test.go b/general_tests/sessions_tnt_change_it_test.go index e0295a656..34a81c909 100644 --- a/general_tests/sessions_tnt_change_it_test.go +++ b/general_tests/sessions_tnt_change_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -39,7 +40,7 @@ var ( sesTntChngCfgDir string sesTntChngCfgPath string sesTntChngCfg *config.CGRConfig - sesTntChngRPC *rpc.Client + sesTntChngRPC *birpc.Client sesTntChngTests = []func(t *testing.T){ testSesTntChngLoadConfig, @@ -107,7 +108,7 @@ func testSesTntChngRPCConn(t *testing.T) { func testSesTntChngSetChargerProfile1(t *testing.T) { var reply *engine.ChargerProfile - if err := sesTntChngRPC.Call(utils.APIerSv1GetChargerProfile, + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Charger1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -122,13 +123,13 @@ func testSesTntChngSetChargerProfile1(t *testing.T) { } var result string - if err := sesTntChngRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := sesTntChngRPC.Call(utils.APIerSv1GetChargerProfile, + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Charger1"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) { @@ -138,7 +139,7 @@ func testSesTntChngSetChargerProfile1(t *testing.T) { func testSesTntChngSetChargerProfile2(t *testing.T) { var reply *engine.ChargerProfile - if err := sesTntChngRPC.Call(utils.APIerSv1GetChargerProfile, + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Charger2"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatal(err) @@ -153,13 +154,13 @@ func testSesTntChngSetChargerProfile2(t *testing.T) { } var result string - if err := sesTntChngRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := sesTntChngRPC.Call(utils.APIerSv1GetChargerProfile, + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv1GetChargerProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "Charger2"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) { @@ -179,7 +180,7 @@ func testChargerSAuthProcessEventAuth(t *testing.T) { }, } var reply string - if err := sesTntChngRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -196,7 +197,7 @@ func testChargerSAuthProcessEventAuth(t *testing.T) { }, } var reply2 string - if err := sesTntChngRPC.Call(utils.APIerSv2SetBalance, attrSetBalance2, &reply2); err != nil { + if err := sesTntChngRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance2, &reply2); err != nil { t.Error(err) } else if reply2 != utils.OK { t.Errorf("Received: %s", reply2) @@ -219,7 +220,7 @@ func testChargerSAuthProcessEventAuth(t *testing.T) { }, } var rply sessions.V1AuthorizeReply - if err := sesTntChngRPC.Call(utils.SessionSv1AuthorizeEvent, ev, &rply); err != nil { + if err := sesTntChngRPC.Call(context.Background(), utils.SessionSv1AuthorizeEvent, ev, &rply); err != nil { t.Fatal(err) } expected := &sessions.V1AuthorizeReply{ diff --git a/general_tests/shared_client_lock_it_test.go b/general_tests/shared_client_lock_it_test.go index 815047396..44d49373f 100644 --- a/general_tests/shared_client_lock_it_test.go +++ b/general_tests/shared_client_lock_it_test.go @@ -25,11 +25,12 @@ import ( "crypto/rand" "fmt" "math/big" - "net/rpc" "os" "path/filepath" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -39,7 +40,7 @@ import ( var ( clntLockCfgPath string clntLockCfg *config.CGRConfig - clntLockRPC *rpc.Client + clntLockRPC *birpc.Client clntLockDelay int sTestsClntLock = []func(t *testing.T){ @@ -148,7 +149,7 @@ func testSharedClientLockRpcConn(t *testing.T) { func testSharedClientLockSetProfiles(t *testing.T) { var reply string - err := clntLockRPC.Call(utils.APIerSv1SetChargerProfile, + err := clntLockRPC.Call(context.Background(), utils.APIerSv1SetChargerProfile, &v1.ChargerWithAPIOpts{ ChargerProfile: &engine.ChargerProfile{ Tenant: "cgrates.org", @@ -163,7 +164,7 @@ func testSharedClientLockSetProfiles(t *testing.T) { t.Error("Unexpected reply returned", reply) } - err = clntLockRPC.Call(utils.APIerSv1SetAttributeProfile, + err = clntLockRPC.Call(context.Background(), utils.APIerSv1SetAttributeProfile, &engine.AttributeProfileWithAPIOpts{ AttributeProfile: &engine.AttributeProfile{ Tenant: "cgrates.org", @@ -197,7 +198,7 @@ func testSharedClientLockCDRsProcessEvent(t *testing.T) { }, } var reply string - err = clntLockRPC.Call(utils.CDRsV1ProcessEvent, argsEv, &reply) + err = clntLockRPC.Call(context.Background(), utils.CDRsV1ProcessEvent, argsEv, &reply) if err == nil || err.Error() != utils.ErrPartiallyExecuted.Error() { t.Errorf("expected: <%v>,\nreceived: <%v>", utils.ErrPartiallyExecuted, err) diff --git a/general_tests/suretax_it_test.go b/general_tests/suretax_it_test.go index b8ea670e5..b810e0632 100644 --- a/general_tests/suretax_it_test.go +++ b/general_tests/suretax_it_test.go @@ -23,11 +23,12 @@ package general_tests import ( "flag" - "net/rpc" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -43,7 +44,7 @@ var ( tpDir = flag.String("tp_dir", "", "CGR config dir path here") stiCfg *config.CGRConfig - stiRpc *rpc.Client + stiRpc *birpc.Client stiLoadInst utils.LoadInstance sTestSTI = []func(t *testing.T){ @@ -108,7 +109,7 @@ func testSTIRpcConn(t *testing.T) { // Load the tariff plan, creating accounts and their balances func testSTILoadTariffPlanFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: *tpDir} - if err := stiRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &stiLoadInst); err != nil { + if err := stiRpc.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &stiLoadInst); err != nil { t.Error(err) } else if stiLoadInst.RatingLoadID == "" || stiLoadInst.AccountingLoadID == "" { t.Error("Empty loadId received, loadInstance: ", stiLoadInst) @@ -121,7 +122,7 @@ func testSTICacheStats(t *testing.T) { var rcvStats *utils.CacheStats expectedStats := &utils.CacheStats{Destinations: 1, RatingPlans: 1, RatingProfiles: 1} var args utils.AttrCacheStats - if err := stiRpc.Call(utils.APIerSv2GetCacheStats, args, &rcvStats); err != nil { + if err := stiRpc.Call(context.Background(), utils.APIerSv2GetCacheStats, args, &rcvStats); err != nil { t.Error("Got error on APIerSv2.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { t.Errorf("Calling APIerSv2.GetCacheStats expected: %+v, received: %+v", expectedStats, rcvStats) @@ -137,7 +138,7 @@ func testSTIProcessExternalCdr(t *testing.T) { Usage: "15s", PDD: "7.0", ExtraFields: map[string]string{"CustomerNumber": "000000534", "ZipCode": ""}, } var reply string - if err := stiRpc.Call(utils.CDRsV1ProcessExternalCDR, cdr, &reply); err != nil { + if err := stiRpc.Call(context.Background(), utils.CDRsV1ProcessExternalCDR, cdr, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if reply != utils.OK { t.Error("Unexpected reply received: ", reply) @@ -148,7 +149,7 @@ func testSTIProcessExternalCdr(t *testing.T) { func testSTIGetCdrs(t *testing.T) { var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{"1001"}} - if err := stiRpc.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := stiRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -158,7 +159,7 @@ func testSTIGetCdrs(t *testing.T) { } } req = utils.RPCCDRsFilter{RunIDs: []string{utils.MetaSureTax}, Accounts: []string{"1001"}} - if err := stiRpc.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := stiRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) diff --git a/general_tests/tls_it_test.go b/general_tests/tls_it_test.go index 0c84da9c2..645b7c115 100644 --- a/general_tests/tls_it_test.go +++ b/general_tests/tls_it_test.go @@ -25,6 +25,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -85,22 +86,22 @@ func testTLSStartEngine(t *testing.T) { func testTLSRpcConn(t *testing.T) { var err error - tlsRpcClientJson, err = rpcclient.NewRPCClient(utils.TCP, "localhost:2022", true, tlsCfg.TLSCfg().ClientKey, - tlsCfg.TLSCfg().ClientCerificate, tlsCfg.TLSCfg().CaCertificate, 3, 3, + tlsRpcClientJson, err = rpcclient.NewRPCClient(context.Background(), utils.TCP, "localhost:2022", true, tlsCfg.TLSCfg().ClientKey, + tlsCfg.TLSCfg().ClientCerificate, tlsCfg.TLSCfg().CaCertificate, 3, 3, 0, utils.FibDuration, time.Second, 5*time.Minute, rpcclient.JSONrpc, nil, false, nil) if err != nil { t.Errorf("Error: %s when dialing", err) } - tlsRpcClientGob, err = rpcclient.NewRPCClient(utils.TCP, "localhost:2023", true, tlsCfg.TLSCfg().ClientKey, - tlsCfg.TLSCfg().ClientCerificate, tlsCfg.TLSCfg().CaCertificate, 3, 3, + tlsRpcClientGob, err = rpcclient.NewRPCClient(context.Background(), utils.TCP, "localhost:2023", true, tlsCfg.TLSCfg().ClientKey, + tlsCfg.TLSCfg().ClientCerificate, tlsCfg.TLSCfg().CaCertificate, 3, 3, 0, utils.FibDuration, time.Second, 5*time.Minute, rpcclient.GOBrpc, nil, false, nil) if err != nil { t.Errorf("Error: %s when dialing", err) } - tlsHTTPJson, err = rpcclient.NewRPCClient(utils.TCP, "https://localhost:2280/jsonrpc", true, tlsCfg.TLSCfg().ClientKey, - tlsCfg.TLSCfg().ClientCerificate, tlsCfg.TLSCfg().CaCertificate, 3, 3, + tlsHTTPJson, err = rpcclient.NewRPCClient(context.Background(), utils.TCP, "https://localhost:2280/jsonrpc", true, tlsCfg.TLSCfg().ClientKey, + tlsCfg.TLSCfg().ClientCerificate, tlsCfg.TLSCfg().CaCertificate, 3, 3, 0, utils.FibDuration, time.Second, 5*time.Minute, rpcclient.HTTPjson, nil, false, nil) if err != nil { t.Errorf("Error: %s when dialing", err) @@ -110,28 +111,28 @@ func testTLSRpcConn(t *testing.T) { func testTLSPing(t *testing.T) { var reply string - if err := tlsRpcClientJson.Call(utils.ThresholdSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := tlsRpcClientJson.Call(context.Background(), utils.ThresholdSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := tlsRpcClientGob.Call(utils.ThresholdSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := tlsRpcClientGob.Call(context.Background(), utils.ThresholdSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := tlsHTTPJson.Call(utils.ThresholdSv1Ping, new(utils.CGREvent), &reply); err != nil { + if err := tlsHTTPJson.Call(context.Background(), utils.ThresholdSv1Ping, new(utils.CGREvent), &reply); err != nil { t.Error(err) } else if reply != utils.Pong { t.Errorf("Received: %s", reply) } - if err := tlsRpcClientJson.Call(utils.DispatcherSv1Ping, "", &reply); err == nil { + if err := tlsRpcClientJson.Call(context.Background(), utils.DispatcherSv1Ping, "", &reply); err == nil { t.Error(err) } - if err := tlsRpcClientGob.Call(utils.DispatcherSv1Ping, "", &reply); err == nil { + if err := tlsRpcClientGob.Call(context.Background(), utils.DispatcherSv1Ping, "", &reply); err == nil { t.Error(err) } - if err := tlsHTTPJson.Call(utils.DispatcherSv1Ping, "", &reply); err == nil { + if err := tlsHTTPJson.Call(context.Background(), utils.DispatcherSv1Ping, "", &reply); err == nil { t.Error(err) } @@ -160,7 +161,7 @@ func testTLSPing(t *testing.T) { }, } var rply sessions.V1InitReplyWithDigest - if err := tlsHTTPJson.Call(utils.SessionSv1InitiateSessionWithDigest, + if err := tlsHTTPJson.Call(context.Background(), utils.SessionSv1InitiateSessionWithDigest, args, &rply); err == nil { t.Error(err) } diff --git a/general_tests/tp_it_test.go b/general_tests/tp_it_test.go index 47370713e..af9d76be3 100644 --- a/general_tests/tp_it_test.go +++ b/general_tests/tp_it_test.go @@ -22,11 +22,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" @@ -38,7 +39,7 @@ var ( tpCfgPath string tpCfgDIR string tpCfg *config.CGRConfig - tpRPC *rpc.Client + tpRPC *birpc.Client tpLoadInst utils.LoadInstance // Share load information between tests sTestTp = []func(t *testing.T){ @@ -123,7 +124,7 @@ func testTpRpcConn(t *testing.T) { // Load the tariff plan, creating accounts and their balances func testTpLoadTariffPlanFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testtp")} - if err := tpRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &tpLoadInst); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &tpLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -143,14 +144,14 @@ func testTpBalanceCounter(t *testing.T) { }, } var cc engine.CallCost - if err := tpRPC.Call(utils.ResponderDebit, cd, &cc); err != nil { + if err := tpRPC.Call(context.Background(), utils.ResponderDebit, cd, &cc); err != nil { t.Error("Got error on Responder.GetCost: ", err.Error()) } else if cc.GetDuration() != 20*time.Second { t.Errorf("Calling Responder.MaxDebit got callcost: %v", cc.GetDuration()) } var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := tpRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) } else if acnt.UnitCounters[utils.MetaMonetary][1].Counters[0].Value != 20.0 { t.Errorf("Calling APIerSv2.GetBalance received: %s", utils.ToIJSON(acnt)) @@ -159,13 +160,13 @@ func testTpBalanceCounter(t *testing.T) { func testTpActionTriggers(t *testing.T) { var atrs engine.ActionTriggers - if err := tpRPC.Call(utils.APIerSv1GetActionTriggers, &v1.AttrGetActionTriggers{GroupIDs: []string{}}, &atrs); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv1GetActionTriggers, &v1.AttrGetActionTriggers{GroupIDs: []string{}}, &atrs); err != nil { t.Error("Got error on APIerSv1.GetActionTriggers: ", err.Error()) } else if len(atrs) != 4 { t.Errorf("Calling v1.GetActionTriggers got: %v", atrs) } var reply string - if err := tpRPC.Call(utils.APIerSv1SetActionTrigger, v1.AttrSetActionTrigger{ + if err := tpRPC.Call(context.Background(), utils.APIerSv1SetActionTrigger, v1.AttrSetActionTrigger{ GroupID: "TestATR", UniqueID: "Unique atr id", ActionTrigger: map[string]any{ @@ -176,12 +177,12 @@ func testTpActionTriggers(t *testing.T) { } else if reply != utils.OK { t.Errorf("Calling v1.SetActionTrigger got: %v", reply) } - if err := tpRPC.Call(utils.APIerSv1GetActionTriggers, &v1.AttrGetActionTriggers{GroupIDs: []string{}}, &atrs); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv1GetActionTriggers, &v1.AttrGetActionTriggers{GroupIDs: []string{}}, &atrs); err != nil { t.Error(err) } else if len(atrs) != 5 { t.Errorf("Calling v1.GetActionTriggers got: %v", atrs) } - if err := tpRPC.Call(utils.APIerSv1GetActionTriggers, &v1.AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv1GetActionTriggers, &v1.AttrGetActionTriggers{GroupIDs: []string{"TestATR"}}, &atrs); err != nil { t.Error("Got error on APIerSv1.GetActionTriggers: ", err.Error()) } else if len(atrs) != 1 { t.Errorf("Calling v1.GetActionTriggers got: %v", atrs) @@ -203,7 +204,7 @@ func testTpActionTriggers(t *testing.T) { func testTpZeroCost(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1012"} - if err := tpRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) } if acnt == nil { @@ -228,12 +229,12 @@ func testTpZeroCost(t *testing.T) { }, } var cc engine.CallCost - if err := tpRPC.Call(utils.ResponderDebit, cd, &cc); err != nil { + if err := tpRPC.Call(context.Background(), utils.ResponderDebit, cd, &cc); err != nil { t.Error("Got error on Responder.Debit: ", err.Error()) } else if cc.GetDuration() != 20*time.Second { t.Errorf("Calling Responder.MaxDebit got callcost: %v", utils.ToIJSON(cc)) } - if err := tpRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) } else if acnt.BalanceMap[utils.MetaMonetary][0].Value != balanceValueBefore { t.Errorf("Calling APIerSv2.GetAccount received: %s", utils.ToIJSON(acnt)) @@ -255,14 +256,14 @@ func testTpZeroNegativeCost(t *testing.T) { }, } var cc engine.CallCost - if err := tpRPC.Call(utils.ResponderDebit, cd, &cc); err != nil { + if err := tpRPC.Call(context.Background(), utils.ResponderDebit, cd, &cc); err != nil { t.Error("Got error on Responder.GetCost: ", err.Error()) } else if cc.GetDuration() != 20*time.Second { t.Errorf("Calling Responder.MaxDebit got callcost: %v", utils.ToIJSON(cc)) } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1013"} - if err := tpRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) } else if acnt.BalanceMap[utils.MetaVoice][0].Value != 100.0 { t.Errorf("Calling APIerSv2.GetAccount received: %s", utils.ToIJSON(acnt)) @@ -271,39 +272,39 @@ func testTpZeroNegativeCost(t *testing.T) { func testTpExecuteActionCgrRpc(t *testing.T) { var reply string - if err := tpRPC.Call(utils.APIerSv2ExecuteAction, utils.AttrExecuteAction{ActionsId: "RPC"}, &reply); err != nil { - t.Error("Got error on APIerSv2.ExecuteAction: ", err.Error()) + if err := tpRPC.Call(context.Background(), utils.APIerSv1ExecuteAction, utils.AttrExecuteAction{ActionsId: "RPC"}, &reply); err != nil { + t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling ExecuteAction got reply: %s", reply) } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1013"} - if err := tpRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) } } func testTpExecuteActionCgrRpcAcc(t *testing.T) { var reply string - if err := tpRPC.Call(utils.APIerSv2ExecuteAction, utils.AttrExecuteAction{ + if err := tpRPC.Call(context.Background(), utils.APIerSv1ExecuteAction, utils.AttrExecuteAction{ Tenant: "cgrates.org", Account: "1016", ActionsId: "RPC_DEST", }, &reply); err != nil { - t.Error("Got error on APIerSv2.ExecuteAction: ", err.Error()) + t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling ExecuteAction got reply: %s", reply) } var dests []*engine.Destination attrs := &v2.AttrGetDestinations{DestinationIDs: []string{}} - if err := tpRPC.Call(utils.APIerSv2GetDestinations, attrs, &dests); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetDestinations, attrs, &dests); err != nil { t.Error("Got error on APIerSv2.GetDestinations: ", err.Error()) } } func testTpCreateExecuteActionMatch(t *testing.T) { var reply string - if err := tpRPC.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{ + if err := tpRPC.Call(context.Background(), utils.APIerSv2SetActions, &utils.AttrSetActions{ ActionsId: "PAYMENT_2056bd2fe137082970f97102b64e42fd", Actions: []*utils.TPAction{ { @@ -319,27 +320,27 @@ func testTpCreateExecuteActionMatch(t *testing.T) { } else if reply != utils.OK { t.Errorf("Calling APIerSv2.SetActions got reply: %s", reply) } - if err := tpRPC.Call(utils.APIerSv2ExecuteAction, utils.AttrExecuteAction{ + if err := tpRPC.Call(context.Background(), utils.APIerSv1ExecuteAction, utils.AttrExecuteAction{ Tenant: "cgrates.org", Account: "1015", ActionsId: "PAYMENT_2056bd2fe137082970f97102b64e42fd", }, &reply); err != nil { - t.Error("Got error on APIerSv2.ExecuteAction: ", err.Error()) + t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling ExecuteAction got reply: %s", reply) } - if err := tpRPC.Call(utils.APIerSv2ExecuteAction, utils.AttrExecuteAction{ + if err := tpRPC.Call(context.Background(), utils.APIerSv1ExecuteAction, utils.AttrExecuteAction{ Tenant: "cgrates.org", Account: "1015", ActionsId: "PAYMENT_2056bd2fe137082970f97102b64e42fd", }, &reply); err != nil { - t.Error("Got error on APIerSv2.ExecuteAction: ", err.Error()) + t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling ExecuteAction got reply: %s", reply) } var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1015"} - if err := tpRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) } if len(acnt.BalanceMap) != 1 || @@ -351,7 +352,7 @@ func testTpCreateExecuteActionMatch(t *testing.T) { func testTpSetRemoveActions(t *testing.T) { var reply string - if err := tpRPC.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{ + if err := tpRPC.Call(context.Background(), utils.APIerSv2SetActions, &utils.AttrSetActions{ ActionsId: "TO_BE_DELETED", Actions: []*utils.TPAction{ { @@ -368,21 +369,21 @@ func testTpSetRemoveActions(t *testing.T) { t.Errorf("Calling APIerSv2.SetActions got reply: %s", reply) } actionsMap := make(map[string]engine.Actions) - if err := tpRPC.Call(utils.APIerSv2GetActions, &v2.AttrGetActions{ + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetActions, &v2.AttrGetActions{ ActionIDs: []string{"PAYMENT_2056bd2fe137082970f97102b64e42fd"}, }, &actionsMap); err != nil { t.Error("Got error on APIerSv2.GetActions: ", err.Error()) } else if len(actionsMap) != 1 { t.Errorf("Calling APIerSv2.GetActions got reply: %s", utils.ToIJSON(actionsMap)) } - if err := tpRPC.Call(utils.APIerSv2RemoveActions, v1.AttrRemoveActions{ + if err := tpRPC.Call(context.Background(), utils.APIerSv2RemoveActions, v1.AttrRemoveActions{ ActionIDs: []string{"PAYMENT_2056bd2fe137082970f97102b64e42fd"}, }, &reply); err != nil { t.Error("Got error on APIerSv2.RemoveActions: ", err.Error()) } else if reply != utils.OK { t.Errorf("Calling APIerSv2.RemoveActions got reply: %s", reply) } - if err := tpRPC.Call(utils.APIerSv2GetActions, &v2.AttrGetActions{ + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetActions, &v2.AttrGetActions{ ActionIDs: []string{"PAYMENT_2056bd2fe137082970f97102b64e42fd"}, }, &actionsMap); err == nil { t.Error("no error on APIerSv2.GetActions: ", err) @@ -391,7 +392,7 @@ func testTpSetRemoveActions(t *testing.T) { func testTpRemoveActionsRefenced(t *testing.T) { actionsMap := make(map[string]engine.Actions) - if err := tpRPC.Call(utils.APIerSv2GetActions, &v2.AttrGetActions{ + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetActions, &v2.AttrGetActions{ ActionIDs: []string{"TOPUP_VOICE"}, }, &actionsMap); err != nil { t.Error("Got error on APIerSv2.GetActions: ", err.Error()) @@ -399,7 +400,7 @@ func testTpRemoveActionsRefenced(t *testing.T) { t.Errorf("Calling APIerSv2.GetActions got reply: %s", utils.ToIJSON(actionsMap)) } var reply string - if err := tpRPC.Call(utils.APIerSv2RemoveActions, v1.AttrRemoveActions{ + if err := tpRPC.Call(context.Background(), utils.APIerSv2RemoveActions, v1.AttrRemoveActions{ ActionIDs: []string{"TOPUP_VOICE"}, }, &reply); err != nil { t.Error("Error on APIerSv2.RemoveActions: ", err.Error()) @@ -407,7 +408,7 @@ func testTpRemoveActionsRefenced(t *testing.T) { t.Errorf("Calling APIerSv2.RemoveActions got reply: %s", reply) } /* - if err := tpRPC.Call(utils.APIerSv2GetActions, v2.AttrGetActions{ + if err := tpRPC.Call(context.Background(),utils.APIerSv2GetActions, v2.AttrGetActions{ ActionIDs: []string{"PAYMENT_2056bd2fe137082970f97102b64e42fd"}, }, &actionsMap); err == nil { t.Error("no error on APIerSv2.GetActions: ", err) @@ -418,13 +419,13 @@ func testTpRemoveActionsRefenced(t *testing.T) { func testTpApierResetAccountActionTriggers(t *testing.T) { var acnt engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1005"} - if err := tpRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.ActionTriggers[0].Executed != true { t.Skip("Skipping test since Executed is not yet true") } var reply string - if err := tpRPC.Call(utils.APIerSv2ResetAccountActionTriggers, v1.AttrResetAccountActionTriggers{ + if err := tpRPC.Call(context.Background(), utils.APIerSv2ResetAccountActionTriggers, v1.AttrResetAccountActionTriggers{ Tenant: "cgrates.org", Account: "1005", GroupID: "STANDARD_TRIGGERS", @@ -434,7 +435,7 @@ func testTpApierResetAccountActionTriggers(t *testing.T) { } else if reply != utils.OK { t.Errorf("Calling APIerSv2.ResetAccountActionTriggers got reply: %s", reply) } - if err := tpRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := tpRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.ActionTriggers[0].Executed == false { t.Errorf("wrong action trigger executed flag: %s", utils.ToIJSON(acnt.ActionTriggers)) diff --git a/general_tests/tut_smgeneric_it_test.go b/general_tests/tut_smgeneric_it_test.go index 646f8a54d..7bfe05130 100644 --- a/general_tests/tut_smgeneric_it_test.go +++ b/general_tests/tut_smgeneric_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -38,7 +39,7 @@ var ( tutSMGCfgPath string tutSMGCfgDIR string tutSMGCfg *config.CGRConfig - tutSMGRpc *rpc.Client + tutSMGRpc *birpc.Client smgLoadInst utils.LoadInstance // Share load information between tests sTestTutSMG = []func(t *testing.T){ @@ -115,7 +116,7 @@ func testTutSMGRpcConn(t *testing.T) { // Load the tariff plan, creating accounts and their balances func testTutSMGLoadTariffPlanFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} - if err := tutSMGRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &smgLoadInst); err != nil { + if err := tutSMGRpc.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &smgLoadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -124,7 +125,7 @@ func testTutSMGLoadTariffPlanFromFolder(t *testing.T) { // Check loaded stats func testTutSMGCacheStats(t *testing.T) { var reply string - if err := tutSMGRpc.Call(utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil { + if err := tutSMGRpc.Call(context.Background(), utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Error(reply) @@ -171,7 +172,7 @@ func testTutSMGCacheStats(t *testing.T) { expectedStats[utils.CacheAttributeFilterIndexes].Groups = 2 expectedStats[utils.CacheReverseFilterIndexes].Items = 15 expectedStats[utils.CacheReverseFilterIndexes].Groups = 13 - if err := tutSMGRpc.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { + if err := tutSMGRpc.Call(context.Background(), utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil { t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { t.Errorf("Calling APIerSv2.CacheSv1 expected: %+v,\n received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats)) diff --git a/general_tests/tutorial2_calls_test.go b/general_tests/tutorial2_calls_test.go index fffd40a19..2d092c582 100644 --- a/general_tests/tutorial2_calls_test.go +++ b/general_tests/tutorial2_calls_test.go @@ -40,7 +40,7 @@ package general_tests // ) // var tutorial2CallsCfg *config.CGRConfig -// var tutorial2CallsRpc *rpc.Client +// var tutorial2CallsRpc *birpc.Client // var tutorial2CallsPjSuaListener *os.File // var tutorial2FSConfig = flag.String("tutorial2FSConfig", "/usr/share/cgrates/tutorial_tests/fs_evsock", "FreeSwitch tutorial folder") // var tutorial2OptConf string @@ -166,7 +166,7 @@ package general_tests // func testTutorial2CallLoadTariffPlanFromFolder(t *testing.T) { // var reply string // attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} -// if err := tutorial2CallsRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { // t.Error(err) // } // time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -176,14 +176,14 @@ package general_tests // func testTutorial2CallAccountsBefore(t *testing.T) { // var reply *engine.Account // attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} -// if err := tutorial2CallsRpc.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.APIerSv2GetAccount, attrs, &reply); err != nil { // t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) // } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() != 10.0 { // t.Errorf("Calling APIerSv1.GetBalance received: %f", reply.BalanceMap[utils.MetaMonetary].GetTotalValue()) // } // var reply2 *engine.Account // attrs2 := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1002"} -// if err := tutorial2CallsRpc.Call(utils.APIerSv2GetAccount, attrs2, &reply2); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.APIerSv2GetAccount, attrs2, &reply2); err != nil { // t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) // } else if reply2.BalanceMap[utils.MetaMonetary].GetTotalValue() != 10.0 { // t.Errorf("Calling APIerSv1.GetBalance received: %f", reply2.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -196,13 +196,13 @@ package general_tests // utils.MetaTCC: utils.NotAvailable, // utils.MetaTCD: utils.NotAvailable, // } -// if err := tutorial2CallsRpc.Call(utils.StatSv1GetQueueStringMetrics, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.StatSv1GetQueueStringMetrics, // &utils.TenantID{Tenant: "cgrates.org", ID: "Stats2"}, &metrics); err != nil { // t.Error(err) // } else if !reflect.DeepEqual(expectedMetrics, metrics) { // t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics) // } -// if err := tutorial2CallsRpc.Call(utils.StatSv1GetQueueStringMetrics, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.StatSv1GetQueueStringMetrics, // &utils.TenantID{Tenant: "cgrates.org", ID: "Stats2_1"}, &metrics); err != nil { // t.Error(err) // } else if !reflect.DeepEqual(expectedMetrics, metrics) { @@ -224,7 +224,7 @@ package general_tests // }, // }, // } -// if err := tutorial2CallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { // t.Fatal(err) // } else if len(*rs) != 1 { // t.Fatalf("Resources: %+v", utils.ToJSON(rs)) @@ -240,7 +240,7 @@ package general_tests // func testTutorial2CallCheckThreshold1001Before(t *testing.T) { // var td engine.Threshold // eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1001", Hits: 0} -// if err := tutorial2CallsRpc.Call(utils.ThresholdSv1GetThreshold, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.ThresholdSv1GetThreshold, // &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &td); err != nil { // t.Error(err) // } else if !reflect.DeepEqual(eTd, td) { @@ -251,7 +251,7 @@ package general_tests // func testTutorial2CallCheckThreshold1002Before(t *testing.T) { // var td engine.Threshold // eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1002", Hits: 0} -// if err := tutorial2CallsRpc.Call(utils.ThresholdSv1GetThreshold, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.ThresholdSv1GetThreshold, // &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1002"}, &td); err != nil { // t.Error(err) // } else if !reflect.DeepEqual(eTd, td) { @@ -299,7 +299,7 @@ package general_tests // Destination: "1002", // }, // } -// if err := tutorial2CallsRpc.Call(utils.SessionSv1GetActiveSessions, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.SessionSv1GetActiveSessions, // nil, &reply); err != nil { // t.Error("Got error on SessionSv1.GetActiveSessions: ", err.Error()) // } else { @@ -334,7 +334,7 @@ package general_tests // }, // }, // } -// if err := tutorial2CallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { // t.Fatal(err) // } else if len(*rs) != 1 { // t.Fatalf("Resources: %+v", utils.ToJSON(rs)) @@ -352,7 +352,7 @@ package general_tests // func testTutorial2CallAccount1001(t *testing.T) { // var reply *engine.Account // attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} -// if err := tutorial2CallsRpc.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.APIerSv2GetAccount, attrs, &reply); err != nil { // t.Error(err.Error()) // } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() == 10.0 { // Make sure we debitted // t.Errorf("Expected: 10, received: %+v", reply.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -365,7 +365,7 @@ package general_tests // func testTutorial2Call1001Cdrs(t *testing.T) { // var reply []*engine.ExternalCDR // req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{"1001"}} -// if err := tutorial2CallsRpc.Call(utils.APIerSv2GetCDRs, &req, &reply); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.APIerSv2GetCDRs, &req, &reply); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if len(reply) != 2 { // t.Error("Unexpected number of CDRs returned: ", len(reply)) @@ -413,7 +413,7 @@ package general_tests // utils.MetaTCD: "37s", // } -// if err := tutorial2CallsRpc.Call(utils.StatSv1GetQueueStringMetrics, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.StatSv1GetQueueStringMetrics, // &utils.TenantID{Tenant: "cgrates.org", ID: "Stats"}, &metrics); err != nil { // t.Fatal(err) // } @@ -439,7 +439,7 @@ package general_tests // }, // }, // } -// if err := tutorial2CallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { // t.Fatal(err) // } else if len(*rs) != 1 { // t.Fatalf("Resources: %+v", rs) @@ -453,7 +453,7 @@ package general_tests // func testTutorial2CallCheckThreshold1001After(t *testing.T) { // var td engine.Threshold -// if err := tutorial2CallsRpc.Call(utils.ThresholdSv1GetThreshold, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.ThresholdSv1GetThreshold, // &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &td); err != nil && // err.Error() != utils.ErrNotFound.Error() { // t.Error(err) @@ -463,7 +463,7 @@ package general_tests // func testTutorial2CallCheckThreshold1002After(t *testing.T) { // var td engine.Threshold // eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1002", Hits: 4} -// if err := tutorial2CallsRpc.Call(utils.ThresholdSv1GetThreshold, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.ThresholdSv1GetThreshold, // &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1002"}, &td); err != nil { // t.Error(err) // } else if !reflect.DeepEqual(eTd.Tenant, td.Tenant) { @@ -478,7 +478,7 @@ package general_tests // func testTutorial2CallSyncSessions(t *testing.T) { // var reply *[]*sessions.ExternalSession // // activeSessions shouldn't be active -// if err := tutorial2CallsRpc.Call(utils.SessionSv1GetActiveSessions, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.SessionSv1GetActiveSessions, // nil, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { // t.Error("Got error on SessionSv1.GetActiveSessions: ", err) // } @@ -496,7 +496,7 @@ package general_tests // } // time.Sleep(time.Second) // // get active sessions -// if err := tutorial2CallsRpc.Call(utils.SessionSv1GetActiveSessions, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.SessionSv1GetActiveSessions, // nil, &reply); err != nil { // t.Error("Got error on SessionSv1.GetActiveSessions: ", err.Error()) // } else if len(*reply) != 4 { // expect to have 4 sessions ( two for 1001 to 1003 *raw and *default and two from 1001 to 1002 *raw and *default) @@ -516,7 +516,7 @@ package general_tests // }, // }, // } -// if err := tutorial2CallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { // t.Fatal(err) // } else if len(*rs) != 1 { // t.Fatalf("Resources: %+v", utils.ToJSON(rs)) @@ -540,7 +540,7 @@ package general_tests // time.Sleep(2 * time.Second) // // activeSessions shouldn't be active -// if err := tutorial2CallsRpc.Call(utils.SessionSv1GetActiveSessions, +// if err := tutorial2CallsRpc.Call(context.Background(),utils.SessionSv1GetActiveSessions, // nil, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { // t.Errorf("Got error on SessionSv1.GetActiveSessions: %v and reply: %s", err, utils.ToJSON(reply)) // } @@ -559,7 +559,7 @@ package general_tests // RunIDs: []string{utils.MetaDefault}, // Accounts: []string{"1001"}, // } -// if err := tutorial2CallsRpc.Call(utils.APIerSv2GetCDRs, &req, &rplCdrs); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.APIerSv2GetCDRs, &req, &rplCdrs); err != nil { // t.Error("Unexpected error: ", err.Error()) // } else if len(rplCdrs) != numberOfCDR { // cdr from sync session + cdr from before // t.Fatal("Unexpected number of CDRs returned: ", len(rplCdrs), utils.ToJSON(rplCdrs)) @@ -581,7 +581,7 @@ package general_tests // //check if resource was released // var rsAfter *engine.Resources -// if err := tutorial2CallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rsAfter); err != nil { +// if err := tutorial2CallsRpc.Call(context.Background(),utils.ResourceSv1GetResourcesForEvent, args, &rsAfter); err != nil { // t.Fatal(err) // } else if len(*rsAfter) != 1 { // t.Fatalf("Resources: %+v", rsAfter) diff --git a/general_tests/tutorial2_it_test.go b/general_tests/tutorial2_it_test.go index 0a113e3ed..48959c9b6 100644 --- a/general_tests/tutorial2_it_test.go +++ b/general_tests/tutorial2_it_test.go @@ -22,11 +22,12 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" @@ -37,7 +38,7 @@ import ( var ( tutCfgPath string tutCfg *config.CGRConfig - tutRpc *rpc.Client + tutRpc *birpc.Client tutCfgDir string //run tests for specific configuration tutDelay int ) @@ -117,7 +118,7 @@ func testTutFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{ FolderPath: path.Join(*dataDir, "tariffplans", "tutorial2")} - if err := tutRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, + if err := tutRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } @@ -133,7 +134,7 @@ func testTutGetCost(t *testing.T) { Usage: "45s", } var rply *engine.EventCost - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 0.550000 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -145,7 +146,7 @@ func testTutGetCost(t *testing.T) { AnswerTime: "2019-03-11T09:00:00Z", Usage: "45s", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 1.4 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -164,7 +165,7 @@ func testTutGetCost(t *testing.T) { AnswerTime: "*now", Usage: "45s", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 1.4 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -176,7 +177,7 @@ func testTutGetCost(t *testing.T) { AnswerTime: "2020-01-01T21:00:00Z", Usage: "45s", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 0.55 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -188,7 +189,7 @@ func testTutGetCost(t *testing.T) { AnswerTime: "2019-03-11T21:00:00Z", Usage: "45s", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 0.55 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -200,7 +201,7 @@ func testTutGetCost(t *testing.T) { AnswerTime: "2019-03-11T09:00:00Z", Usage: "1m", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err == nil || + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err == nil || err.Error() != "SERVER_ERROR: UNAUTHORIZED_DESTINATION" { t.Error("Unexpected nil error received: ", err) } @@ -211,7 +212,7 @@ func testTutGetCost(t *testing.T) { AnswerTime: "*now", Usage: "2048", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 2.0 { // FixMe: missing ConnectFee out of Cost t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -224,7 +225,7 @@ func testTutGetCost(t *testing.T) { AnswerTime: "*now", Usage: "1", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 0.1 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -237,7 +238,7 @@ func testTutGetCost(t *testing.T) { AnswerTime: "*now", Usage: "1", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 0.2 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -250,7 +251,7 @@ func testTutGetCost(t *testing.T) { AnswerTime: "*now", Usage: "1", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err == nil || + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err == nil || err.Error() != "SERVER_ERROR: UNAUTHORIZED_DESTINATION" { t.Error("Unexpected nil error received: ", err) } @@ -262,7 +263,7 @@ func testTutGetCost(t *testing.T) { AnswerTime: "*now", Usage: "5m", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 0.1 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -275,7 +276,7 @@ func testTutGetCost(t *testing.T) { Usage: "45s", Category: "reseller1", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 0.1 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -288,7 +289,7 @@ func testTutGetCost(t *testing.T) { Usage: "10m45s", Category: "reseller1", } - if err := tutRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 0.1 { t.Errorf("Unexpected cost received: %f", *rply.Cost) @@ -298,7 +299,7 @@ func testTutGetCost(t *testing.T) { func testTutAccounts(t *testing.T) { // make sure Account was created var acnt *engine.Account - if err := tutRpc.Call(utils.APIerSv2GetAccount, + if err := tutRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &acnt); err != nil { t.Fatal(err) @@ -327,10 +328,10 @@ func testTutAccounts(t *testing.T) { }, } var rplySetBlc string - if err := tutRpc.Call(utils.APIerSv1SetBalance, attrBlc, &rplySetBlc); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1SetBalance, attrBlc, &rplySetBlc); err != nil { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) } - if err := tutRpc.Call(utils.APIerSv2GetAccount, + if err := tutRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &acnt); err != nil { t.Error(err) @@ -347,10 +348,10 @@ func testTutAccounts(t *testing.T) { utils.ID: utils.MetaDefault, }, } - if err := tutRpc.Call(utils.APIerSv1SetBalance, attrBlc, &rplySetBlc); err != nil { + if err := tutRpc.Call(context.Background(), utils.APIerSv1SetBalance, attrBlc, &rplySetBlc); err != nil { t.Error("Got error on APIerSv1.SetBalance: ", err.Error()) } - if err := tutRpc.Call(utils.APIerSv2GetAccount, + if err := tutRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &acnt); err != nil { t.Error(err) @@ -359,7 +360,7 @@ func testTutAccounts(t *testing.T) { } // enable the account again var rplySetAcnt string - if err := tutRpc.Call(utils.APIerSv2SetAccount, + if err := tutRpc.Call(context.Background(), utils.APIerSv2SetAccount, &v2.AttrSetAccount{ Tenant: "cgrates.org", Account: "1001", @@ -370,7 +371,7 @@ func testTutAccounts(t *testing.T) { t.Error(err) } acnt = new(engine.Account) - if err := tutRpc.Call(utils.APIerSv2GetAccount, + if err := tutRpc.Call(context.Background(), utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}, &acnt); err != nil { t.Error(err) diff --git a/general_tests/tutorial_calls_test.go b/general_tests/tutorial_calls_test.go index 7baf4d526..4297440e0 100644 --- a/general_tests/tutorial_calls_test.go +++ b/general_tests/tutorial_calls_test.go @@ -23,8 +23,6 @@ package general_tests import ( "flag" - "net/rpc" - "net/rpc/jsonrpc" "os" "path" "reflect" @@ -33,6 +31,9 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/sessions" @@ -40,7 +41,7 @@ import ( ) var tutorialCallsCfg *config.CGRConfig -var tutorialCallsRpc *rpc.Client +var tutorialCallsRpc *birpc.Client var tutorialCallsPjSuaListener *os.File var fsConfig = flag.String("fsConfig", "/usr/share/cgrates/tutorial_tests/fs_evsock", "FreeSwitch tutorial folder") var kamConfig = flag.String("kamConfig", "/usr/share/cgrates/tutorial_tests/kamevapi", "Kamailio tutorial folder") @@ -253,7 +254,7 @@ func testCallRpcConn(t *testing.T) { func testCallLoadTariffPlanFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := tutorialCallsRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -263,21 +264,21 @@ func testCallLoadTariffPlanFromFolder(t *testing.T) { func testCallAccountsBefore(t *testing.T) { var reply *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := tutorialCallsRpc.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &reply); err != nil { t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() != 10.0 { t.Errorf("Calling APIerSv1.GetBalance received: %f", reply.BalanceMap[utils.MetaMonetary].GetTotalValue()) } var reply2 *engine.Account attrs2 := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1002"} - if err := tutorialCallsRpc.Call(utils.APIerSv2GetAccount, attrs2, &reply2); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs2, &reply2); err != nil { t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) } else if reply2.BalanceMap[utils.MetaMonetary].GetTotalValue() != 10.0 { t.Errorf("Calling APIerSv1.GetBalance received: %f", reply2.BalanceMap[utils.MetaMonetary].GetTotalValue()) } var reply3 *engine.Account attrs3 := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1003"} - if err := tutorialCallsRpc.Call(utils.APIerSv2GetAccount, attrs3, &reply3); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs3, &reply3); err != nil { t.Error("Got error on APIerSv2.GetAccount: ", err.Error()) } else if reply3.BalanceMap[utils.MetaMonetary].GetTotalValue() != 10.0 { t.Errorf("Calling APIerSv1.GetBalance received: %f", reply3.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -290,13 +291,13 @@ func testCallStatMetricsBefore(t *testing.T) { utils.MetaTCC: utils.NotAvailable, utils.MetaTCD: utils.NotAvailable, } - if err := tutorialCallsRpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := tutorialCallsRpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats2"}, &metrics); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics, metrics) { t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics) } - if err := tutorialCallsRpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := tutorialCallsRpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats2_1"}, &metrics); err != nil { t.Error(err) } else if !reflect.DeepEqual(expectedMetrics, metrics) { @@ -318,7 +319,7 @@ func testCallCheckResourceBeforeAllocation(t *testing.T) { utils.OptsResourcesUsageID: "OriginID", }, } - if err := tutorialCallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Fatal(err) } else if len(*rs) != 1 { t.Fatalf("Resources: %+v", utils.ToJSON(rs)) @@ -334,7 +335,7 @@ func testCallCheckResourceBeforeAllocation(t *testing.T) { func testCallCheckThreshold1001Before(t *testing.T) { var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1001", Hits: 0} - if err := tutorialCallsRpc.Call(utils.ThresholdSv1GetThreshold, + if err := tutorialCallsRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd, td) { @@ -345,7 +346,7 @@ func testCallCheckThreshold1001Before(t *testing.T) { func testCallCheckThreshold1002Before(t *testing.T) { var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1002", Hits: 0} - if err := tutorialCallsRpc.Call(utils.ThresholdSv1GetThreshold, + if err := tutorialCallsRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1002"}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd, td) { @@ -395,7 +396,7 @@ func testCallGetActiveSessions(t *testing.T) { Destination: "1002", }, } - if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions, + if err := tutorialCallsRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &reply); err != nil { t.Error("Got error on SessionSv1.GetActiveSessions: ", err.Error()) } else { @@ -469,7 +470,7 @@ func testCallCheckResourceAllocation(t *testing.T) { utils.OptsResourcesUsageID: "OriginID1", }, } - if err := tutorialCallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Fatal(err) } else if len(*rs) != 1 { t.Fatalf("Resources: %+v", utils.ToJSON(rs)) @@ -487,7 +488,7 @@ func testCallCheckResourceAllocation(t *testing.T) { func testCallAccount1001(t *testing.T) { var reply *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := tutorialCallsRpc.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &reply); err != nil { t.Error(err.Error()) } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() == 10.0 { // Make sure we debitted t.Errorf("Expected: 10, received: %+v", reply.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -500,7 +501,7 @@ func testCallAccount1001(t *testing.T) { func testCall1001Cdrs(t *testing.T) { var reply []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{"1001"}} - if err := tutorialCallsRpc.Call(utils.APIerSv2GetCDRs, &req, &reply); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 2 { t.Error("Unexpected number of CDRs returned: ", len(reply)) @@ -541,7 +542,7 @@ func testCall1002Cdrs(t *testing.T) { var reply []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{"1002"}, DestinationPrefixes: []string{"1001"}} - if err := tutorialCallsRpc.Call(utils.APIerSv2GetCDRs, &req, &reply); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 1 { t.Error("Unexpected number of CDRs returned: ", len(reply)) @@ -567,7 +568,7 @@ func testCall1003Cdrs(t *testing.T) { var reply []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{"1003"}, DestinationPrefixes: []string{"1001"}} - if err := tutorialCallsRpc.Call(utils.APIerSv2GetCDRs, &req, &reply); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &reply); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(reply) != 2 { t.Error("Unexpected number of CDRs returned: ", len(reply)) @@ -619,7 +620,7 @@ func testCallStatMetrics(t *testing.T) { utils.MetaTCD: "37s", } - if err := tutorialCallsRpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := tutorialCallsRpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats2"}, &metrics); err != nil { t.Fatal(err) } @@ -632,7 +633,7 @@ func testCallStatMetrics(t *testing.T) { !reflect.DeepEqual(firstStatMetrics4, metrics) { t.Errorf("expecting: %+v, received reply: %s", firstStatMetrics1, metrics) } - if err := tutorialCallsRpc.Call(utils.StatSv1GetQueueStringMetrics, + if err := tutorialCallsRpc.Call(context.Background(), utils.StatSv1GetQueueStringMetrics, &utils.TenantID{Tenant: "cgrates.org", ID: "Stats2_1"}, &metrics); err != nil { t.Error(err) } @@ -659,7 +660,7 @@ func testCallCheckResourceRelease(t *testing.T) { utils.OptsResourcesUsageID: "OriginID2", }, } - if err := tutorialCallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Fatal(err) } else if len(*rs) != 1 { t.Fatalf("Resources: %+v", rs) @@ -673,7 +674,7 @@ func testCallCheckResourceRelease(t *testing.T) { func testCallCheckThreshold1001After(t *testing.T) { var td engine.Threshold - if err := tutorialCallsRpc.Call(utils.ThresholdSv1GetThreshold, + if err := tutorialCallsRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &td); err != nil && err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -683,7 +684,7 @@ func testCallCheckThreshold1001After(t *testing.T) { func testCallCheckThreshold1002After(t *testing.T) { var td engine.Threshold eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1002", Hits: 4} - if err := tutorialCallsRpc.Call(utils.ThresholdSv1GetThreshold, + if err := tutorialCallsRpc.Call(context.Background(), utils.ThresholdSv1GetThreshold, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1002"}, &td); err != nil { t.Error(err) } else if !reflect.DeepEqual(eTd.Tenant, td.Tenant) { @@ -698,7 +699,7 @@ func testCallCheckThreshold1002After(t *testing.T) { func testCallSyncSessions(t *testing.T) { var reply *[]*sessions.ExternalSession // activeSessions shouldn't be active - if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions, + if err := tutorialCallsRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error("Got error on SessionSv1.GetActiveSessions: ", err) } @@ -716,7 +717,7 @@ func testCallSyncSessions(t *testing.T) { } time.Sleep(time.Second) // get active sessions - if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions, + if err := tutorialCallsRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &reply); err != nil { t.Error("Got error on SessionSv1.GetActiveSessions: ", err.Error()) } else if len(*reply) != 4 { // expect to have 4 sessions ( two for 1001 to 1003 *raw and *default and two from 1001 to 1002 *raw and *default) @@ -736,7 +737,7 @@ func testCallSyncSessions(t *testing.T) { utils.OptsResourcesUsageID: "OriginID3", }, } - if err := tutorialCallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil { t.Fatal(err) } else if len(*rs) != 1 { t.Fatalf("Resources: %+v", utils.ToJSON(rs)) @@ -769,7 +770,7 @@ func testCallSyncSessions(t *testing.T) { time.Sleep(2 * time.Second) // activeSessions shouldn't be active - if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions, + if err := tutorialCallsRpc.Call(context.Background(), utils.SessionSv1GetActiveSessions, nil, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Got error on SessionSv1.GetActiveSessions: %v and reply: %s", err, utils.ToJSON(reply)) } @@ -794,7 +795,7 @@ func testCallSyncSessions(t *testing.T) { RunIDs: []string{utils.MetaDefault}, Accounts: []string{"1001"}, } - if err := tutorialCallsRpc.Call(utils.APIerSv2GetCDRs, &req, &rplCdrs); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &rplCdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(rplCdrs) != numberOfCDR { // cdr from sync session + cdr from before t.Fatal("Unexpected number of CDRs returned: ", len(rplCdrs), utils.ToJSON(rplCdrs)) @@ -816,7 +817,7 @@ func testCallSyncSessions(t *testing.T) { //check if resource was released var rsAfter *engine.Resources - if err := tutorialCallsRpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rsAfter); err != nil { + if err := tutorialCallsRpc.Call(context.Background(), utils.ResourceSv1GetResourcesForEvent, args, &rsAfter); err != nil { t.Fatal(err) } else if len(*rsAfter) != 1 { t.Fatalf("Resources: %+v", rsAfter) diff --git a/general_tests/tutorial_it_test.go b/general_tests/tutorial_it_test.go index 12376570d..55b9eb8b5 100644 --- a/general_tests/tutorial_it_test.go +++ b/general_tests/tutorial_it_test.go @@ -23,11 +23,12 @@ package general_tests import ( "flag" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -38,7 +39,7 @@ var ( itTestMongoAtalas = flag.Bool("mongo_atlas", false, "Run the test with mongo atalas connection") tutorialCfgPath string tutorialCfg *config.CGRConfig - tutorialRpc *rpc.Client + tutorialRpc *birpc.Client tutorialConfDIR string //run tests for specific configuration tutorialDelay int @@ -122,7 +123,7 @@ func testTutorialRpcConn(t *testing.T) { func testTutorialFromFolder(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} - if err := tutorialRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := tutorialRpc.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -138,7 +139,7 @@ func testTutorialGetCost(t *testing.T) { Usage: "2m10s", } var rply *engine.EventCost - if err := tutorialRpc.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil { + if err := tutorialRpc.Call(context.Background(), utils.APIerSv1GetCost, &attrs, &rply); err != nil { t.Error("Unexpected nil error received: ", err.Error()) } else if *rply.Cost != 0.716900 { t.Errorf("Unexpected cost received: %f", *rply.Cost) diff --git a/general_tests/twoengines_it_test.go b/general_tests/twoengines_it_test.go index 5aeaadfd3..6d55fe5f7 100644 --- a/general_tests/twoengines_it_test.go +++ b/general_tests/twoengines_it_test.go @@ -22,12 +22,13 @@ along with this program. If not, see package general_tests import ( - "net/rpc" "path" "reflect" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/utils" "github.com/cgrates/cgrates/engine" @@ -38,11 +39,11 @@ import ( var ( engineOneCfgPath string engineOneCfg *config.CGRConfig - engineOneRpc *rpc.Client + engineOneRpc *birpc.Client engineTwoCfgPath string engineTwoCfg *config.CGRConfig - engineTwoRpc *rpc.Client + engineTwoRpc *birpc.Client ) var sTestsTwoEnginesIT = []func(t *testing.T){ @@ -112,7 +113,7 @@ func testTwoEnginesCheckCacheBeforeSet(t *testing.T) { CacheID: utils.CacheThresholdProfiles, ItemID: "cgrates.org:THD_TwoEnginesTest", } - if err := engineOneRpc.Call(utils.CacheSv1HasItem, argHasItem, &reply); err != nil { + if err := engineOneRpc.Call(context.Background(), utils.CacheSv1HasItem, argHasItem, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: false , received: %v ", reply) @@ -121,17 +122,17 @@ func testTwoEnginesCheckCacheBeforeSet(t *testing.T) { argGetItemIDs := utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheThresholdProfiles, } - if err := engineOneRpc.Call(utils.CacheSv1GetItemIDs, argGetItemIDs, &rcvKeys); err == nil || + if err := engineOneRpc.Call(context.Background(), utils.CacheSv1GetItemIDs, argGetItemIDs, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err.Error(), rcvKeys) } - if err := engineTwoRpc.Call(utils.CacheSv1HasItem, argHasItem, &reply); err != nil { + if err := engineTwoRpc.Call(context.Background(), utils.CacheSv1HasItem, argHasItem, &reply); err != nil { t.Error(err) } else if reply { t.Errorf("Expected: false , received: %v ", reply) } - if err := engineTwoRpc.Call(utils.CacheSv1GetItemIDs, argGetItemIDs, &rcvKeys); err == nil || + if err := engineTwoRpc.Call(context.Background(), utils.CacheSv1GetItemIDs, argGetItemIDs, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err.Error(), rcvKeys) } @@ -140,7 +141,7 @@ func testTwoEnginesCheckCacheBeforeSet(t *testing.T) { func testTwoEnginesSetThreshold(t *testing.T) { var reply *engine.ThresholdProfile // enforce caching with nil on engine2 so CacheSv1.ReloadCache load correctly the threshold - if err := engineTwoRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := engineTwoRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_TwoEnginesTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) @@ -159,12 +160,12 @@ func testTwoEnginesSetThreshold(t *testing.T) { Async: true, }, } - if err := engineOneRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := engineOneRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := engineOneRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := engineOneRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_TwoEnginesTest"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) { @@ -179,7 +180,7 @@ func testTwoEnginesCheckCacheAfterSet(t *testing.T) { CacheID: utils.CacheThresholdProfiles, ItemID: "cgrates.org:THD_TwoEnginesTest", } - if err := engineOneRpc.Call(utils.CacheSv1HasItem, argHasItem, &reply); err != nil { + if err := engineOneRpc.Call(context.Background(), utils.CacheSv1HasItem, argHasItem, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: %v , received:%v", expected, reply) @@ -189,18 +190,18 @@ func testTwoEnginesCheckCacheAfterSet(t *testing.T) { argGetItemIDs := utils.ArgsGetCacheItemIDs{ CacheID: utils.CacheThresholdProfiles, } - if err := engineOneRpc.Call(utils.CacheSv1GetItemIDs, argGetItemIDs, &rcvKeys); err != nil { + if err := engineOneRpc.Call(context.Background(), utils.CacheSv1GetItemIDs, argGetItemIDs, &rcvKeys); err != nil { t.Fatalf("Got error on APIerSv1.GetCacheStats: %s ", err.Error()) } else if !reflect.DeepEqual(expKeys, rcvKeys) { t.Errorf("Expected: %+v, received: %+v", expKeys, rcvKeys) } - if err := engineTwoRpc.Call(utils.CacheSv1HasItem, argHasItem, &reply); err != nil { + if err := engineTwoRpc.Call(context.Background(), utils.CacheSv1HasItem, argHasItem, &reply); err != nil { t.Error(err) } else if !reply { t.Errorf("Expected: %v , received:%v", expected, reply) } - if err := engineTwoRpc.Call(utils.CacheSv1GetItemIDs, argGetItemIDs, &rcvKeys); err != nil { + if err := engineTwoRpc.Call(context.Background(), utils.CacheSv1GetItemIDs, argGetItemIDs, &rcvKeys); err != nil { t.Fatalf("Got error on APIerSv1.GetCacheStats: %s ", err.Error()) } else if !reflect.DeepEqual(expKeys, rcvKeys) { t.Errorf("Expected: %+v, received: %+v", expKeys, rcvKeys) @@ -220,7 +221,7 @@ func testTwoEnginesCheckCacheAfterSet(t *testing.T) { }, } var rplTh *engine.ThresholdProfile - if err := engineTwoRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := engineTwoRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_TwoEnginesTest"}, &rplTh); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, rplTh) { @@ -247,18 +248,18 @@ func testTwoEnginesUpdateThreshold(t *testing.T) { utils.CacheOpt: utils.MetaReload, }, } - if err := engineOneRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { + if err := engineOneRpc.Call(context.Background(), utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil { t.Error(err) } else if result != utils.OK { t.Error("Unexpected reply returned", result) } - if err := engineOneRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := engineOneRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_TwoEnginesTest"}, &rplTh); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, rplTh) { t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, rplTh) } - if err := engineTwoRpc.Call(utils.APIerSv1GetThresholdProfile, + if err := engineTwoRpc.Call(context.Background(), utils.APIerSv1GetThresholdProfile, &utils.TenantID{Tenant: "cgrates.org", ID: "THD_TwoEnginesTest"}, &rplTh); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, rplTh) { diff --git a/go.mod b/go.mod index 324a83e07..82cce8d94 100644 --- a/go.mod +++ b/go.mod @@ -17,14 +17,14 @@ require ( github.com/antchfx/xmlquery v1.3.3 github.com/aws/aws-sdk-go v1.36.24 github.com/blevesearch/bleve v1.0.14 - github.com/cenkalti/rpc2 v0.0.0-20210604223624-c1acbc6ec984 github.com/cgrates/aringo v0.0.0-20220525160735-b5990313d99e github.com/cgrates/baningo v0.0.0-20210413080722-004ffd5e429f + github.com/cgrates/birpc v1.3.1-0.20211117095917-5b0ff29f3084 github.com/cgrates/fsock v0.0.0-20230123160954-12cae14030cc github.com/cgrates/kamevapi v0.0.0-20220525160402-5b8036487a6c github.com/cgrates/ltcache v0.0.0-20210405185848-da943e80c1ab github.com/cgrates/radigo v0.0.0-20210902121842-ea2f9a730627 - github.com/cgrates/rpcclient v0.0.0-20210218104959-cc39fa26221e + github.com/cgrates/rpcclient v0.0.0-20230605090759-8bb5188b73e5 github.com/cgrates/sipingo v1.0.1-0.20200514112313-699ebc1cdb8e github.com/cgrates/ugocodec v0.0.0-20201023092048-df93d0123f60 github.com/creack/pty v1.1.11 diff --git a/go.sum b/go.sum index 9987834f7..bb9515ebd 100644 --- a/go.sum +++ b/go.sum @@ -77,14 +77,13 @@ github.com/cenk/hub v1.0.1 h1:RBwXNOF4a8KjD8BJ08XqN8KbrqaGiQLDrgvUGJSHuPA= github.com/cenk/hub v1.0.1/go.mod h1:rJM1LNAW0ppT8FMMuPK6c2NP/R2nH/UthtuRySSaf6Y= github.com/cenkalti/hub v1.0.1 h1:UMtjc6dHSaOQTO15SVA50MBIR9zQwvsukQupDrkIRtg= github.com/cenkalti/hub v1.0.1/go.mod h1:tcYwtS3a2d9NO/0xDXVJWx3IedurUjYCqFCmpi0lpHs= -github.com/cenkalti/rpc2 v0.0.0-20210117202628-1bea588996c7/go.mod h1:v2npkhrXyk5BCnkNIiPdRI23Uq6uWPUQGL2hnRcRr/M= -github.com/cenkalti/rpc2 v0.0.0-20210604223624-c1acbc6ec984 h1:CNwZyGS6KpfaOWbh2yLkSy3rSTUh3jub9CzpFpP6PVQ= -github.com/cenkalti/rpc2 v0.0.0-20210604223624-c1acbc6ec984/go.mod h1:v2npkhrXyk5BCnkNIiPdRI23Uq6uWPUQGL2hnRcRr/M= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cgrates/aringo v0.0.0-20220525160735-b5990313d99e h1:jbScwE0ebeCBD9CsuCfqMv2oC2KUf+FxEePBxAaF1cQ= github.com/cgrates/aringo v0.0.0-20220525160735-b5990313d99e/go.mod h1:v+wPvWvfle06wQ7WBJZGXvrF+CWA0CrReh+c3PuXaAU= github.com/cgrates/baningo v0.0.0-20210413080722-004ffd5e429f h1:dCp5BflGB8I8wlhWn4R5g0o4ok2pZRmcYHyzIks9Pbc= github.com/cgrates/baningo v0.0.0-20210413080722-004ffd5e429f/go.mod h1:3SwVROaS1Iml5lqEhj0gRhDRtmbBgypZpKcEkVTSleU= +github.com/cgrates/birpc v1.3.1-0.20211117095917-5b0ff29f3084 h1:YIEepjEOjeHaFrewWaar/JkXYiDgO7gRw/R1zWITxEw= +github.com/cgrates/birpc v1.3.1-0.20211117095917-5b0ff29f3084/go.mod h1:z/PmNnDPqSQALedKJv5T8+eXIq6XHa9J0St1YsvAVns= github.com/cgrates/fsock v0.0.0-20230123160954-12cae14030cc h1:qKfOK61ZLktbywOLTMNWwobJsxkxszlMbuduwNgAO/c= github.com/cgrates/fsock v0.0.0-20230123160954-12cae14030cc/go.mod h1:5A9wag324AzIlaDd7tpPDAg26ouUO1orarAq7Vxr4As= github.com/cgrates/kamevapi v0.0.0-20220525160402-5b8036487a6c h1:ILTMiCcBw80hSe1L0LE3u2U7sFQB/vcFc2JZpvTD4/E= @@ -93,8 +92,8 @@ github.com/cgrates/ltcache v0.0.0-20210405185848-da943e80c1ab h1:dKdAUwrij6vYwew github.com/cgrates/ltcache v0.0.0-20210405185848-da943e80c1ab/go.mod h1:9oSG/6gUoab/vKm/eQ3QcX6KeTR0wRw88N33iCnC/k4= github.com/cgrates/radigo v0.0.0-20210902121842-ea2f9a730627 h1:foxHlpQxYj15khhlpbj+EiIM/W9Gk0HP800NQ/DVPpU= github.com/cgrates/radigo v0.0.0-20210902121842-ea2f9a730627/go.mod h1:PizDxlLTjVQpyPU0ksWYfmM9UbYGu7q6at0nzuiZprI= -github.com/cgrates/rpcclient v0.0.0-20210218104959-cc39fa26221e h1:OhIDLqNfNx9n64DAZhqIsJsWh8KXrZmvpwUg3WDmPww= -github.com/cgrates/rpcclient v0.0.0-20210218104959-cc39fa26221e/go.mod h1:1lZpAp/cwSuf9Kt+ZSd3hgCt/7E1z3dx5GwkdlgKBTI= +github.com/cgrates/rpcclient v0.0.0-20230605090759-8bb5188b73e5 h1:GhA5qBUK7o0j+7fi1GACKnT454pv/LfCjoI52vFIz3E= +github.com/cgrates/rpcclient v0.0.0-20230605090759-8bb5188b73e5/go.mod h1:tDqS6BieViKYpz696//gxseUN1b92hPHqk+w0CzY8AE= github.com/cgrates/sipingo v1.0.1-0.20200514112313-699ebc1cdb8e h1:izFjZB83/XRXInc+gMIssUxdbleGsGIuGCPj2u7RQo0= github.com/cgrates/sipingo v1.0.1-0.20200514112313-699ebc1cdb8e/go.mod h1:0f2+3dq5Iiv3VlcuY83VPJ0QzqRlzDG1Cr8okogQE3g= github.com/cgrates/ugocodec v0.0.0-20201023092048-df93d0123f60 h1:TQDg+HGB17LU8FitLiLvYazYSy62GQ1lO3lGKI3xUrU= diff --git a/loaders/lib_test.go b/loaders/lib_test.go index 571182537..f8c757d81 100644 --- a/loaders/lib_test.go +++ b/loaders/lib_test.go @@ -23,11 +23,12 @@ import ( "errors" "flag" "io" - "net/rpc" - "net/rpc/jsonrpc" "strings" "testing" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/rpcclient" "github.com/cgrates/cgrates/config" @@ -46,12 +47,12 @@ var loaderPaths = []string{"/tmp/In", "/tmp/Out", "/tmp/LoaderIn", "/tmp/Subpath "/tmp/SubpathLoaderWithMove", "/tmp/SubpathOut", "/tmp/templateLoaderIn", "/tmp/templateLoaderOut", "/tmp/customSepLoaderIn", "/tmp/customSepLoaderOut"} -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } @@ -61,7 +62,7 @@ type testMockCacheConn struct { calls map[string]func(arg any, rply any) error } -func (s *testMockCacheConn) Call(method string, arg any, rply any) error { +func (s *testMockCacheConn) Call(ctx *context.Context, method string, arg any, rply any) error { if call, has := s.calls[method]; !has { return rpcclient.ErrUnsupporteServiceMethod } else { @@ -97,12 +98,12 @@ func TestProcessContentCallsRemoveItems(t *testing.T) { } data := engine.NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) - internalCacheSChan := make(chan rpcclient.ClientConnector, 1) + internalCacheSChan := make(chan birpc.ClientConnector, 1) internalCacheSChan <- sMock ldr := &Loader{ ldrID: "TestProcessContentCallsRemoveItems", bufLoaderData: make(map[string][]LoaderData), - connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{ + connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): internalCacheSChan, }), dm: engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil), @@ -201,12 +202,12 @@ func TestProcessContentCallsClear(t *testing.T) { } data := engine.NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) - internalCacheSChan := make(chan rpcclient.ClientConnector, 1) + internalCacheSChan := make(chan birpc.ClientConnector, 1) internalCacheSChan <- sMock ldr := &Loader{ ldrID: "TestProcessContentCallsClear", bufLoaderData: make(map[string][]LoaderData), - connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{ + connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): internalCacheSChan, }), dm: engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil), @@ -312,12 +313,12 @@ func TestRemoveContentCallsReload(t *testing.T) { } data := engine.NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) - internalCacheSChan := make(chan rpcclient.ClientConnector, 1) + internalCacheSChan := make(chan birpc.ClientConnector, 1) internalCacheSChan <- sMock ldr := &Loader{ ldrID: "TestRemoveContentCallsReload", bufLoaderData: make(map[string][]LoaderData), - connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{ + connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): internalCacheSChan, }), cacheConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, @@ -418,12 +419,12 @@ func TestRemoveContentCallsLoad(t *testing.T) { } data := engine.NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) - internalCacheSChan := make(chan rpcclient.ClientConnector, 1) + internalCacheSChan := make(chan birpc.ClientConnector, 1) internalCacheSChan <- sMock ldr := &Loader{ ldrID: "TestRemoveContentCallsReload", bufLoaderData: make(map[string][]LoaderData), - connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{ + connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): internalCacheSChan, }), cacheConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, @@ -524,12 +525,12 @@ func TestRemoveContentCallsRemove(t *testing.T) { } data := engine.NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) - internalCacheSChan := make(chan rpcclient.ClientConnector, 1) + internalCacheSChan := make(chan birpc.ClientConnector, 1) internalCacheSChan <- sMock ldr := &Loader{ ldrID: "TestRemoveContentCallsReload", bufLoaderData: make(map[string][]LoaderData), - connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{ + connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): internalCacheSChan, }), cacheConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, @@ -641,12 +642,12 @@ func TestRemoveContentCallsClear(t *testing.T) { } data := engine.NewInternalDB(nil, nil, true, config.CgrConfig().DataDbCfg().Items) - internalCacheSChan := make(chan rpcclient.ClientConnector, 1) + internalCacheSChan := make(chan birpc.ClientConnector, 1) internalCacheSChan <- sMock ldr := &Loader{ ldrID: "TestRemoveContentCallsReload", bufLoaderData: make(map[string][]LoaderData), - connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{ + connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): internalCacheSChan, }), cacheConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)}, diff --git a/loaders/loader_it_test.go b/loaders/loader_it_test.go index 0a5d99928..be43ac48e 100644 --- a/loaders/loader_it_test.go +++ b/loaders/loader_it_test.go @@ -23,7 +23,6 @@ package loaders import ( "encoding/csv" "io" - "net/rpc" "os" "path" "reflect" @@ -32,6 +31,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -41,7 +42,7 @@ var ( loaderCfgPath string loaderCfgDIR string //run tests for specific configuration loaderCfg *config.CGRConfig - loaderRPC *rpc.Client + loaderRPC *birpc.Client customAttributes = "12012000001\t12018209998\n12012000002\t15512580598\n12012000007\t19085199998\n12012000008\t18622784999\n12012000010\t17329440866\n12012000011\t18623689800\n12012000012\t19082050951\n12012000014\t17329440866\n12012000015\t12018209999\n12012000031\t12018209999\n12012000032\t19082050951\n12012000033\t12018209998\n12012000034\t12018209998\n" sTestsLoader = []func(t *testing.T){ @@ -169,7 +170,7 @@ func testLoaderPopulateData(t *testing.T) { func testLoaderLoadAttributes(t *testing.T) { var reply string - if err := loaderRPC.Call(utils.LoaderSv1Load, + if err := loaderRPC.Call(context.Background(), utils.LoaderSv1Load, &ArgsProcessFolder{LoaderID: "CustomLoader"}, &reply); err != nil { t.Error(err) } @@ -212,7 +213,7 @@ func testLoaderCheckAttributes(t *testing.T) { eAttrPrf.Attributes[1].FilterIDs = nil } var reply *engine.AttributeProfile - if err := loaderRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := loaderRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ALS1"}, }, &reply); err != nil { @@ -240,7 +241,7 @@ func testLoaderPopulateDataWithoutMoving(t *testing.T) { func testLoaderLoadAttributesWithoutMoving(t *testing.T) { var reply string - if err := loaderRPC.Call(utils.LoaderSv1Load, + if err := loaderRPC.Call(context.Background(), utils.LoaderSv1Load, &ArgsProcessFolder{LoaderID: "WithoutMoveToOut"}, &reply); err != nil { t.Error(err) } @@ -272,7 +273,7 @@ func testLoaderPopulateDataWithSubpath(t *testing.T) { func testLoaderLoadAttributesWithSubpath(t *testing.T) { var reply string - if err := loaderRPC.Call(utils.LoaderSv1Load, + if err := loaderRPC.Call(context.Background(), utils.LoaderSv1Load, &ArgsProcessFolder{LoaderID: "SubpathLoaderWithoutMove"}, &reply); err != nil { t.Error(err) } @@ -304,7 +305,7 @@ func testLoaderPopulateDataWithSubpathWithMove(t *testing.T) { func testLoaderLoadAttributesWithoutSubpathWithMove(t *testing.T) { var reply string - if err := loaderRPC.Call(utils.LoaderSv1Load, + if err := loaderRPC.Call(context.Background(), utils.LoaderSv1Load, &ArgsProcessFolder{LoaderID: "SubpathLoaderWithMove"}, &reply); err != nil { t.Error(err) } @@ -335,7 +336,7 @@ func testLoaderPopulateDataForTemplateLoader(t *testing.T) { func testLoaderLoadAttributesForTemplateLoader(t *testing.T) { var reply string - if err := loaderRPC.Call(utils.LoaderSv1Load, + if err := loaderRPC.Call(context.Background(), utils.LoaderSv1Load, &ArgsProcessFolder{LoaderID: "LoaderWithTemplate"}, &reply); err != nil { t.Error(err) } @@ -390,7 +391,7 @@ func testLoaderCheckForCustomSep(t *testing.T) { eAttrPrf.Attributes[0].FilterIDs = nil } var reply *engine.AttributeProfile - if err := loaderRPC.Call(utils.APIerSv1GetAttributeProfile, + if err := loaderRPC.Call(context.Background(), utils.APIerSv1GetAttributeProfile, &utils.TenantIDWithAPIOpts{ TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_12012000001"}, }, &reply); err != nil { diff --git a/loaders/loader_test.go b/loaders/loader_test.go index 821bd9d4c..4e9e581a9 100644 --- a/loaders/loader_test.go +++ b/loaders/loader_test.go @@ -27,6 +27,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/engine" "github.com/cgrates/rpcclient" @@ -3042,7 +3044,7 @@ type ccMock struct { calls map[string]func(args any, reply any) error } -func (ccM *ccMock) Call(serviceMethod string, args any, reply any) (err error) { +func (ccM *ccMock) Call(_ *context.Context, serviceMethod string, args any, reply any) (err error) { if call, has := ccM.calls[serviceMethod]; !has { return rpcclient.ErrUnsupporteServiceMethod } else { @@ -3073,9 +3075,9 @@ func TestStoreLoadedDataAttributes(t *testing.T) { }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- cM - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), connMgr) @@ -3122,9 +3124,9 @@ func TestStoreLoadedDataResources(t *testing.T) { }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- cM - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), connMgr) @@ -3170,9 +3172,9 @@ func TestStoreLoadedDataFilters(t *testing.T) { }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- cM - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), connMgr) @@ -3219,9 +3221,9 @@ func TestStoreLoadedDataStats(t *testing.T) { }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- cM - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), connMgr) @@ -3268,9 +3270,9 @@ func TestStoreLoadedDataThresholds(t *testing.T) { }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- cM - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), connMgr) @@ -3316,9 +3318,9 @@ func TestStoreLoadedDataRoutes(t *testing.T) { }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- cM - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), connMgr) @@ -3364,9 +3366,9 @@ func TestStoreLoadedDataChargers(t *testing.T) { }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- cM - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), connMgr) @@ -3412,9 +3414,9 @@ func TestStoreLoadedDataDispatchers(t *testing.T) { }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- cM - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), connMgr) @@ -3460,9 +3462,9 @@ func TestStoreLoadedDataDispatcherHosts(t *testing.T) { }, } - rpcInternal := make(chan rpcclient.ClientConnector, 1) + rpcInternal := make(chan birpc.ClientConnector, 1) rpcInternal <- cM - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): rpcInternal, }) dm := engine.NewDataManager(data, config.CgrConfig().CacheCfg(), connMgr) diff --git a/loaders/loaders.go b/loaders/loaders.go index 47b024ebd..c1c8b0654 100644 --- a/loaders/loaders.go +++ b/loaders/loaders.go @@ -23,6 +23,7 @@ import ( "fmt" "sync" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -68,7 +69,7 @@ type ArgsProcessFolder struct { StopOnError bool } -func (ldrS *LoaderService) V1Load(args *ArgsProcessFolder, +func (ldrS *LoaderService) V1Load(ctx *context.Context, args *ArgsProcessFolder, rply *string) (err error) { ldrS.RLock() defer ldrS.RUnlock() @@ -101,7 +102,7 @@ func (ldrS *LoaderService) V1Load(args *ArgsProcessFolder, return } -func (ldrS *LoaderService) V1Remove(args *ArgsProcessFolder, +func (ldrS *LoaderService) V1Remove(ctx *context.Context, args *ArgsProcessFolder, rply *string) (err error) { ldrS.RLock() defer ldrS.RUnlock() diff --git a/loaders/loaders_it_test.go b/loaders/loaders_it_test.go index c5750f688..6503e445d 100644 --- a/loaders/loaders_it_test.go +++ b/loaders/loaders_it_test.go @@ -31,6 +31,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" @@ -124,12 +125,12 @@ cgrates.org,NewRes1`)); err != nil { var reply string expected := "ANOTHER_LOADER_RUNNING" //cannot load when there is another loader running - if err := ldrs.V1Load(&ArgsProcessFolder{LoaderID: "testV1LoadResource"}, + if err := ldrs.V1Load(context.Background(), &ArgsProcessFolder{LoaderID: "testV1LoadResource"}, &reply); err == nil || reply != utils.EmptyString || err.Error() != expected { t.Errorf("Expected %+v and %+v \n, received %+v and %+v", expected, utils.EmptyString, err, reply) } - if err := ldrs.V1Load(&ArgsProcessFolder{LoaderID: "testV1LoadResource", ForceLock: true}, + if err := ldrs.V1Load(context.Background(), &ArgsProcessFolder{LoaderID: "testV1LoadResource", ForceLock: true}, &reply); err != nil && reply != utils.OK { t.Error(err) } @@ -183,7 +184,7 @@ cgrates.org,NewRes1 var reply string ldrs := NewLoaderService(dm, cfgLdr, "UTC", nil, nil) - if err := ldrs.V1Load(&ArgsProcessFolder{ + if err := ldrs.V1Load(context.Background(), &ArgsProcessFolder{ LoaderID: utils.EmptyString}, &reply); err == nil && reply != utils.EmptyString && err.Error() != utils.EmptyString { t.Errorf("Expected %+v and %+v \n, received %+v and %+v", utils.EmptyString, utils.EmptyString, err, reply) } @@ -220,9 +221,10 @@ func testV1LoadUnableToDeleteFile(t *testing.T) { var reply string ldrs := NewLoaderService(dm, cfgLdr, "UTC", nil, nil) expected := "SERVER_ERROR: stat /\x00/Resources.csv: invalid argument" - if err := ldrs.V1Load(&ArgsProcessFolder{ - LoaderID: "testV1LoadUnableToDeleteFile", - ForceLock: true}, &reply); err == nil || err.Error() != expected { + if err := ldrs.V1Load(context.Background(), + &ArgsProcessFolder{ + LoaderID: "testV1LoadUnableToDeleteFile", + ForceLock: true}, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v and %+v \n, received %+v and %+v", utils.EmptyString, utils.EmptyString, err, reply) } @@ -289,11 +291,12 @@ NOT_UINT var reply string expected := "SERVER_ERROR: open testV1LoadProcessFolderError/not_a_file: no such file or directory" //try to load by changing the caching method - if err := ldrs.V1Load(&ArgsProcessFolder{ - LoaderID: "testV1LoadResource", - ForceLock: true, - Caching: utils.StringPointer("not_a_chaching_method"), - StopOnError: true}, &reply); err == nil || err.Error() != expected || reply != utils.EmptyString { + if err := ldrs.V1Load(context.Background(), + &ArgsProcessFolder{ + LoaderID: "testV1LoadResource", + ForceLock: true, + Caching: utils.StringPointer("not_a_chaching_method"), + StopOnError: true}, &reply); err == nil || err.Error() != expected || reply != utils.EmptyString { t.Errorf("Expected %+q and %+q \n, received %+q and %+q", expected, utils.EmptyString, err, reply) } @@ -368,15 +371,16 @@ cgrates.org,NewRes1`)) var reply string expected := "ANOTHER_LOADER_RUNNING" //cannot load when there is another loader running - if err := ldrs.V1Remove(&ArgsProcessFolder{LoaderID: "testV1RemoveResource"}, + if err := ldrs.V1Remove(context.Background(), &ArgsProcessFolder{LoaderID: "testV1RemoveResource"}, &reply); err == nil || reply != utils.EmptyString || err.Error() != expected { t.Errorf("Expected %+v and %+v \n, received %+v and %+v", expected, utils.EmptyString, err, reply) } os.Remove(path.Join(flPath, "lock.cgr")) - if err := ldrs.V1Remove(&ArgsProcessFolder{ - LoaderID: "testV1RemoveResource", - ForceLock: true}, &reply); err != nil && reply != utils.OK { + if err := ldrs.V1Remove(context.Background(), + &ArgsProcessFolder{ + LoaderID: "testV1RemoveResource", + ForceLock: true}, &reply); err != nil && reply != utils.OK { t.Error(err) } @@ -421,7 +425,7 @@ cgrates.org,NewRes1 var reply string ldrs := NewLoaderService(dm, cfgLdr, "UTC", nil, nil) expected := "UNKNOWN_LOADER: *default" - if err := ldrs.V1Remove(&ArgsProcessFolder{ + if err := ldrs.V1Remove(context.Background(), &ArgsProcessFolder{ LoaderID: utils.EmptyString}, &reply); err == nil || reply != utils.EmptyString || err.Error() != expected { t.Errorf("Expected %+v and %+v \n, received %+v and %+v", expected, utils.EmptyString, err, reply) } @@ -458,9 +462,10 @@ func testV1RemoveUnableToDeleteFile(t *testing.T) { var reply string ldrs := NewLoaderService(dm, cfgLdr, "UTC", nil, nil) expected := "SERVER_ERROR: stat /\x00/Resources.csv: invalid argument" - if err := ldrs.V1Remove(&ArgsProcessFolder{ - LoaderID: "testV1RemoveUnableToDeleteFile", - ForceLock: true}, &reply); err == nil || err.Error() != expected { + if err := ldrs.V1Remove(context.Background(), + &ArgsProcessFolder{ + LoaderID: "testV1RemoveUnableToDeleteFile", + ForceLock: true}, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v and %+v \n, received %+v and %+v", utils.EmptyString, utils.EmptyString, err, reply) } @@ -505,20 +510,22 @@ func testV1LoadAndRemoveProcessRemoveFolderError(t *testing.T) { var reply string expected := "SERVER_ERROR: remove /tmp/testV1RemoveProcessFolderError: directory not empty" //try to load by changing the caching method, but there is not a lockFileName - if err := ldrs.V1Load(&ArgsProcessFolder{ - LoaderID: "testV1RemoveProcessFolderError", - ForceLock: true, - Caching: utils.StringPointer("not_a_chaching_method"), - StopOnError: true}, &reply); err == nil || err.Error() != expected || reply != utils.EmptyString { + if err := ldrs.V1Load(context.Background(), + &ArgsProcessFolder{ + LoaderID: "testV1RemoveProcessFolderError", + ForceLock: true, + Caching: utils.StringPointer("not_a_chaching_method"), + StopOnError: true}, &reply); err == nil || err.Error() != expected || reply != utils.EmptyString { t.Errorf("Expected %+q and %+q \n, received %+q and %+q", expected, utils.EmptyString, err, reply) } //try to remove by changing the caching method - if err := ldrs.V1Remove(&ArgsProcessFolder{ - LoaderID: "testV1RemoveProcessFolderError", - ForceLock: true, - Caching: utils.StringPointer("not_a_chaching_method"), - StopOnError: true}, &reply); err == nil || err.Error() != expected || reply != utils.EmptyString { + if err := ldrs.V1Remove(context.Background(), + &ArgsProcessFolder{ + LoaderID: "testV1RemoveProcessFolderError", + ForceLock: true, + Caching: utils.StringPointer("not_a_chaching_method"), + StopOnError: true}, &reply); err == nil || err.Error() != expected || reply != utils.EmptyString { t.Errorf("Expected %+q and %+q \n, received %+q and %+q", expected, utils.EmptyString, err, reply) } @@ -563,11 +570,12 @@ func testV1RemoveProcessFolderError(t *testing.T) { var reply string expected := "SERVER_ERROR: open testV1RemoveProcessFolderError/not_a_file2: no such file or directory" //try to load by changing the caching method - if err := ldrs.V1Remove(&ArgsProcessFolder{ - LoaderID: "testV1RemoveProcessFolderError", - ForceLock: true, - Caching: utils.StringPointer("not_a_chaching_method"), - StopOnError: true}, &reply); err == nil || err.Error() != expected || reply != utils.EmptyString { + if err := ldrs.V1Remove(context.Background(), + &ArgsProcessFolder{ + LoaderID: "testV1RemoveProcessFolderError", + ForceLock: true, + Caching: utils.StringPointer("not_a_chaching_method"), + StopOnError: true}, &reply); err == nil || err.Error() != expected || reply != utils.EmptyString { t.Errorf("Expected %+q and %+q \n, received %+q and %+q", expected, utils.EmptyString, err, reply) } diff --git a/registrarc/lib_test.go b/registrarc/lib_test.go index f60a86188..c99378ff5 100644 --- a/registrarc/lib_test.go +++ b/registrarc/lib_test.go @@ -20,9 +20,9 @@ package registrarc import ( "errors" "flag" - "net/rpc" - "net/rpc/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) @@ -34,12 +34,12 @@ var ( dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/registrarc/libregistrarc_test.go b/registrarc/libregistrarc_test.go index 819e6e1c0..5b7889e26 100644 --- a/registrarc/libregistrarc_test.go +++ b/registrarc/libregistrarc_test.go @@ -27,6 +27,7 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -232,7 +233,7 @@ func TestRegister(t *testing.T) { } errCfg := config.NewDefaultCGRConfig() - engine.NewConnManager(errCfg, map[string]chan rpcclient.ClientConnector{}) + engine.NewConnManager(errCfg, map[string]chan birpc.ClientConnector{}) errCfg.CacheCfg().Partitions[utils.CacheDispatcherHosts].Replicate = true errCfg.RPCConns()["errCon"] = &config.RPCConn{ Strategy: utils.MetaFirst, @@ -514,7 +515,7 @@ func TestRegisterRegistrarSv1UnregisterRPCHostsError(t *testing.T) { }, }, } - engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{}) + engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{}) cfg.RPCConns()["errCon"] = config.CgrConfig().RPCConns()["errCon"] cfg.CacheCfg().ReplicationConns = []string{"errCon"} cfg.CacheCfg().Partitions[utils.CacheRPCConnections].Replicate = true @@ -615,7 +616,7 @@ func TestRegisterRegistrarSv1RegisterRPCHostsError(t *testing.T) { }, }, } - engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{}) + engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{}) cfg.RPCConns()["errCon1"] = config.CgrConfig().RPCConns()["errCon1"] cfg.CacheCfg().ReplicationConns = []string{"errCon1"} cfg.CacheCfg().Partitions[utils.CacheRPCConnections].Replicate = true diff --git a/registrarc/registrarc.go b/registrarc/registrarc.go index f76ba936c..de13941c0 100644 --- a/registrarc/registrarc.go +++ b/registrarc/registrarc.go @@ -22,6 +22,7 @@ import ( "fmt" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -115,7 +116,7 @@ func (dhS *RegistrarCService) registerDispHosts() { continue } var rply string - if err := dhS.connMgr.Call([]string{connID}, nil, utils.RegistrarSv1RegisterDispatcherHosts, args, &rply); err != nil { + if err := dhS.connMgr.Call(context.TODO(), []string{connID}, utils.RegistrarSv1RegisterDispatcherHosts, args, &rply); err != nil { utils.Logger.Warning(fmt.Sprintf("<%s> Unable to set the hosts to the conn with ID <%s> because : %s", utils.RegistrarC, connID, err)) continue @@ -135,7 +136,7 @@ func (dhS *RegistrarCService) registerRPCHosts() { continue } var rply string - if err := dhS.connMgr.Call([]string{connID}, nil, utils.RegistrarSv1RegisterRPCHosts, args, &rply); err != nil { + if err := dhS.connMgr.Call(context.TODO(), []string{connID}, utils.RegistrarSv1RegisterRPCHosts, args, &rply); err != nil { utils.Logger.Warning(fmt.Sprintf("<%s> Unable to set the hosts to the conn with ID <%s> because : %s", utils.RegistrarC, connID, err)) continue @@ -151,7 +152,7 @@ func unregisterHosts(connMgr *engine.ConnManager, regCfg *config.RegistrarCCfg, if tnt == utils.MetaDefault { tnt = dTnt } - if err := connMgr.Call([]string{connID}, nil, method, NewUnregisterArgs(tnt, hostCfgs), &rply); err != nil { + if err := connMgr.Call(context.TODO(), []string{connID}, method, NewUnregisterArgs(tnt, hostCfgs), &rply); err != nil { utils.Logger.Warning(fmt.Sprintf("<%s> Unable to unregister the hosts with tenant<%s> to the conn with ID <%s> because : %s", utils.RegistrarC, tnt, connID, err)) } diff --git a/registrarc/registrarc_it_test.go b/registrarc/registrarc_it_test.go index 4249ba3ef..c39191414 100644 --- a/registrarc/registrarc_it_test.go +++ b/registrarc/registrarc_it_test.go @@ -23,12 +23,14 @@ package registrarc import ( "bytes" - "net/rpc" "os/exec" "path" "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -39,7 +41,7 @@ var ( dspCfgPath string dspCfg *config.CGRConfig dspCmd *exec.Cmd - dspRPC *rpc.Client + dspRPC *birpc.Client allDir string allCfgPath string @@ -128,7 +130,7 @@ func testDsphLoadData(t *testing.T) { func testDsphGetNodeID() (id string, err error) { var status map[string]any - if err = dspRPC.Call(utils.DispatcherSv1RemoteStatus, utils.TenantWithAPIOpts{ + if err = dspRPC.Call(context.Background(), utils.DispatcherSv1RemoteStatus, utils.TenantWithAPIOpts{ Tenant: "cgrates.org", APIOpts: map[string]any{}, }, &status); err != nil { diff --git a/registrarc/registrarc_test.go b/registrarc/registrarc_test.go index 6b953eedf..6b70cf9b0 100644 --- a/registrarc/registrarc_test.go +++ b/registrarc/registrarc_test.go @@ -25,6 +25,7 @@ import ( "testing" "time" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -55,7 +56,7 @@ func TestDispatcherHostsService(t *testing.T) { cfg.RegistrarCCfg().Dispatchers.RefreshInterval = 100 * time.Millisecond cfg.RegistrarCCfg().Dispatchers.RegistrarSConns = []string{"conn1"} - ds := NewRegistrarCService(cfg, engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{})) + ds := NewRegistrarCService(cfg, engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{})) ds.registerDispHosts() @@ -115,7 +116,7 @@ func TestDispatcherHostsService(t *testing.T) { cfg.ListenCfg().RPCJSONListen = "2012" ds.registerDispHosts() - ds = NewRegistrarCService(cfg, engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{})) + ds = NewRegistrarCService(cfg, engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{})) ds.Shutdown() stopChan := make(chan struct{}) close(stopChan) @@ -173,11 +174,11 @@ func TestRegisterRPCHosts(t *testing.T) { } regist := &RegistrarCService{ cfg: cfg, - connMgr: engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{}), + connMgr: engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{}), } registCmp := &RegistrarCService{ cfg: cfg, - connMgr: engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{}), + connMgr: engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{}), } regist.registerRPCHosts() if !reflect.DeepEqual(regist, registCmp) { diff --git a/registrarc/registrarcrpc_it_test.go b/registrarc/registrarcrpc_it_test.go index ea0a88c48..7b38cc6c0 100644 --- a/registrarc/registrarcrpc_it_test.go +++ b/registrarc/registrarcrpc_it_test.go @@ -22,7 +22,6 @@ along with this program. If not, see package registrarc import ( - "net/rpc" "os/exec" "path" "reflect" @@ -31,6 +30,9 @@ import ( "testing" "time" + "github.com/cgrates/birpc/context" + + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -45,7 +47,7 @@ var ( rpcsDir string rpcsCfgPath string rpcsCfg *config.CGRConfig - rpcsRPC *rpc.Client + rpcsRPC *birpc.Client rpchTest = []func(t *testing.T){ testRPCInitCfg, @@ -111,7 +113,7 @@ func testRPCStartEngine(t *testing.T) { func testRPCLoadData(t *testing.T) { var reply string attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")} - if err := rpcsRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { + if err := rpcsRPC.Call(context.Background(), utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil { t.Error(err) } time.Sleep(100 * time.Millisecond) @@ -127,7 +129,7 @@ func testRPCChargerSNoAttr(t *testing.T) { } expErr := utils.NewErrServerError(rpcclient.ErrDisconnected).Error() var rply []*engine.ChrgSProcessEventReply - if err := rpcsRPC.Call(utils.ChargerSv1ProcessEvent, cgrEv, &rply); err == nil || err.Error() != expErr { + if err := rpcsRPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, cgrEv, &rply); err == nil || err.Error() != expErr { t.Errorf("Expected error: %s,received: %v", expErr, err) } } @@ -201,7 +203,7 @@ func testRPCChargerSWithAttr(t *testing.T) { }, } var rply []*engine.ChrgSProcessEventReply - if err := rpcsRPC.Call(utils.ChargerSv1ProcessEvent, cgrEv, &rply); err != nil { + if err := rpcsRPC.Call(context.Background(), utils.ChargerSv1ProcessEvent, cgrEv, &rply); err != nil { t.Fatal(err) } sort.Slice(rply, func(i, j int) bool { diff --git a/services/analyzers.go b/services/analyzers.go index 69be102e0..3755b0568 100644 --- a/services/analyzers.go +++ b/services/analyzers.go @@ -22,19 +22,18 @@ import ( "fmt" "sync" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/analyzers" - v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewAnalyzerService returns the Analyzer Service func NewAnalyzerService(cfg *config.CGRConfig, server *cores.Server, filterSChan chan *engine.FilterS, shdChan *utils.SyncedChan, - internalAnalyzerSChan chan rpcclient.ClientConnector, + internalAnalyzerSChan chan birpc.ClientConnector, srvDep map[string]*sync.WaitGroup) *AnalyzerService { return &AnalyzerService{ connChan: internalAnalyzerSChan, @@ -56,8 +55,7 @@ type AnalyzerService struct { shdChan *utils.SyncedChan anz *analyzers.AnalyzerService - rpc *v1.AnalyzerSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector srvDep map[string]*sync.WaitGroup } @@ -79,10 +77,8 @@ func (anz *AnalyzerService) Start() (err error) { utils.Logger.Crit(fmt.Sprintf("<%s> Error: %s listening for packets", utils.AnalyzerS, err.Error())) anz.shdChan.CloseOnce() } - return }(anz.anz) anz.server.SetAnalyzer(anz.anz) - anz.rpc = v1.NewAnalyzerSv1(anz.anz) go anz.start() return } @@ -101,10 +97,18 @@ func (anz *AnalyzerService) start() { anz.filterSChan <- fS anz.anz.SetFilterS(fS) } - if !anz.cfg.DispatcherSCfg().Enabled { - anz.server.RpcRegister(anz.rpc) + srv, err := engine.NewServiceWithName(anz.anz, utils.AnalyzerS, true) + if err != nil { + utils.Logger.Err(fmt.Sprintf("<%s> failed to initialize service, error: <%s>", + utils.AnalyzerS, err.Error())) + return } - anz.connChan <- anz.rpc + if !anz.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + anz.server.RpcRegister(s) + } + } + anz.connChan <- srv } // Reload handles the change of config @@ -119,7 +123,6 @@ func (anz *AnalyzerService) Shutdown() (err error) { anz.server.SetAnalyzer(nil) anz.anz.Shutdown() anz.anz = nil - anz.rpc = nil <-anz.connChan anz.Unlock() return @@ -148,17 +151,9 @@ func (anz *AnalyzerService) GetAnalyzerS() *analyzers.AnalyzerService { } // GetInternalCodec returns the connection wrapped in analyzer connector -func (anz *AnalyzerService) GetInternalCodec(c rpcclient.ClientConnector, to string) rpcclient.ClientConnector { +func (anz *AnalyzerService) GetInternalCodec(c birpc.ClientConnector, to string) birpc.ClientConnector { if !anz.IsRunning() { return c } return anz.anz.NewAnalyzerConnector(c, utils.MetaInternal, utils.EmptyString, to) } - -// GetInternalCodec returns the connection wrapped in analyzer connector -func (anz *AnalyzerService) GetInternalBiRPCCodec(c rpcclient.BiRPCConector, to string) rpcclient.BiRPCConector { - if !anz.IsRunning() { - return c - } - return anz.anz.NewAnalyzerBiRPCConnector(c, rpcclient.BiRPCInternal, utils.EmptyString, to) -} diff --git a/services/analyzers_it_test.go b/services/analyzers_it_test.go index 3158bb268..db4a74224 100644 --- a/services/analyzers_it_test.go +++ b/services/analyzers_it_test.go @@ -28,12 +28,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestAnalyzerSReload(t *testing.T) { @@ -52,11 +53,11 @@ func TestAnalyzerSReload(t *testing.T) { srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anzRPC := make(chan rpcclient.ClientConnector, 1) + anzRPC := make(chan birpc.ClientConnector, 1) anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, anzRPC, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(anz, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -65,10 +66,11 @@ func TestAnalyzerSReload(t *testing.T) { } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "analyzers"), - Section: config.AnalyzerCfgJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "analyzers"), + Section: config.AnalyzerCfgJson, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) @@ -117,7 +119,7 @@ func TestAnalyzerSReload2(t *testing.T) { filterSChan <- nil server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anzRPC := make(chan rpcclient.ClientConnector, 1) + anzRPC := make(chan birpc.ClientConnector, 1) anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, anzRPC, srvDep) anz.stopChan = make(chan struct{}) anz.start() @@ -147,7 +149,7 @@ func TestAnalyzerSReload3(t *testing.T) { filterSChan <- nil server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anzRPC := make(chan rpcclient.ClientConnector, 1) + anzRPC := make(chan birpc.ClientConnector, 1) anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, anzRPC, srvDep) anz.stopChan = make(chan struct{}) anz.Start() diff --git a/services/analyzers_test.go b/services/analyzers_test.go index 16c79800c..73b2287b8 100644 --- a/services/analyzers_test.go +++ b/services/analyzers_test.go @@ -22,13 +22,13 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/analyzers" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestAnalyzerCoverage for cover testing @@ -39,7 +39,7 @@ func TestAnalyzerCoverage(t *testing.T) { filterSChan <- nil server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - connChan := make(chan rpcclient.ClientConnector, 1) + connChan := make(chan birpc.ClientConnector, 1) anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, connChan, srvDep) if anz == nil { t.Errorf("\nExpecting ,\n Received <%+v>", utils.ToJSON(anz)) @@ -57,7 +57,7 @@ func TestAnalyzerCoverage(t *testing.T) { if anz2.IsRunning() { t.Errorf("Expected service to be down") } - var rpcClientCnctr rpcclient.ClientConnector + var rpcClientCnctr birpc.ClientConnector getIntrnCdc := anz2.GetInternalCodec(rpcClientCnctr, utils.EmptyString) if !reflect.DeepEqual(getIntrnCdc, rpcClientCnctr) { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(rpcClientCnctr), utils.ToJSON(getIntrnCdc)) @@ -79,7 +79,7 @@ func TestAnalyzerCoverage(t *testing.T) { if !reflect.DeepEqual(anz2.anz, getAnalyzerS) { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(anz2.anz), utils.ToJSON(getAnalyzerS)) } - var rpcClientCnctr2 rpcclient.ClientConnector + var rpcClientCnctr2 birpc.ClientConnector getIntrnCdc2 := anz2.GetInternalCodec(rpcClientCnctr2, utils.EmptyString) expected2 := anz2.anz.NewAnalyzerConnector(nil, utils.MetaInternal, utils.EmptyString, utils.EmptyString) if !reflect.DeepEqual(getIntrnCdc2, expected2) { diff --git a/services/apiers_it_test.go b/services/apiers_it_test.go index ef195599b..20091e2d3 100644 --- a/services/apiers_it_test.go +++ b/services/apiers_it_test.go @@ -27,6 +27,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" @@ -34,7 +36,6 @@ import ( "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestApiersReload(t *testing.T) { @@ -60,16 +61,16 @@ func TestApiersReload(t *testing.T) { db := NewDataDBService(cfg, nil, srvDep) cfg.StorDbCfg().Type = utils.MetaInternal stordb := NewStorDBService(cfg, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) - rspd := NewResponderService(cfg, server, make(chan rpcclient.ClientConnector, 1), shdChan, anz, srvDep, filterSChan) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) + rspd := NewResponderService(cfg, server, make(chan birpc.ClientConnector, 1), shdChan, anz, srvDep, filterSChan) apiSv1 := NewAPIerSv1Service(cfg, db, stordb, filterSChan, server, schS, rspd, - make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + make(chan birpc.ClientConnector, 1), nil, anz, srvDep) - apiSv2 := NewAPIerSv2Service(apiSv1, cfg, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) + apiSv2 := NewAPIerSv2Service(apiSv1, cfg, server, make(chan birpc.ClientConnector, 1), anz, srvDep) srvMngr.AddServices(apiSv1, apiSv2, schS, tS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db, stordb) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db, stordb) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -86,10 +87,11 @@ func TestApiersReload(t *testing.T) { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.ApierS, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.ApierS, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/apiers_test.go b/services/apiers_test.go index 694712af2..829a69fba 100644 --- a/services/apiers_test.go +++ b/services/apiers_test.go @@ -22,6 +22,7 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" v2 "github.com/cgrates/cgrates/apier/v2" v1 "github.com/cgrates/cgrates/apier/v1" @@ -30,7 +31,6 @@ import ( "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestApiersCoverage for cover testing @@ -47,11 +47,11 @@ func TestApiersCoverage(t *testing.T) { db := NewDataDBService(cfg, nil, srvDep) cfg.StorDbCfg().Type = utils.MetaInternal stordb := NewStorDBService(cfg, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) apiSv1 := NewAPIerSv1Service(cfg, db, stordb, filterSChan, server, schS, new(ResponderService), - make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) - apiSv2 := NewAPIerSv2Service(apiSv1, cfg, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) + make(chan birpc.ClientConnector, 1), nil, anz, srvDep) + apiSv2 := NewAPIerSv2Service(apiSv1, cfg, server, make(chan birpc.ClientConnector, 1), anz, srvDep) if apiSv1.IsRunning() { t.Errorf("Expected service to be down") } @@ -94,14 +94,18 @@ func TestApiersCoverage(t *testing.T) { //populates apiSv1 and apiSv2 with something in order to call the close function apiSv1.stopChan = make(chan struct{}, 1) apiSv1.stopChan <- struct{}{} - apiSv1.connChan = make(chan rpcclient.ClientConnector, 1) - apiSv1.connChan <- chS + srv, err := engine.NewService(chS) + if err != nil { + t.Error(err) + } + apiSv1.connChan = make(chan birpc.ClientConnector, 1) + apiSv1.connChan <- srv shutdownApi1 := apiSv1.Shutdown() if shutdownApi1 != nil { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", nil, shutdownApi1) } - apiSv2.connChan = make(chan rpcclient.ClientConnector, 1) - apiSv2.connChan <- chS + apiSv2.connChan = make(chan birpc.ClientConnector, 1) + apiSv2.connChan <- srv shutdownApi2 := apiSv2.Shutdown() if shutdownApi2 != nil { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", nil, shutdownApi2) diff --git a/services/apierv1.go b/services/apierv1.go index 0ce3f03d5..37308f2c0 100644 --- a/services/apierv1.go +++ b/services/apierv1.go @@ -22,12 +22,12 @@ import ( "runtime" "sync" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewAPIerSv1Service returns the APIerSv1 Service @@ -36,7 +36,7 @@ func NewAPIerSv1Service(cfg *config.CGRConfig, dm *DataDBService, server *cores.Server, schedService *SchedulerService, responderService *ResponderService, - internalAPIerSv1Chan chan rpcclient.ClientConnector, + internalAPIerSv1Chan chan birpc.ClientConnector, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) *APIerSv1Service { return &APIerSv1Service{ @@ -68,7 +68,7 @@ type APIerSv1Service struct { connMgr *engine.ConnManager api *v1.APIerSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector stopChan chan struct{} @@ -79,7 +79,7 @@ type APIerSv1Service struct { // Start should handle the sercive start // For this service the start should be called from RAL Service -func (apiService *APIerSv1Service) Start() (err error) { +func (apiService *APIerSv1Service) Start() error { if apiService.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -117,17 +117,37 @@ func (apiService *APIerSv1Service) Start() (err error) { go apiService.api.ListenAndServe(apiService.stopChan) runtime.Gosched() + srv, err := engine.NewService(apiService.api) + if err != nil { + return err + } if !apiService.cfg.DispatcherSCfg().Enabled { - apiService.server.RpcRegister(apiService.api) - apiService.server.RpcRegisterName(utils.ApierV1, apiService.api) - apiService.server.RpcRegister(v1.NewReplicatorSv1(datadb, apiService.api)) + for _, s := range srv { + apiService.server.RpcRegister(s) + } + var legacySrv engine.IntService + legacySrv, err = engine.NewServiceWithName(apiService.api, utils.ApierV1, true) + if err != nil { + return err + } + //backwards compatible + for _, s := range legacySrv { + apiService.server.RpcRegister(s) + } + var rplSrv engine.IntService + rplSrv, err = engine.NewService(v1.NewReplicatorSv1(datadb, apiService.api)) + if err != nil { + return err + } + for _, s := range rplSrv { + apiService.server.RpcRegister(s) + } } - //backwards compatible - apiService.connChan <- apiService.anz.GetInternalCodec(apiService.api, utils.APIerSv1) + apiService.connChan <- apiService.anz.GetInternalCodec(srv, utils.APIerSv1) apiService.APIerSv1Chan <- apiService.api - return + return nil } // Reload handles the change of config diff --git a/services/apierv2.go b/services/apierv2.go index da2921ff9..6272490db 100644 --- a/services/apierv2.go +++ b/services/apierv2.go @@ -21,16 +21,17 @@ package services import ( "sync" + "github.com/cgrates/birpc" v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewAPIerSv2Service returns the APIerSv2 Service func NewAPIerSv2Service(apiv1 *APIerSv1Service, cfg *config.CGRConfig, - server *cores.Server, internalAPIerSv2Chan chan rpcclient.ClientConnector, + server *cores.Server, internalAPIerSv2Chan chan birpc.ClientConnector, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) *APIerSv2Service { return &APIerSv2Service{ apiv1: apiv1, @@ -50,14 +51,14 @@ type APIerSv2Service struct { apiv1 *APIerSv1Service api *v2.APIerSv2 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the sercive start // For this service the start should be called from RAL Service -func (api *APIerSv2Service) Start() (err error) { +func (api *APIerSv2Service) Start() error { if api.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -72,14 +73,34 @@ func (api *APIerSv2Service) Start() (err error) { api.api = &v2.APIerSv2{ APIerSv1: *apiV1, } - + srv, err := engine.NewService(api.api) + if err != nil { + return err + } + var apierV1Srv *birpc.Service + apierV1Srv, err = birpc.NewService(apiV1, "", false) + if err != nil { + return err + } + engine.RegisterPingMethod(apierV1Srv.Methods) + srv[utils.APIerSv1] = apierV1Srv if !api.cfg.DispatcherSCfg().Enabled { - api.server.RpcRegister(api.api) - api.server.RpcRegisterName(utils.ApierV2, api.api) + for _, s := range srv { + api.server.RpcRegister(s) + } + var legacySrv engine.IntService + legacySrv, err = engine.NewServiceWithName(api.api, utils.ApierV2, true) + if err != nil { + return err + } + //backwards compatible + for _, s := range legacySrv { + api.server.RpcRegister(s) + } } - api.connChan <- api.anz.GetInternalCodec(api.api, utils.APIerSv2) - return + api.connChan <- api.anz.GetInternalCodec(srv, utils.APIerSv2) + return nil } // Reload handles the change of config diff --git a/services/asteriskagent.go b/services/asteriskagent.go index 7ae03feca..9fd95b600 100644 --- a/services/asteriskagent.go +++ b/services/asteriskagent.go @@ -64,18 +64,22 @@ func (ast *AsteriskAgent) Start() (err error) { defer ast.Unlock() listenAndServe := func(sma *agents.AsteriskAgent, stopChan chan struct{}, shdChan *utils.SyncedChan) { - if err := sma.ListenAndServe(stopChan); err != nil { - utils.Logger.Err(fmt.Sprintf("<%s> runtime error: %s!", utils.AsteriskAgent, err)) + if lnsErr := sma.ListenAndServe(stopChan); lnsErr != nil { + utils.Logger.Err(fmt.Sprintf("<%s> runtime error: %s!", utils.AsteriskAgent, lnsErr)) shdChan.CloseOnce() } } ast.stopChan = make(chan struct{}) ast.smas = make([]*agents.AsteriskAgent, len(ast.cfg.AsteriskAgentCfg().AsteriskConns)) for connIdx := range ast.cfg.AsteriskAgentCfg().AsteriskConns { // Instantiate connections towards asterisk servers - ast.smas[connIdx] = agents.NewAsteriskAgent(ast.cfg, connIdx, ast.connMgr) + ast.smas[connIdx], err = agents.NewAsteriskAgent(ast.cfg, connIdx, ast.connMgr) + if err != nil { + utils.Logger.Err(fmt.Sprintf("<%s> failed to initialize agent for connection %d, error: %s!", utils.AsteriskAgent, connIdx, err)) + return err + } go listenAndServe(ast.smas[connIdx], ast.stopChan, ast.shdChan) } - return + return nil } // Reload handles the change of config diff --git a/services/asteriskagent_it_test.go b/services/asteriskagent_it_test.go index 6d6b6e50e..50d6724e0 100644 --- a/services/asteriskagent_it_test.go +++ b/services/asteriskagent_it_test.go @@ -26,12 +26,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestAsteriskAgentReload(t *testing.T) { @@ -49,52 +50,57 @@ func TestAsteriskAgentReload(t *testing.T) { }() shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Error(err) + } - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) - srv := NewAsteriskAgent(cfg, shdChan, nil, srvDep) + astService := NewAsteriskAgent(cfg, shdChan, nil, srvDep) engine.NewConnManager(cfg, nil) - srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + srvMngr.AddServices(astService, sS, + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } - if srv.IsRunning() { + if astService.IsRunning() { t.Fatalf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "asterisk_ari", "cgrates", "etc", "cgrates"), - Section: config.AsteriskAgentJSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "asterisk_ari", "cgrates", "etc", "cgrates"), + Section: config.AsteriskAgentJSN, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) } time.Sleep(10 * time.Millisecond) //need to switch to gorutine - if !srv.IsRunning() { + if !astService.IsRunning() { t.Fatalf("Expected service to be running") } - srvReload := srv.Reload() + srvReload := astService.Reload() if srvReload != nil { t.Fatalf("\nExpecting ,\n Received <%+v>", srvReload) } - err := srv.Start() + err = astService.Start() if err != utils.ErrServiceAlreadyRunning { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err) } cfg.AsteriskAgentCfg().Enabled = false cfg.GetReloadChan(config.AsteriskAgentJSN) <- struct{}{} time.Sleep(10 * time.Millisecond) - if srv.IsRunning() { + if astService.IsRunning() { t.Fatalf("Expected service to be down") } @@ -115,45 +121,49 @@ func TestAsteriskAgentReload2(t *testing.T) { }() shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) - - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Error(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) - srv := NewAsteriskAgent(cfg, shdChan, nil, srvDep) + astSrv := NewAsteriskAgent(cfg, shdChan, nil, srvDep) engine.NewConnManager(cfg, nil) - srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + srvMngr.AddServices(astSrv, sS, + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } - if srv.IsRunning() { + if astSrv.IsRunning() { t.Fatalf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "asterisk_ari", "cgrates", "etc", "cgrates"), - Section: config.AsteriskAgentJSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "asterisk_ari", "cgrates", "etc", "cgrates"), + Section: config.AsteriskAgentJSN, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) } time.Sleep(10 * time.Millisecond) //need to switch to gorutine - if !srv.IsRunning() { + if !astSrv.IsRunning() { t.Fatalf("Expected service to be running") } - srvReload := srv.Reload() + srvReload := astSrv.Reload() if srvReload != nil { t.Fatalf("\nExpecting ,\n Received <%+v>", srvReload) } - err := srv.Start() + err = astSrv.Start() if err != utils.ErrServiceAlreadyRunning { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err) } @@ -166,14 +176,14 @@ func TestAsteriskAgentReload2(t *testing.T) { ConnectAttempts: 0, Reconnects: 0, }} - srvReload = srv.Reload() + srvReload = astSrv.Reload() if srvReload != nil { t.Fatalf("\nExpecting ,\n Received <%+v>", srvReload) } cfg.AsteriskAgentCfg().Enabled = false cfg.GetReloadChan(config.AsteriskAgentJSN) <- struct{}{} time.Sleep(10 * time.Millisecond) - if srv.IsRunning() { + if astSrv.IsRunning() { t.Fatalf("Expected service to be down") } } diff --git a/services/asteriskagent_test.go b/services/asteriskagent_test.go index 5c47bce80..65d7f8904 100644 --- a/services/asteriskagent_test.go +++ b/services/asteriskagent_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/agents" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestAsteriskAgentCoverage for cover testing @@ -38,12 +38,16 @@ func TestAsteriskAgentCoverage(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Error(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - srv := NewAsteriskAgent(cfg, shdChan, nil, srvDep) - if srv == nil { - t.Errorf("\nExpecting ,\n Received <%+v>", utils.ToJSON(srv)) + astSrv := NewAsteriskAgent(cfg, shdChan, nil, srvDep) + if astSrv == nil { + t.Errorf("\nExpecting ,\n Received <%+v>", utils.ToJSON(astSrv)) } srv2 := &AsteriskAgent{ RWMutex: sync.RWMutex{}, diff --git a/services/attributes.go b/services/attributes.go index d88294f29..d3384b828 100644 --- a/services/attributes.go +++ b/services/attributes.go @@ -22,19 +22,19 @@ import ( "fmt" "sync" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewAttributeService returns the Attribute Service func NewAttributeService(cfg *config.CGRConfig, dm *DataDBService, cacheS *engine.CacheS, filterSChan chan *engine.FilterS, - server *cores.Server, internalChan chan rpcclient.ClientConnector, + server *cores.Server, internalChan chan birpc.ClientConnector, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { return &AttributeService{ @@ -59,14 +59,14 @@ type AttributeService struct { server *cores.Server attrS *engine.AttributeService - rpc *v1.AttributeSv1 // useful on restart - connChan chan rpcclient.ClientConnector // publish the internal Subsystem when available + rpc *v1.AttributeSv1 // useful on restart + connChan chan birpc.ClientConnector // publish the internal Subsystem when available anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the service start -func (attrS *AttributeService) Start() (err error) { +func (attrS *AttributeService) Start() error { if attrS.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -85,11 +85,17 @@ func (attrS *AttributeService) Start() (err error) { attrS.attrS = engine.NewAttributeService(datadb, filterS, attrS.cfg) utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.AttributeS)) attrS.rpc = v1.NewAttributeSv1(attrS.attrS) - if !attrS.cfg.DispatcherSCfg().Enabled { - attrS.server.RpcRegister(attrS.rpc) + srv, err := engine.NewService(attrS.rpc) + if err != nil { + return err } - attrS.connChan <- attrS.anz.GetInternalCodec(attrS.rpc, utils.AttributeS) - return + if !attrS.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + attrS.server.RpcRegister(s) + } + } + attrS.connChan <- attrS.anz.GetInternalCodec(srv, utils.AttributeS) + return nil } // Reload handles the change of config diff --git a/services/attributes_it_test.go b/services/attributes_it_test.go index 11ed0c165..d1e9bdfe2 100644 --- a/services/attributes_it_test.go +++ b/services/attributes_it_test.go @@ -26,8 +26,8 @@ import ( "testing" "time" - "github.com/cgrates/rpcclient" - + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -52,14 +52,14 @@ func TestAttributeSReload(t *testing.T) { srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - attrRPC := make(chan rpcclient.ClientConnector, 1) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + attrRPC := make(chan birpc.ClientConnector, 1) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) attrS := NewAttributeService(cfg, db, chS, filterSChan, server, attrRPC, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(attrS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -71,10 +71,11 @@ func TestAttributeSReload(t *testing.T) { } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.ATTRIBUTE_JSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.ATTRIBUTE_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/attributes_test.go b/services/attributes_test.go index 1b8536341..14576d773 100644 --- a/services/attributes_test.go +++ b/services/attributes_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestAttributeSCoverage for cover testing @@ -38,15 +38,15 @@ func TestAttributeSCoverage(t *testing.T) { chS := engine.NewCacheS(cfg, nil, nil) server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - attrRPC := make(chan rpcclient.ClientConnector, 1) + attrRPC := make(chan birpc.ClientConnector, 1) db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) attrS := NewAttributeService(cfg, db, chS, filterSChan, server, attrRPC, anz, srvDep) if attrS == nil { t.Errorf("\nExpecting ,\n Received <%+v>", utils.ToJSON(attrS)) } attrS2 := &AttributeService{ - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), cfg: cfg, dm: db, cacheS: chS, @@ -72,7 +72,11 @@ func TestAttributeSCoverage(t *testing.T) { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.AttributeS, serviceName) } chS = engine.NewCacheS(cfg, nil, nil) - attrS2.connChan <- chS + srv, err := engine.NewService(chS) + if err != nil { + t.Error(err) + } + attrS2.connChan <- srv shutdownErr := attrS2.Shutdown() if shutdownErr != nil { t.Errorf("\nExpecting ,\n Received <%+v>", shutdownErr) diff --git a/services/cdrs.go b/services/cdrs.go index 0931ef566..6720f9946 100644 --- a/services/cdrs.go +++ b/services/cdrs.go @@ -23,6 +23,7 @@ import ( "runtime" "sync" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" @@ -30,13 +31,12 @@ import ( "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewCDRServer returns the CDR Server func NewCDRServer(cfg *config.CGRConfig, dm *DataDBService, storDB *StorDBService, filterSChan chan *engine.FilterS, - server *cores.Server, internalCDRServerChan chan rpcclient.ClientConnector, + server *cores.Server, internalCDRServerChan chan birpc.ClientConnector, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { return &CDRServer{ @@ -62,9 +62,7 @@ type CDRServer struct { server *cores.Server cdrS *engine.CDRServer - rpcv1 *v1.CDRsV1 - rpcv2 *v2.CDRsV2 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector connMgr *engine.ConnManager stopChan chan struct{} @@ -73,7 +71,7 @@ type CDRServer struct { } // Start should handle the sercive start -func (cdrService *CDRServer) Start() (err error) { +func (cdrService *CDRServer) Start() error { if cdrService.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -99,16 +97,26 @@ func (cdrService *CDRServer) Start() (err error) { utils.Logger.Info("Registering CDRS HTTP Handlers.") cdrService.cdrS.RegisterHandlersToServer(cdrService.server) utils.Logger.Info("Registering CDRS RPC service.") - cdrService.rpcv1 = v1.NewCDRsV1(cdrService.cdrS) - cdrService.rpcv2 = &v2.CDRsV2{CDRsV1: *cdrService.rpcv1} - if !cdrService.cfg.DispatcherSCfg().Enabled { - cdrService.server.RpcRegister(cdrService.rpcv1) - cdrService.server.RpcRegister(cdrService.rpcv2) - // Make the cdr server available for internal communication - cdrService.server.RpcRegister(cdrService.cdrS) // register CdrServer for internal usage (TODO: refactor this) + + cdrsV1 := v1.NewCDRsV1(cdrService.cdrS) + cdrsV2 := &v2.CDRsV2{CDRsV1: *cdrsV1} + srv, err := engine.NewService(cdrsV1) + if err != nil { + return err } - cdrService.connChan <- cdrService.anz.GetInternalCodec(cdrService.cdrS, utils.CDRServer) // Signal that cdrS is operational - return + cdrsV2Srv, err := birpc.NewService(cdrsV2, "", false) + if err != nil { + return err + } + engine.RegisterPingMethod(cdrsV2Srv.Methods) + srv[utils.CDRsV2] = cdrsV2Srv + if !cdrService.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + cdrService.server.RpcRegister(s) + } + } + cdrService.connChan <- cdrService.anz.GetInternalCodec(srv, utils.CDRServer) // Signal that cdrS is operational + return nil } // Reload handles the change of config @@ -121,8 +129,6 @@ func (cdrService *CDRServer) Shutdown() (err error) { cdrService.Lock() close(cdrService.stopChan) cdrService.cdrS = nil - cdrService.rpcv1 = nil - cdrService.rpcv2 = nil <-cdrService.connChan cdrService.Unlock() return diff --git a/services/cdrs_it_test.go b/services/cdrs_it_test.go index d806ccc44..637d7a096 100644 --- a/services/cdrs_it_test.go +++ b/services/cdrs_it_test.go @@ -26,12 +26,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestCdrsReload(t *testing.T) { @@ -66,19 +67,19 @@ func TestCdrsReload(t *testing.T) { db := NewDataDBService(cfg, nil, srvDep) cfg.StorDbCfg().Type = utils.MetaInternal stordb := NewStorDBService(cfg, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - chrS := NewChargerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) - schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + chrS := NewChargerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) + schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) ralS := NewRalService(cfg, chS, server, - make(chan rpcclient.ClientConnector, 1), - make(chan rpcclient.ClientConnector, 1), + make(chan birpc.ClientConnector, 1), + make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep, filterSChan) - cdrsRPC := make(chan rpcclient.ClientConnector, 1) + cdrsRPC := make(chan birpc.ClientConnector, 1) cdrS := NewCDRServer(cfg, db, stordb, filterSChan, server, cdrsRPC, nil, anz, srvDep) srvMngr.AddServices(cdrS, ralS, schS, chrS, NewLoaderService(cfg, db, filterSChan, server, - make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db, stordb) + make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db, stordb) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -94,10 +95,11 @@ func TestCdrsReload(t *testing.T) { cfg.RalsCfg().Enabled = true var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.CDRS_JSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.CDRS_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/cdrs_test.go b/services/cdrs_test.go index b85314fc9..df709e1a4 100644 --- a/services/cdrs_test.go +++ b/services/cdrs_test.go @@ -21,11 +21,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestCdrsCoverage for cover testing @@ -43,8 +43,8 @@ func TestCdrsCoverage(t *testing.T) { db := NewDataDBService(cfg, nil, srvDep) cfg.StorDbCfg().Type = utils.MetaInternal stordb := NewStorDBService(cfg, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - cdrsRPC := make(chan rpcclient.ClientConnector, 1) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + cdrsRPC := make(chan birpc.ClientConnector, 1) cdrS := NewCDRServer(cfg, db, stordb, filterSChan, server, cdrsRPC, nil, anz, srvDep) if cdrS.IsRunning() { @@ -58,14 +58,18 @@ func TestCdrsCoverage(t *testing.T) { storDB: stordb, filterSChan: filterSChan, server: server, - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), connMgr: nil, stopChan: make(chan struct{}, 1), anz: anz, srvDep: srvDep, cdrS: &engine.CDRServer{}, } - cdrS2.connChan <- chS + srv, err := engine.NewService(chS) + if err != nil { + t.Error(err) + } + cdrS2.connChan <- srv cdrS2.stopChan <- struct{}{} if !cdrS2.IsRunning() { t.Errorf("Expected service to be running") diff --git a/services/chargers.go b/services/chargers.go index 631f5b1ed..385587eae 100644 --- a/services/chargers.go +++ b/services/chargers.go @@ -22,19 +22,19 @@ import ( "fmt" "sync" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewChargerService returns the Charger Service func NewChargerService(cfg *config.CGRConfig, dm *DataDBService, cacheS *engine.CacheS, filterSChan chan *engine.FilterS, server *cores.Server, - internalChargerSChan chan rpcclient.ClientConnector, connMgr *engine.ConnManager, + internalChargerSChan chan birpc.ClientConnector, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { return &ChargerService{ connChan: internalChargerSChan, @@ -61,13 +61,13 @@ type ChargerService struct { chrS *engine.ChargerService rpc *v1.ChargerSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the sercive start -func (chrS *ChargerService) Start() (err error) { +func (chrS *ChargerService) Start() error { if chrS.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -85,12 +85,17 @@ func (chrS *ChargerService) Start() (err error) { defer chrS.Unlock() chrS.chrS = engine.NewChargerService(datadb, filterS, chrS.cfg, chrS.connMgr) utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.ChargerS)) - cSv1 := v1.NewChargerSv1(chrS.chrS) - if !chrS.cfg.DispatcherSCfg().Enabled { - chrS.server.RpcRegister(cSv1) + srv, err := engine.NewServiceWithName(chrS.chrS, utils.ChargerS, true) + if err != nil { + return err } - chrS.connChan <- chrS.anz.GetInternalCodec(cSv1, utils.ChargerS) - return + if !chrS.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + chrS.server.RpcRegister(s) + } + } + chrS.connChan <- chrS.anz.GetInternalCodec(srv, utils.ChargerS) + return nil } // Reload handles the change of config diff --git a/services/chargers_it_test.go b/services/chargers_it_test.go index c1979af40..29f8caaca 100644 --- a/services/chargers_it_test.go +++ b/services/chargers_it_test.go @@ -26,8 +26,8 @@ import ( "testing" "time" - "github.com/cgrates/rpcclient" - + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -54,13 +54,13 @@ func TestChargerSReload(t *testing.T) { server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - attrS := NewAttributeService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) - chrS := NewChargerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + attrS := NewAttributeService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) + chrS := NewChargerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(attrS, chrS, NewLoaderService(cfg, db, filterSChan, server, - make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -71,10 +71,11 @@ func TestChargerSReload(t *testing.T) { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.ChargerSCfgJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.ChargerSCfgJson, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/chargers_test.go b/services/chargers_test.go index 547fd2647..46874ef6b 100644 --- a/services/chargers_test.go +++ b/services/chargers_test.go @@ -22,8 +22,7 @@ import ( "sync" "testing" - "github.com/cgrates/rpcclient" - + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -41,15 +40,15 @@ func TestChargerSCoverage(t *testing.T) { srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} server := cores.NewServer(nil) db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) chrS1 := NewChargerService(cfg, db, chS, - filterSChan, server, make(chan rpcclient.ClientConnector, 1), + filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) if chrS1.IsRunning() { t.Errorf("Expected service to be down") } chrS := &ChargerService{ - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), cfg: cfg, dm: db, cacheS: chS, @@ -75,8 +74,12 @@ func TestChargerSCoverage(t *testing.T) { if !reflect.DeepEqual(shouldRun, false) { t.Errorf("\nExpecting ,\n Received <%+v>", shouldRun) } - chrS.connChan = make(chan rpcclient.ClientConnector, 1) - chrS.connChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Error(err) + } + chrS.connChan = make(chan birpc.ClientConnector, 1) + chrS.connChan <- cacheSrv shutErr := chrS.Shutdown() if shutErr != nil { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", nil, shutErr) diff --git a/services/cores.go b/services/cores.go index 7c27079b2..42d285d40 100644 --- a/services/cores.go +++ b/services/cores.go @@ -23,17 +23,16 @@ import ( "io" "sync" - v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewCoreService returns the Core Service func NewCoreService(cfg *config.CGRConfig, caps *engine.Caps, server *cores.Server, - internalCoreSChan chan rpcclient.ClientConnector, anz *AnalyzerService, + internalCoreSChan chan birpc.ClientConnector, anz *AnalyzerService, fileCpu io.Closer, fileMEM string, shdWg *sync.WaitGroup, stopMemPrf chan struct{}, shdChan *utils.SyncedChan, srvDep map[string]*sync.WaitGroup) *CoreService { return &CoreService{ @@ -64,14 +63,13 @@ type CoreService struct { fileCpu io.Closer fileMem string cS *cores.CoreService - rpc *v1.CoreSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the service start -func (cS *CoreService) Start() (err error) { +func (cS *CoreService) Start() error { if cS.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -81,12 +79,17 @@ func (cS *CoreService) Start() (err error) { utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.CoreS)) cS.stopChan = make(chan struct{}) cS.cS = cores.NewCoreService(cS.cfg, cS.caps, cS.fileCpu, cS.fileMem, cS.stopChan, cS.shdWg, cS.stopMemPrf, cS.shdChan) - cS.rpc = v1.NewCoreSv1(cS.cS) - if !cS.cfg.DispatcherSCfg().Enabled { - cS.server.RpcRegister(cS.rpc) + srv, err := engine.NewServiceWithName(cS.cS, utils.CoreS, true) + if err != nil { + return err } - cS.connChan <- cS.anz.GetInternalCodec(cS.rpc, utils.CoreS) - return + if !cS.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + cS.server.RpcRegister(s) + } + } + cS.connChan <- cS.anz.GetInternalCodec(srv, utils.CoreS) + return nil } // Reload handles the change of config @@ -101,7 +104,6 @@ func (cS *CoreService) Shutdown() (err error) { cS.cS.Shutdown() close(cS.stopChan) cS.cS = nil - cS.rpc = nil <-cS.connChan return } diff --git a/services/cores_it_test.go b/services/cores_it_test.go index 272783678..ffba0c198 100644 --- a/services/cores_it_test.go +++ b/services/cores_it_test.go @@ -26,8 +26,8 @@ import ( "testing" "time" - "github.com/cgrates/rpcclient" - + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -49,13 +49,13 @@ func TestCoreSReload(t *testing.T) { srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - coreRPC := make(chan rpcclient.ClientConnector, 1) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + coreRPC := make(chan birpc.ClientConnector, 1) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) caps := engine.NewCaps(1, "test_caps") coreS := NewCoreService(cfg, caps, server, coreRPC, anz, nil, "", nil, nil, nil, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(coreS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -64,10 +64,11 @@ func TestCoreSReload(t *testing.T) { } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "caps_queue"), - Section: config.CoreSCfgJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "caps_queue"), + Section: config.CoreSCfgJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) diff --git a/services/cores_test.go b/services/cores_test.go index f64ab207b..b31cb442a 100644 --- a/services/cores_test.go +++ b/services/cores_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestCoreSCoverage for cover testing @@ -34,12 +34,12 @@ func TestCoreSCoverage(t *testing.T) { cfg := config.NewDefaultCGRConfig() caps := engine.NewCaps(1, "test_caps") server := cores.NewServer(nil) - internalCoreSChan := make(chan rpcclient.ClientConnector, 1) + internalCoreSChan := make(chan birpc.ClientConnector, 1) filterSChan := make(chan *engine.FilterS, 1) filterSChan <- nil shdChan := utils.NewSyncedChan() srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) srv := NewCoreService(cfg, caps, server, internalCoreSChan, anz, nil, "/tmp", nil, nil, nil, srvDep) if srv == nil { @@ -66,7 +66,11 @@ func TestCoreSCoverage(t *testing.T) { } //populates connChan with something in order to call the shutdown function chS := engine.NewCacheS(cfg, nil, nil) - srv.connChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Error(err) + } + srv.connChan <- cacheSrv srv.stopChan = make(chan struct{}) getShut := srv.Shutdown() if getShut != nil { diff --git a/services/datadb_it_test.go b/services/datadb_it_test.go index 8b6d73f7e..7b1f06ceb 100644 --- a/services/datadb_it_test.go +++ b/services/datadb_it_test.go @@ -27,8 +27,8 @@ import ( "testing" "time" - "github.com/cgrates/rpcclient" - + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -54,10 +54,10 @@ func TestDataDBReload(t *testing.T) { srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) cM := engine.NewConnManager(cfg, nil) db := NewDataDBService(cfg, cM, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) srvMngr.AddServices(NewAttributeService(cfg, db, - chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep), - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep), + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -66,10 +66,11 @@ func TestDataDBReload(t *testing.T) { } var reply string cfg.AttributeSCfg().Enabled = true - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.DATADB_JSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.DATADB_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/diameteragent.go b/services/diameteragent.go index 689bcaded..145e1ff44 100644 --- a/services/diameteragent.go +++ b/services/diameteragent.go @@ -73,24 +73,26 @@ func (da *DiameterAgent) Start() (err error) { return da.start(filterS) } -func (da *DiameterAgent) start(filterS *engine.FilterS) (err error) { +func (da *DiameterAgent) start(filterS *engine.FilterS) error { + var err error da.da, err = agents.NewDiameterAgent(da.cfg, filterS, da.connMgr) if err != nil { - utils.Logger.Err(fmt.Sprintf("<%s> error: %s!", + utils.Logger.Err(fmt.Sprintf("<%s> failed to initialize agent, error: %s", utils.DiameterAgent, err)) - return + return err } da.lnet = da.cfg.DiameterAgentCfg().ListenNet da.laddr = da.cfg.DiameterAgentCfg().Listen da.stopChan = make(chan struct{}) go func(d *agents.DiameterAgent) { - if err = d.ListenAndServe(da.stopChan); err != nil { - utils.Logger.Err(fmt.Sprintf("<%s> error: %s!", - utils.DiameterAgent, err)) + lnsErr := d.ListenAndServe(da.stopChan) + if lnsErr != nil { + utils.Logger.Err(fmt.Sprintf("<%s> error: %s", + utils.DiameterAgent, lnsErr)) da.shdChan.CloseOnce() } }(da.da) - return + return nil } // Reload handles the change of config diff --git a/services/diameteragent_it_test.go b/services/diameteragent_it_test.go index f4a2c9693..83a4d6bd6 100644 --- a/services/diameteragent_it_test.go +++ b/services/diameteragent_it_test.go @@ -26,12 +26,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestDiameterAgentReload1(t *testing.T) { @@ -45,56 +46,61 @@ func TestDiameterAgentReload1(t *testing.T) { shdChan := utils.NewSyncedChan() shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) - srv := NewDiameterAgent(cfg, filterSChan, shdChan, nil, srvDep) + diamSrv := NewDiameterAgent(cfg, filterSChan, shdChan, nil, srvDep) engine.NewConnManager(cfg, nil) - srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + srvMngr.AddServices(diamSrv, sS, + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } - if srv.IsRunning() { + if diamSrv.IsRunning() { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "diamagent_mysql"), - Section: config.DA_JSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "diamagent_mysql"), + Section: config.DA_JSN, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) } time.Sleep(10 * time.Millisecond) //need to switch to gorutine - if !srv.IsRunning() { + if !diamSrv.IsRunning() { t.Errorf("Expected service to be running") } - err := srv.Start() + err = diamSrv.Start() if err == nil || err != utils.ErrServiceAlreadyRunning { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err) } - err = srv.Reload() + err = diamSrv.Reload() if err != nil { t.Errorf("\nExpecting ,\n Received <%+v>", err) } cfg.DiameterAgentCfg().Enabled = false cfg.GetReloadChan(config.DA_JSN) <- struct{}{} - srv.(*DiameterAgent).lnet = "bad_lnet_test" - err2 := srv.Reload() + diamSrv.(*DiameterAgent).lnet = "bad_lnet_test" + err2 := diamSrv.Reload() if err != nil { t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err2) } time.Sleep(10 * time.Millisecond) - if srv.IsRunning() { + if diamSrv.IsRunning() { t.Errorf("Expected service to be down") } shdChan.CloseOnce() @@ -111,8 +117,12 @@ func TestDiameterAgentReload2(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewDiameterAgent(cfg, filterSChan, shdChan, nil, srvDep) if srv.IsRunning() { @@ -136,15 +146,19 @@ func TestDiameterAgentReload3(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewDiameterAgent(cfg, filterSChan, shdChan, nil, srvDep) cfg.DiameterAgentCfg().ListenNet = "bad" cfg.DiameterAgentCfg().DictionariesPath = "" - err := srv.(*DiameterAgent).start(nil) + err = srv.(*DiameterAgent).start(nil) if err != nil { t.Fatal(err) } diff --git a/services/dispatchers.go b/services/dispatchers.go index 4eb2e1ba7..f5eb6e953 100644 --- a/services/dispatchers.go +++ b/services/dispatchers.go @@ -21,6 +21,7 @@ package services import ( "sync" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" v2 "github.com/cgrates/cgrates/apier/v2" "github.com/cgrates/cgrates/config" @@ -29,13 +30,12 @@ import ( "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewDispatcherService returns the Dispatcher Service func NewDispatcherService(cfg *config.CGRConfig, dm *DataDBService, cacheS *engine.CacheS, filterSChan chan *engine.FilterS, - server *cores.Server, internalChan chan rpcclient.ClientConnector, + server *cores.Server, internalChan chan birpc.ClientConnector, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { return &DispatcherService{ @@ -63,13 +63,13 @@ type DispatcherService struct { dspS *dispatchers.DispatcherService rpc *v1.DispatcherSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the sercive start -func (dspS *DispatcherService) Start() (err error) { +func (dspS *DispatcherService) Start() error { if dspS.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -88,69 +88,18 @@ func (dspS *DispatcherService) Start() (err error) { dspS.dspS = dispatchers.NewDispatcherService(datadb, dspS.cfg, fltrS, dspS.connMgr) - // for the moment we dispable Apier through dispatcher - // until we figured out a better sollution in case of gob server - // dspS.server.SetDispatched() + dspS.server.RpcUnregisterName(utils.AttributeSv1) - dspS.server.RpcRegister(v1.NewDispatcherSv1(dspS.dspS)) + srv, err := newDispatcherServiceMap(dspS.dspS) + if err != nil { + return err + } + for _, s := range srv { + dspS.server.RpcRegister(s) + } + dspS.connChan <- dspS.anz.GetInternalCodec(srv, utils.DispatcherS) - dspS.server.RpcRegisterName(utils.ThresholdSv1, - v1.NewDispatcherThresholdSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.StatSv1, - v1.NewDispatcherStatSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.ResourceSv1, - v1.NewDispatcherResourceSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.RouteSv1, - v1.NewDispatcherRouteSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.AttributeSv1, - v1.NewDispatcherAttributeSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.SessionSv1, - v1.NewDispatcherSessionSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.ChargerSv1, - v1.NewDispatcherChargerSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.CoreSv1, - v1.NewDispatcherCoreSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.EeSv1, - v1.NewDispatcherEeSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.Responder, - v1.NewDispatcherResponder(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.CacheSv1, - v1.NewDispatcherCacheSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.GuardianSv1, - v1.NewDispatcherGuardianSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.SchedulerSv1, - v1.NewDispatcherSchedulerSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.CDRsV1, - v1.NewDispatcherSCDRsV1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.ConfigSv1, - v1.NewDispatcherConfigSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.RALsV1, - v1.NewDispatcherRALsV1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.ReplicatorSv1, - v1.NewDispatcherReplicatorSv1(dspS.dspS)) - - dspS.server.RpcRegisterName(utils.CDRsV2, - v2.NewDispatcherSCDRsV2(dspS.dspS)) - - dspS.connChan <- dspS.anz.GetInternalCodec(dspS.dspS, utils.DispatcherS) - - return + return nil } // Reload handles the change of config @@ -185,3 +134,142 @@ func (dspS *DispatcherService) ServiceName() string { func (dspS *DispatcherService) ShouldRun() bool { return dspS.cfg.DispatcherSCfg().Enabled } + +func newDispatcherServiceMap(val *dispatchers.DispatcherService) (engine.IntService, error) { + srvMap := make(engine.IntService) + + srv, err := birpc.NewService(v1.NewDispatcherAttributeSv1(val), + utils.AttributeSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherCacheSv1(val), + utils.CacheSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherSCDRsV1(val), + utils.CDRsV1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v2.NewDispatcherSCDRsV2(val), + utils.CDRsV2, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherChargerSv1(val), + utils.ChargerSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherConfigSv1(val), + utils.ConfigSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherCoreSv1(val), + utils.CoreSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherSv1(val), + utils.DispatcherSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherEeSv1(val), + utils.EeSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherGuardianSv1(val), + utils.GuardianSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherRALsV1(val), + utils.RALsV1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherReplicatorSv1(val), + utils.ReplicatorSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherResourceSv1(val), + utils.ResourceSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherThresholdSv1(val), + utils.ThresholdSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherResponder(val), + utils.Responder, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherRouteSv1(val), + utils.RouteSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherSchedulerSv1(val), + utils.SchedulerSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherSessionSv1(val), + utils.SessionSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + srv, err = birpc.NewService(v1.NewDispatcherStatSv1(val), + utils.StatSv1, true) + if err != nil { + return nil, err + } + srvMap[srv.Name] = srv + + return srvMap, nil +} diff --git a/services/dispatchers_it_test.go b/services/dispatchers_it_test.go index 77a8b025a..0f4a117f6 100644 --- a/services/dispatchers_it_test.go +++ b/services/dispatchers_it_test.go @@ -26,8 +26,8 @@ import ( "testing" "time" - "github.com/cgrates/rpcclient" - + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -55,14 +55,14 @@ func TestDispatcherSReload(t *testing.T) { srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - attrS := NewAttributeService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + attrS := NewAttributeService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) srv := NewDispatcherService(cfg, db, chS, filterSChan, server, - make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + make(chan birpc.ClientConnector, 1), nil, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(attrS, srv, NewLoaderService(cfg, db, filterSChan, server, - make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -73,11 +73,12 @@ func TestDispatcherSReload(t *testing.T) { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dispatchers", "dispatchers_mysql"), + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dispatchers", "dispatchers_mysql"), - Section: config.DispatcherSJson, - }, &reply); err != nil { + Section: config.DispatcherSJson, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/dispatchers_test.go b/services/dispatchers_test.go index 53f0a557b..101934c01 100644 --- a/services/dispatchers_test.go +++ b/services/dispatchers_test.go @@ -21,13 +21,13 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/dispatchers" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestDispatcherSCoverage for cover testing @@ -41,9 +41,9 @@ func TestDispatcherSCoverage(t *testing.T) { server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) srv := NewDispatcherService(cfg, db, chS, filterSChan, server, - make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + make(chan birpc.ClientConnector, 1), nil, anz, srvDep) if srv.IsRunning() { t.Errorf("Expected service to be down") } @@ -55,7 +55,7 @@ func TestDispatcherSCoverage(t *testing.T) { filterSChan: filterSChan, server: server, connMgr: nil, - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), anz: anz, srvDep: srvDep, } @@ -72,8 +72,11 @@ func TestDispatcherSCoverage(t *testing.T) { if shouldRun != false { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", false, shouldRun) } - - srv2.connChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + srv2.connChan <- cacheSrv shutErr := srv2.Shutdown() if shutErr != nil { t.Errorf("\nExpecting ,\n Received <%+v>", shutErr) diff --git a/services/dnsagent.go b/services/dnsagent.go index 9af38f9de..7406e79c5 100644 --- a/services/dnsagent.go +++ b/services/dnsagent.go @@ -69,7 +69,7 @@ func (dns *DNSAgent) Start() (err error) { defer dns.Unlock() dns.dns, err = agents.NewDNSAgent(dns.cfg, filterS, dns.connMgr) if err != nil { - utils.Logger.Err(fmt.Sprintf("<%s> error: <%s>", utils.DNSAgent, err.Error())) + utils.Logger.Err(fmt.Sprintf("<%s> failed to initialize agent, error: <%s>", utils.DNSAgent, err.Error())) dns.dns = nil return } diff --git a/services/dnsagent_it_test.go b/services/dnsagent_it_test.go index 6b3d93786..9cb3f4845 100644 --- a/services/dnsagent_it_test.go +++ b/services/dnsagent_it_test.go @@ -27,13 +27,14 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/agents" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestDNSAgentStartReloadShut(t *testing.T) { @@ -63,11 +64,11 @@ func TestDNSAgentStartReloadShut(t *testing.T) { engine.NewConnManager(cfg, nil) db := NewDataDBService(cfg, nil, srvDep) server := cores.NewServer(nil) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) runtime.Gosched() time.Sleep(10 * time.Millisecond) //need to switch to gorutine if err := srv.Shutdown(); err != nil { @@ -107,21 +108,24 @@ func TestDNSAgentReloadFirst(t *testing.T) { }() shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) - - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) srv := NewDNSAgent(cfg, filterSChan, shdChan, nil, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -130,10 +134,11 @@ func TestDNSAgentReloadFirst(t *testing.T) { t.Fatalf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dnsagent_reload"), - Section: config.DNSAgentJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dnsagent_reload"), + Section: config.DNSAgentJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) @@ -143,22 +148,24 @@ func TestDNSAgentReloadFirst(t *testing.T) { if !srv.IsRunning() { t.Fatalf("Expected service to be running") } - err := srv.Start() + err = srv.Start() if err == nil || err != utils.ErrServiceAlreadyRunning { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err) } - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dnsagent_reload"), - Section: config.DNSAgentJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dnsagent_reload"), + Section: config.DNSAgentJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) } - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dnsagent_reload"), - Section: config.DNSAgentJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "dnsagent_reload"), + Section: config.DNSAgentJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) diff --git a/services/dnsagent_test.go b/services/dnsagent_test.go index 531c103b3..85584105c 100644 --- a/services/dnsagent_test.go +++ b/services/dnsagent_test.go @@ -21,11 +21,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/agents" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestDNSAgentCoverage for cover testing @@ -37,8 +37,12 @@ func TestDNSAgentCoverage(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewDNSAgent(cfg, filterSChan, shdChan, nil, srvDep) if srv.IsRunning() { diff --git a/services/ees.go b/services/ees.go index 20ffbd8af..699ff4964 100644 --- a/services/ees.go +++ b/services/ees.go @@ -22,20 +22,19 @@ import ( "fmt" "sync" - v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/ees" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewEventExporterService constructs EventExporterService func NewEventExporterService(cfg *config.CGRConfig, filterSChan chan *engine.FilterS, connMgr *engine.ConnManager, server *cores.Server, - intConnChan chan rpcclient.ClientConnector, anz *AnalyzerService, + intConnChan chan birpc.ClientConnector, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { return &EventExporterService{ cfg: cfg, @@ -57,12 +56,11 @@ type EventExporterService struct { filterSChan chan *engine.FilterS connMgr *engine.ConnManager server *cores.Server - intConnChan chan rpcclient.ClientConnector + intConnChan chan birpc.ClientConnector rldChan chan struct{} stopChan chan struct{} eeS *ees.EventExporterS - rpc *v1.EeSv1 anz *AnalyzerService srvDep map[string]*sync.WaitGroup } @@ -102,7 +100,7 @@ func (es *EventExporterService) Shutdown() (err error) { } // Start should handle the service start -func (es *EventExporterService) Start() (err error) { +func (es *EventExporterService) Start() error { if es.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -119,10 +117,15 @@ func (es *EventExporterService) Start() (err error) { es.stopChan = make(chan struct{}) go es.eeS.ListenAndServe(es.stopChan, es.rldChan) - es.rpc = v1.NewEeSv1(es.eeS) - if !es.cfg.DispatcherSCfg().Enabled { - es.server.RpcRegister(es.rpc) + srv, err := engine.NewServiceWithName(es.eeS, utils.EeS, true) + if err != nil { + return err } - es.intConnChan <- es.anz.GetInternalCodec(es.eeS, utils.EEs) - return + if !es.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + es.server.RpcRegister(s) + } + } + es.intConnChan <- es.anz.GetInternalCodec(srv, utils.EEs) + return nil } diff --git a/services/ees_it_test.go b/services/ees_it_test.go index 8f603a53b..05d63cf37 100644 --- a/services/ees_it_test.go +++ b/services/ees_it_test.go @@ -27,8 +27,8 @@ import ( "testing" "time" - "github.com/cgrates/rpcclient" - + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -62,14 +62,14 @@ func TestEventExporterSReload(t *testing.T) { chS := engine.NewCacheS(cfg, nil, nil) close(chS.GetPrecacheChannel(utils.CacheAttributeProfiles)) close(chS.GetPrecacheChannel(utils.CacheAttributeFilterIndexes)) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) attrS := NewAttributeService(cfg, db, - chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), + chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) ees := NewEventExporterService(cfg, filterSChan, engine.NewConnManager(cfg, nil), - server, make(chan rpcclient.ClientConnector, 2), anz, srvDep) + server, make(chan birpc.ClientConnector, 2), anz, srvDep) srvMngr.AddServices(ees, attrS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -86,10 +86,11 @@ func TestEventExporterSReload(t *testing.T) { fcTmp.ComputePath() cfg.TemplatesCfg()["requiredFields"] = []*config.FCTemplate{fcTmp} var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "ees"), - Section: config.EEsJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "ees"), + Section: config.EEsJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) @@ -136,9 +137,9 @@ func TestEventExporterSReload2(t *testing.T) { shdChan := utils.NewSyncedChan() server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) ees := NewEventExporterService(cfg, filterSChan, engine.NewConnManager(cfg, nil), - server, make(chan rpcclient.ClientConnector, 2), anz, srvDep) + server, make(chan birpc.ClientConnector, 2), anz, srvDep) if ees.IsRunning() { t.Fatalf("Expected service to be down") } diff --git a/services/ees_test.go b/services/ees_test.go index 326de0ba8..6b5654bd8 100644 --- a/services/ees_test.go +++ b/services/ees_test.go @@ -21,13 +21,13 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/ees" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestEventExporterSCoverage for cover testing @@ -41,8 +41,8 @@ func TestEventExporterSCoverage(t *testing.T) { shdChan := utils.NewSyncedChan() server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - srv := NewEventExporterService(cfg, filterSChan, engine.NewConnManager(cfg, nil), server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + srv := NewEventExporterService(cfg, filterSChan, engine.NewConnManager(cfg, nil), server, make(chan birpc.ClientConnector, 1), anz, srvDep) if srv.IsRunning() { t.Errorf("Expected service to be down") } @@ -51,7 +51,7 @@ func TestEventExporterSCoverage(t *testing.T) { filterSChan: filterSChan, connMgr: engine.NewConnManager(cfg, nil), server: server, - intConnChan: make(chan rpcclient.ClientConnector, 1), + intConnChan: make(chan birpc.ClientConnector, 1), anz: anz, srvDep: srvDep, rldChan: make(chan struct{}, 1), @@ -69,7 +69,11 @@ func TestEventExporterSCoverage(t *testing.T) { if shouldRun != false { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", false, shouldRun) } - srv2.intConnChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + srv2.intConnChan <- cacheSrv shutErr := srv2.Shutdown() if shutErr != nil { t.Errorf("\nExpecting ,\n Received <%+v>", shutErr) diff --git a/services/ers_it_test.go b/services/ers_it_test.go index 844f0229d..1f905ba71 100644 --- a/services/ers_it_test.go +++ b/services/ers_it_test.go @@ -28,13 +28,14 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/ers" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestEventReaderSReload(t *testing.T) { @@ -63,13 +64,13 @@ func TestEventReaderSReload(t *testing.T) { server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), shdChan, nil, anz, srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) erS := NewEventReaderService(cfg, filterSChan, shdChan, nil, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(erS, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -77,10 +78,11 @@ func TestEventReaderSReload(t *testing.T) { t.Fatal("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "ers_reload", "internal"), - Section: config.ERsJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "ers_reload", "internal"), + Section: config.ERsJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) diff --git a/services/freeswitchagent.go b/services/freeswitchagent.go index fb731f7f3..01c2d145f 100644 --- a/services/freeswitchagent.go +++ b/services/freeswitchagent.go @@ -54,7 +54,7 @@ type FreeswitchAgent struct { } // Start should handle the sercive start -func (fS *FreeswitchAgent) Start() (err error) { +func (fS *FreeswitchAgent) Start() error { if fS.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -62,15 +62,20 @@ func (fS *FreeswitchAgent) Start() (err error) { fS.Lock() defer fS.Unlock() - fS.fS = agents.NewFSsessions(fS.cfg.FsAgentCfg(), fS.cfg.GeneralCfg().DefaultTimezone, fS.connMgr) + var err error + fS.fS, err = agents.NewFSsessions(fS.cfg.FsAgentCfg(), fS.cfg.GeneralCfg().DefaultTimezone, fS.connMgr) + if err != nil { + utils.Logger.Err(fmt.Sprintf("<%s> failed to initialize agent, error: %s", utils.FreeSWITCHAgent, err)) + return err + } go func(f *agents.FSsessions) { - if err := f.Connect(); err != nil { - utils.Logger.Err(fmt.Sprintf("<%s> error: %s!", utils.FreeSWITCHAgent, err)) + if connErr := f.Connect(); connErr != nil { + utils.Logger.Err(fmt.Sprintf("<%s> error: %s!", utils.FreeSWITCHAgent, connErr)) fS.shdChan.CloseOnce() // stop the engine here } }(fS.fS) - return + return nil } // Reload handles the change of config diff --git a/services/freeswitchagent_it_test.go b/services/freeswitchagent_it_test.go index 19f3f37f6..67aca7f80 100644 --- a/services/freeswitchagent_it_test.go +++ b/services/freeswitchagent_it_test.go @@ -26,13 +26,14 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/agents" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestFreeSwitchAgentReload(t *testing.T) { @@ -51,20 +52,24 @@ func TestFreeSwitchAgentReload(t *testing.T) { }() shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) srv := NewFreeswitchAgent(cfg, shdChan, nil, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -72,10 +77,11 @@ func TestFreeSwitchAgentReload(t *testing.T) { t.Fatalf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "fs_evsock", "cgrates", "etc", "cgrates"), - Section: config.FreeSWITCHAgentJSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "fs_evsock", "cgrates", "etc", "cgrates"), + Section: config.FreeSWITCHAgentJSN, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) @@ -97,8 +103,12 @@ func TestFreeSwitchAgentReload2(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewFreeswitchAgent(cfg, shdChan, nil, srvDep) @@ -109,7 +119,7 @@ func TestFreeSwitchAgentReload2(t *testing.T) { if !srv.IsRunning() { t.Fatalf("Expected service to be running") } - err := srv.Start() + err = srv.Start() if err == nil || err.Error() != "service already running" { t.Fatalf("\nExpected <%+v>, \nReceived <%+v>", "service already running", err) } @@ -129,8 +139,12 @@ func TestFreeSwitchAgentReload3(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewFreeswitchAgent(cfg, shdChan, nil, srvDep) @@ -141,7 +155,7 @@ func TestFreeSwitchAgentReload3(t *testing.T) { if !srv.IsRunning() { t.Fatalf("Expected service to be running") } - err := srv.Start() + err = srv.Start() if err == nil || err.Error() != "service already running" { t.Fatalf("\nExpected <%+v>, \nReceived <%+v>", "service already running", err) } @@ -160,8 +174,12 @@ func TestFreeSwitchAgentReload4(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewFreeswitchAgent(cfg, shdChan, nil, srvDep) if srv.IsRunning() { @@ -186,8 +204,12 @@ func TestFreeSwitchAgentReload4(t *testing.T) { }, }, } - srv.(*FreeswitchAgent).fS = agents.NewFSsessions(agentCfg, "", nil) - err := srv.(*FreeswitchAgent).reload(srv.(*FreeswitchAgent).fS) + + srv.(*FreeswitchAgent).fS, err = agents.NewFSsessions(agentCfg, "", nil) + if err != nil { + t.Fatal(err) + } + err = srv.(*FreeswitchAgent).reload(srv.(*FreeswitchAgent).fS) if err != nil { t.Fatalf("\nExpected <%+v>, \nReceived <%+v>", nil, err) } @@ -202,8 +224,12 @@ func TestFreeSwitchAgentReload5(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewFreeswitchAgent(cfg, shdChan, nil, srvDep) if srv.IsRunning() { @@ -211,7 +237,7 @@ func TestFreeSwitchAgentReload5(t *testing.T) { } srv.(*FreeswitchAgent).fS = nil - err := srv.Start() + err = srv.Start() if err != nil { t.Fatalf("\nExpected <%+v>, \nReceived <%+v>", nil, err) } @@ -226,8 +252,12 @@ func TestFreeSwitchAgentReload6(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewFreeswitchAgent(cfg, shdChan, nil, srvDep) if srv.IsRunning() { @@ -252,8 +282,11 @@ func TestFreeSwitchAgentReload6(t *testing.T) { }, }, } - srv.(*FreeswitchAgent).fS = agents.NewFSsessions(agentCfg, "", nil) - err := srv.Reload() + srv.(*FreeswitchAgent).fS, err = agents.NewFSsessions(agentCfg, "", nil) + if err != nil { + t.Fatal(err) + } + err = srv.Reload() if err != nil { t.Fatalf("\nExpected <%+v>, \nReceived <%+v>", nil, err) } diff --git a/services/freeswitchagent_test.go b/services/freeswitchagent_test.go index 587ecdccf..05b97db88 100644 --- a/services/freeswitchagent_test.go +++ b/services/freeswitchagent_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/agents" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestFreeSwitchAgentCoverage for cover testing @@ -38,8 +38,12 @@ func TestFreeSwitchAgentCoverage(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewFreeswitchAgent(cfg, shdChan, nil, srvDep) diff --git a/services/httpagent_it_test.go b/services/httpagent_it_test.go index 11fd5fb63..c50017e50 100644 --- a/services/httpagent_it_test.go +++ b/services/httpagent_it_test.go @@ -27,12 +27,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestHTTPAgentReload(t *testing.T) { @@ -50,19 +51,23 @@ func TestHTTPAgentReload(t *testing.T) { }() shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) srv := NewHTTPAgent(cfg, filterSChan, server, nil, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -70,10 +75,11 @@ func TestHTTPAgentReload(t *testing.T) { t.Fatalf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "httpagent_mysql_test"), - Section: config.HttpAgentJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "httpagent_mysql_test"), + Section: config.HttpAgentJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) @@ -89,7 +95,7 @@ func TestHTTPAgentReload(t *testing.T) { t.Fatalf("\nExpecting ,\n Received <%+v>", srvReload) } runtime.Gosched() - err := srv.Start() + err = srv.Start() if err != utils.ErrServiceAlreadyRunning { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err) } diff --git a/services/httpagent_test.go b/services/httpagent_test.go index 846a1183e..e93d81de0 100644 --- a/services/httpagent_test.go +++ b/services/httpagent_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestHTTPAgent for cover testing @@ -36,7 +36,7 @@ func TestHTTPAgentCoverage(t *testing.T) { filterSChan := make(chan *engine.FilterS, 1) filterSChan <- nil srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - rpcInternal := map[string]chan rpcclient.ClientConnector{} + rpcInternal := map[string]chan birpc.ClientConnector{} cM := engine.NewConnManager(cfg, rpcInternal) srv := NewHTTPAgent(cfg, filterSChan, server, cM, srvDep) if srv == nil { diff --git a/services/kamailioagent.go b/services/kamailioagent.go index 1330ac032..4e5ed0738 100644 --- a/services/kamailioagent.go +++ b/services/kamailioagent.go @@ -55,7 +55,7 @@ type KamailioAgent struct { } // Start should handle the sercive start -func (kam *KamailioAgent) Start() (err error) { +func (kam *KamailioAgent) Start() error { if kam.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -63,17 +63,22 @@ func (kam *KamailioAgent) Start() (err error) { kam.Lock() defer kam.Unlock() - kam.kam = agents.NewKamailioAgent(kam.cfg.KamAgentCfg(), kam.connMgr, + var err error + kam.kam, err = agents.NewKamailioAgent(kam.cfg.KamAgentCfg(), kam.connMgr, utils.FirstNonEmpty(kam.cfg.KamAgentCfg().Timezone, kam.cfg.GeneralCfg().DefaultTimezone)) + if err != nil { + utils.Logger.Err(fmt.Sprintf("<%s> failed to initialize agent, error: %s", utils.KamailioAgent, err)) + return err + } go func(k *agents.KamailioAgent) { - if err = k.Connect(); err != nil && - !strings.Contains(err.Error(), "use of closed network connection") { // if closed by us do not log - utils.Logger.Err(fmt.Sprintf("<%s> error: %s", utils.KamailioAgent, err)) + if connErr := k.Connect(); connErr != nil && + !strings.Contains(connErr.Error(), "use of closed network connection") { // if closed by us do not log + utils.Logger.Err(fmt.Sprintf("<%s> error: %s", utils.KamailioAgent, connErr)) kam.shdChan.CloseOnce() } }(kam.kam) - return + return nil } // Reload handles the change of config diff --git a/services/kamailioagent_it_test.go b/services/kamailioagent_it_test.go index 3ff8d7429..2756d337f 100644 --- a/services/kamailioagent_it_test.go +++ b/services/kamailioagent_it_test.go @@ -27,6 +27,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/agents" "github.com/cgrates/cgrates/config" @@ -34,7 +36,6 @@ import ( "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestKamailioAgentReload(t *testing.T) { @@ -49,21 +50,24 @@ func TestKamailioAgentReload(t *testing.T) { shdChan := utils.NewSyncedChan() shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) - - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) srv := NewKamailioAgent(cfg, shdChan, nil, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -72,10 +76,11 @@ func TestKamailioAgentReload(t *testing.T) { t.Fatalf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "kamevapi", "cgrates", "etc", "cgrates"), - Section: config.KamailioAgentJSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "tutorial_tests", "kamevapi", "cgrates", "etc", "cgrates"), + Section: config.KamailioAgentJSN, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) @@ -91,9 +96,11 @@ func TestKamailioAgentReload(t *testing.T) { Timezone: "Local", } - srv.(*KamailioAgent).kam = agents.NewKamailioAgent(kaCfg, nil, "") - - err := srv.Reload() + srv.(*KamailioAgent).kam, err = agents.NewKamailioAgent(kaCfg, nil, "") + if err != nil { + t.Fatal(err) + } + err = srv.Reload() if err != nil { t.Fatalf("\nExpected <%+v>, \nReceived <%+v>", nil, err) } diff --git a/services/kamailioagent_test.go b/services/kamailioagent_test.go index 44d70522f..4b0008655 100644 --- a/services/kamailioagent_test.go +++ b/services/kamailioagent_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/agents" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) //TestKamailioAgentCoverage for cover testing @@ -40,8 +40,12 @@ func TestKamailioAgentCoverage(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewKamailioAgent(cfg, shdChan, nil, srvDep) if srv.IsRunning() { diff --git a/services/loaders.go b/services/loaders.go index 51cdb485c..2afa3ec49 100644 --- a/services/loaders.go +++ b/services/loaders.go @@ -21,19 +21,18 @@ package services import ( "sync" - v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/loaders" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewLoaderService returns the Loader Service func NewLoaderService(cfg *config.CGRConfig, dm *DataDBService, filterSChan chan *engine.FilterS, server *cores.Server, - internalLoaderSChan chan rpcclient.ClientConnector, + internalLoaderSChan chan birpc.ClientConnector, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) *LoaderService { return &LoaderService{ @@ -59,15 +58,14 @@ type LoaderService struct { stopChan chan struct{} ldrs *loaders.LoaderService - rpc *v1.LoaderSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector connMgr *engine.ConnManager anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the sercive start -func (ldrs *LoaderService) Start() (err error) { +func (ldrs *LoaderService) Start() error { if ldrs.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -85,17 +83,22 @@ func (ldrs *LoaderService) Start() (err error) { ldrs.cfg.GeneralCfg().DefaultTimezone, filterS, ldrs.connMgr) if !ldrs.ldrs.Enabled() { - return + return nil } - if err = ldrs.ldrs.ListenAndServe(ldrs.stopChan); err != nil { - return + if err := ldrs.ldrs.ListenAndServe(ldrs.stopChan); err != nil { + return err + } + srv, err := engine.NewServiceWithName(ldrs.ldrs, utils.LoaderS, true) + if err != nil { + return err } - ldrs.rpc = v1.NewLoaderSv1(ldrs.ldrs) if !ldrs.cfg.DispatcherSCfg().Enabled { - ldrs.server.RpcRegister(ldrs.rpc) + for _, s := range srv { + ldrs.server.RpcRegister(s) + } } - ldrs.connChan <- ldrs.anz.GetInternalCodec(ldrs.rpc, utils.LoaderS) - return + ldrs.connChan <- ldrs.anz.GetInternalCodec(srv, utils.LoaderS) + return nil } // Reload handles the change of config @@ -123,7 +126,6 @@ func (ldrs *LoaderService) Reload() (err error) { func (ldrs *LoaderService) Shutdown() (err error) { ldrs.Lock() ldrs.ldrs = nil - ldrs.rpc = nil close(ldrs.stopChan) <-ldrs.connChan ldrs.Unlock() diff --git a/services/loaders_it_test.go b/services/loaders_it_test.go index 5edf18295..0b123a9a1 100644 --- a/services/loaders_it_test.go +++ b/services/loaders_it_test.go @@ -27,12 +27,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func testCreateDirs(t *testing.T) { @@ -72,10 +73,10 @@ func TestLoaderSReload(t *testing.T) { srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) conMngr := engine.NewConnManager(cfg, nil) srv := NewLoaderService(cfg, db, filterSChan, - server, make(chan rpcclient.ClientConnector, 1), + server, make(chan birpc.ClientConnector, 1), conMngr, anz, srvDep) srvMngr.AddServices(srv, db) if err := srvMngr.StartServices(); err != nil { @@ -91,10 +92,11 @@ func TestLoaderSReload(t *testing.T) { } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "loaders", "tutinternal"), - Section: config.LoaderJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "loaders", "tutinternal"), + Section: config.LoaderJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) @@ -154,9 +156,9 @@ func TestLoaderSReload2(t *testing.T) { srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) db.dbchan <- new(engine.DataManager) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) srv := NewLoaderService(cfg, db, filterSChan, - server, make(chan rpcclient.ClientConnector, 1), + server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) err := srv.Start() if err != nil { @@ -179,9 +181,9 @@ func TestLoaderSReload3(t *testing.T) { srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) db.dbchan <- new(engine.DataManager) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) srv := NewLoaderService(cfg, db, filterSChan, - server, make(chan rpcclient.ClientConnector, 1), + server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) err := srv.Start() if err == nil || err.Error() != "no such file or directory" { diff --git a/services/loaders_test.go b/services/loaders_test.go index 9797fcf15..f93563c0a 100644 --- a/services/loaders_test.go +++ b/services/loaders_test.go @@ -22,13 +22,13 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/loaders" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestLoaderSCoverage for cover testing @@ -40,10 +40,10 @@ func TestLoaderSCoverage(t *testing.T) { server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - internalLoaderSChan := make(chan rpcclient.ClientConnector, 1) - rpcInternal := map[string]chan rpcclient.ClientConnector{} + internalLoaderSChan := make(chan birpc.ClientConnector, 1) + rpcInternal := map[string]chan birpc.ClientConnector{} cM := engine.NewConnManager(cfg, rpcInternal) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) srv := NewLoaderService(cfg, db, filterSChan, server, internalLoaderSChan, cM, anz, srvDep) @@ -84,7 +84,11 @@ func TestLoaderSCoverage(t *testing.T) { } srv.stopChan = make(chan struct{}, 1) chS := engine.NewCacheS(cfg, nil, nil) - srv.connChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + srv.connChan <- cacheSrv srv.Shutdown() if srv.IsRunning() { t.Errorf("Expected service to be down") diff --git a/services/radiusagent_it_test.go b/services/radiusagent_it_test.go index 9cb0a75d7..b98cf0319 100644 --- a/services/radiusagent_it_test.go +++ b/services/radiusagent_it_test.go @@ -27,13 +27,14 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/agents" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestRadiusAgentReload(t *testing.T) { @@ -52,21 +53,24 @@ func TestRadiusAgentReload(t *testing.T) { }() shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) - - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) srv := NewRadiusAgent(cfg, filterSChan, shdChan, nil, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -74,10 +78,11 @@ func TestRadiusAgentReload(t *testing.T) { t.Fatalf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "radagent_mysql"), - Section: config.RA_JSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "radagent_mysql"), + Section: config.RA_JSN, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) @@ -88,7 +93,7 @@ func TestRadiusAgentReload(t *testing.T) { t.Fatalf("Expected service to be running") } runtime.Gosched() - err := srv.Start() + err = srv.Start() if err == nil || err != utils.ErrServiceAlreadyRunning { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err) } @@ -120,21 +125,24 @@ func TestRadiusAgentReload2(t *testing.T) { }() shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) - - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) srv := NewRadiusAgent(cfg, filterSChan, shdChan, nil, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -142,10 +150,11 @@ func TestRadiusAgentReload2(t *testing.T) { t.Fatalf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "radagent_mysql"), - Section: config.RA_JSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "radagent_mysql"), + Section: config.RA_JSN, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) @@ -158,7 +167,7 @@ func TestRadiusAgentReload2(t *testing.T) { } runtime.Gosched() runtime.Gosched() - err := srv.Start() + err = srv.Start() if err == nil || err != utils.ErrServiceAlreadyRunning { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err) } diff --git a/services/radiusagent_test.go b/services/radiusagent_test.go index 7bdf091b3..6ff24df22 100644 --- a/services/radiusagent_test.go +++ b/services/radiusagent_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/agents" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestLoaderSCoverage for cover testing @@ -38,8 +38,12 @@ func TestRadiusAgentCoverage(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewRadiusAgent(cfg, filterSChan, shdChan, nil, srvDep) if srv.IsRunning() { diff --git a/services/rals.go b/services/rals.go index e484e2aca..a578f7a9a 100644 --- a/services/rals.go +++ b/services/rals.go @@ -21,17 +21,17 @@ package services import ( "sync" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewRalService returns the Ral Service func NewRalService(cfg *config.CGRConfig, cacheS *engine.CacheS, server *cores.Server, - internalRALsChan, internalResponderChan chan rpcclient.ClientConnector, shdChan *utils.SyncedChan, + internalRALsChan, internalResponderChan chan birpc.ClientConnector, shdChan *utils.SyncedChan, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup, filtersCh chan *engine.FilterS) *RalService { @@ -57,7 +57,7 @@ type RalService struct { server *cores.Server rals *v1.RALsV1 responder *ResponderService - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector connMgr *engine.ConnManager anz *AnalyzerService srvDep map[string]*sync.WaitGroup @@ -65,7 +65,7 @@ type RalService struct { // Start should handle the sercive start // For this service the start should be called from RAL Service -func (rals *RalService) Start() (err error) { +func (rals *RalService) Start() error { if rals.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -87,12 +87,18 @@ func (rals *RalService) Start() (err error) { rals.rals = v1.NewRALsV1() + srv, err := engine.NewService(rals.rals) + if err != nil { + return err + } if !rals.cfg.DispatcherSCfg().Enabled { - rals.server.RpcRegister(rals.rals) + for _, s := range srv { + rals.server.RpcRegister(s) + } } - rals.connChan <- rals.anz.GetInternalCodec(rals.rals, utils.RALService) - return + rals.connChan <- rals.anz.GetInternalCodec(srv, utils.RALService) + return nil } // Reload handles the change of config diff --git a/services/rals_it_test.go b/services/rals_it_test.go index 977413a21..63de38d3e 100644 --- a/services/rals_it_test.go +++ b/services/rals_it_test.go @@ -26,12 +26,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestRalsReload(t *testing.T) { @@ -65,16 +66,16 @@ func TestRalsReload(t *testing.T) { srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) cfg.StorDbCfg().Type = utils.MetaInternal - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) stordb := NewStorDBService(cfg, srvDep) - schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) + schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) ralS := NewRalService(cfg, chS, server, - make(chan rpcclient.ClientConnector, 1), - make(chan rpcclient.ClientConnector, 1), + make(chan birpc.ClientConnector, 1), + make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep, filterSChan) srvMngr.AddServices(ralS, schS, tS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db, stordb) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db, stordb) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -88,10 +89,11 @@ func TestRalsReload(t *testing.T) { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.RALS_JSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.RALS_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) @@ -158,10 +160,10 @@ func TestRalsReload2(t *testing.T) { server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} cfg.StorDbCfg().Type = utils.MetaInternal - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) ralS := NewRalService(cfg, chS, server, - make(chan rpcclient.ClientConnector, 1), - make(chan rpcclient.ClientConnector, 1), + make(chan birpc.ClientConnector, 1), + make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep, filterSChan) ralS.responder.resp = &engine.Responder{ ShdChan: shdChan, diff --git a/services/rals_test.go b/services/rals_test.go index 186a1c76d..70102b13c 100644 --- a/services/rals_test.go +++ b/services/rals_test.go @@ -22,12 +22,12 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestRalsCoverage for cover testing @@ -41,10 +41,10 @@ func TestRalsCoverage(t *testing.T) { server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} cfg.StorDbCfg().Type = utils.MetaInternal - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) ralS := NewRalService(cfg, chS, server, - make(chan rpcclient.ClientConnector, 1), - make(chan rpcclient.ClientConnector, 1), + make(chan birpc.ClientConnector, 1), + make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep, filterSChan) if ralS.IsRunning() { t.Errorf("Expected service to be down") @@ -55,7 +55,7 @@ func TestRalsCoverage(t *testing.T) { server: server, shdChan: shdChan, resp: &engine.Responder{}, - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), anz: anz, srvDep: srvDep, }, @@ -63,9 +63,13 @@ func TestRalsCoverage(t *testing.T) { cacheS: chS, server: server, rals: &v1.RALsV1{}, - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), } - ralS2.responder.connChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + ralS2.responder.connChan <- cacheSrv if !ralS2.IsRunning() { t.Errorf("Expected service to be running") } @@ -80,7 +84,7 @@ func TestRalsCoverage(t *testing.T) { if !reflect.DeepEqual(ralS2.GetResponder(), ralS2.responder) { t.Errorf("\nExpecting <%+v>,\n Received <%+v>", ralS2.responder, ralS2.GetResponder()) } - ralS2.connChan <- chS + ralS2.connChan <- cacheSrv ralS2.Shutdown() if ralS.IsRunning() { t.Errorf("Expected service to be down") diff --git a/services/registrarc_it_test.go b/services/registrarc_it_test.go index e2e07b78c..a564b53cc 100644 --- a/services/registrarc_it_test.go +++ b/services/registrarc_it_test.go @@ -27,6 +27,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -54,12 +56,12 @@ func TestDispatcherHReload(t *testing.T) { srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) connMngr := engine.NewConnManager(cfg, nil) srv := NewRegistrarCService(cfg, server, connMngr, anz, srvDep) srvMngr.AddServices(srv, NewLoaderService(cfg, db, filterSChan, server, - make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -68,10 +70,11 @@ func TestDispatcherHReload(t *testing.T) { } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "registrarc", "all_mongo"), - Section: config.RegistrarCJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "registrarc", "all_mongo"), + Section: config.RegistrarCJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/registrarc_test.go b/services/registrarc_test.go index 7d4609baa..5c0281193 100644 --- a/services/registrarc_test.go +++ b/services/registrarc_test.go @@ -23,12 +23,12 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/registrarc" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestDispatcherCoverage for cover testing @@ -39,8 +39,8 @@ func TestDispatcherHCoverage(t *testing.T) { filterSChan <- nil server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - rpcInternal := map[string]chan rpcclient.ClientConnector{} + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + rpcInternal := map[string]chan birpc.ClientConnector{} cM := engine.NewConnManager(cfg, rpcInternal) srv := NewRegistrarCService(cfg, server, cM, anz, srvDep) if srv == nil { diff --git a/services/resources.go b/services/resources.go index f043e4476..43e4e5371 100644 --- a/services/resources.go +++ b/services/resources.go @@ -22,19 +22,18 @@ import ( "fmt" "sync" - v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewResourceService returns the Resource Service func NewResourceService(cfg *config.CGRConfig, dm *DataDBService, cacheS *engine.CacheS, filterSChan chan *engine.FilterS, - server *cores.Server, internalResourceSChan chan rpcclient.ClientConnector, + server *cores.Server, internalResourceSChan chan birpc.ClientConnector, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { return &ResourceService{ @@ -60,15 +59,14 @@ type ResourceService struct { server *cores.Server reS *engine.ResourceService - rpc *v1.ResourceSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector connMgr *engine.ConnManager anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the service start -func (reS *ResourceService) Start() (err error) { +func (reS *ResourceService) Start() error { if reS.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -88,12 +86,17 @@ func (reS *ResourceService) Start() (err error) { reS.reS = engine.NewResourceService(datadb, reS.cfg, filterS, reS.connMgr) utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.ResourceS)) reS.reS.StartLoop() - reS.rpc = v1.NewResourceSv1(reS.reS) - if !reS.cfg.DispatcherSCfg().Enabled { - reS.server.RpcRegister(reS.rpc) + srv, err := engine.NewServiceWithName(reS.reS, utils.ResourceS, true) + if err != nil { + return err } - reS.connChan <- reS.anz.GetInternalCodec(reS.rpc, utils.ResourceS) - return + if !reS.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + reS.server.RpcRegister(s) + } + } + reS.connChan <- reS.anz.GetInternalCodec(srv, utils.ResourceS) + return nil } // Reload handles the change of config @@ -111,7 +114,6 @@ func (reS *ResourceService) Shutdown() (err error) { defer reS.Unlock() reS.reS.Shutdown() //we don't verify the error because shutdown never returns an error reS.reS = nil - reS.rpc = nil <-reS.connChan return } diff --git a/services/resources_it_test.go b/services/resources_it_test.go index 6eb25eeb4..032f65d28 100644 --- a/services/resources_it_test.go +++ b/services/resources_it_test.go @@ -26,8 +26,8 @@ import ( "testing" "time" - "github.com/cgrates/rpcclient" - + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -56,13 +56,13 @@ func TestResourceSReload(t *testing.T) { server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) - reS := NewResourceService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) + reS := NewResourceService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(tS, reS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -73,10 +73,11 @@ func TestResourceSReload(t *testing.T) { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.RESOURCES_JSON, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.RESOURCES_JSON, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/resources_test.go b/services/resources_test.go index 23f614aca..d26f0fe11 100644 --- a/services/resources_test.go +++ b/services/resources_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestResourceSCoverage for cover testing @@ -39,9 +39,9 @@ func TestResourceSCoverage(t *testing.T) { chS := engine.NewCacheS(cfg, nil, nil) server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, srvDep) - reS := NewResourceService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + reS := NewResourceService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) if reS.IsRunning() { t.Errorf("Expected service to be down") @@ -52,7 +52,7 @@ func TestResourceSCoverage(t *testing.T) { cacheS: chS, filterSChan: filterSChan, server: server, - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), connMgr: nil, anz: anz, srvDep: srvDep, diff --git a/services/responders.go b/services/responders.go index a2b081f34..83672e01f 100644 --- a/services/responders.go +++ b/services/responders.go @@ -21,16 +21,16 @@ package services import ( "sync" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewResponderService returns the Resonder Service func NewResponderService(cfg *config.CGRConfig, server *cores.Server, - internalRALsChan chan rpcclient.ClientConnector, + internalRALsChan chan birpc.ClientConnector, shdChan *utils.SyncedChan, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup, filterSCh chan *engine.FilterS) *ResponderService { @@ -55,7 +55,7 @@ type ResponderService struct { shdChan *utils.SyncedChan resp *engine.Responder - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector anz *AnalyzerService srvDep map[string]*sync.WaitGroup syncChans map[string]chan *engine.Responder @@ -65,7 +65,7 @@ type ResponderService struct { // Start should handle the sercive start // For this service the start should be called from RAL Service -func (resp *ResponderService) Start() (err error) { +func (resp *ResponderService) Start() error { if resp.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -80,13 +80,19 @@ func (resp *ResponderService) Start() (err error) { MaxComputedUsage: resp.cfg.RalsCfg().MaxComputedUsage, } + srv, err := engine.NewService(resp.resp) + if err != nil { + return err + } if !resp.cfg.DispatcherSCfg().Enabled { - resp.server.RpcRegister(resp.resp) + for _, s := range srv { + resp.server.RpcRegister(s) + } } - resp.connChan <- resp.anz.GetInternalCodec(resp.resp, utils.ResponderS) // Rater done + resp.connChan <- resp.anz.GetInternalCodec(srv, utils.ResponderS) // Rater done resp.sync() - return + return nil } // Reload handles the change of config diff --git a/services/responders_it_test.go b/services/responders_it_test.go index 2e6c85e15..5ad390946 100644 --- a/services/responders_it_test.go +++ b/services/responders_it_test.go @@ -24,8 +24,7 @@ import ( "sync" "testing" - "github.com/cgrates/rpcclient" - + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -44,8 +43,8 @@ func TestResponderSReload(t *testing.T) { shdChan := utils.NewSyncedChan() server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - internalChan := make(chan rpcclient.ClientConnector, 1) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + internalChan := make(chan birpc.ClientConnector, 1) srv := NewResponderService(cfg, server, internalChan, shdChan, anz, srvDep, filterSChan) @@ -101,8 +100,8 @@ func TestResponderSReload2(t *testing.T) { shdChan := utils.NewSyncedChan() server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - internalChan := make(chan rpcclient.ClientConnector, 1) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + internalChan := make(chan birpc.ClientConnector, 1) srv := NewResponderService(cfg, server, internalChan, shdChan, anz, srvDep, filterSChan) diff --git a/services/responders_test.go b/services/responders_test.go index 5ffd1a302..92dcb245c 100644 --- a/services/responders_test.go +++ b/services/responders_test.go @@ -22,24 +22,24 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestResponderCoverage for cover testing func TestResponderCoverage(t *testing.T) { cfg := config.NewDefaultCGRConfig() server := cores.NewServer(nil) - internalChan := make(chan rpcclient.ClientConnector, 1) + internalChan := make(chan birpc.ClientConnector, 1) shdChan := utils.NewSyncedChan() filterSChan := make(chan *engine.FilterS, 1) filterSChan <- nil srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} anz := NewAnalyzerService(cfg, server, filterSChan, - shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + shdChan, make(chan birpc.ClientConnector, 1), srvDep) srv := NewResponderService(cfg, server, internalChan, shdChan, anz, srvDep, filterSChan) if srv == nil { diff --git a/services/routes.go b/services/routes.go index 4f4aefb9e..829f44a65 100644 --- a/services/routes.go +++ b/services/routes.go @@ -22,19 +22,18 @@ import ( "fmt" "sync" - v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewRouteService returns the Route Service func NewRouteService(cfg *config.CGRConfig, dm *DataDBService, cacheS *engine.CacheS, filterSChan chan *engine.FilterS, - server *cores.Server, internalRouteSChan chan rpcclient.ClientConnector, + server *cores.Server, internalRouteSChan chan birpc.ClientConnector, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { return &RouteService{ @@ -61,14 +60,13 @@ type RouteService struct { connMgr *engine.ConnManager routeS *engine.RouteService - rpc *v1.RouteSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the sercive start -func (routeS *RouteService) Start() (err error) { +func (routeS *RouteService) Start() error { if routeS.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -87,12 +85,17 @@ func (routeS *RouteService) Start() (err error) { routeS.routeS = engine.NewRouteService(datadb, filterS, routeS.cfg, routeS.connMgr) utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.RouteS)) - routeS.rpc = v1.NewRouteSv1(routeS.routeS) - if !routeS.cfg.DispatcherSCfg().Enabled { - routeS.server.RpcRegister(routeS.rpc) + srv, err := engine.NewServiceWithName(routeS.routeS, utils.RouteS, true) + if err != nil { + return err } - routeS.connChan <- routeS.anz.GetInternalCodec(routeS.rpc, utils.RouteS) - return + if !routeS.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + routeS.server.RpcRegister(s) + } + } + routeS.connChan <- routeS.anz.GetInternalCodec(srv, utils.RouteS) + return nil } // Reload handles the change of config @@ -106,7 +109,6 @@ func (routeS *RouteService) Shutdown() (err error) { defer routeS.Unlock() routeS.routeS.Shutdown() //we don't verify the error because shutdown never returns an error routeS.routeS = nil - routeS.rpc = nil <-routeS.connChan return } diff --git a/services/routes_it_test.go b/services/routes_it_test.go index aa010a420..b61b3e6cf 100644 --- a/services/routes_it_test.go +++ b/services/routes_it_test.go @@ -26,12 +26,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestRouteSReload(t *testing.T) { @@ -50,12 +51,12 @@ func TestRouteSReload(t *testing.T) { server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, srvDep) - routeS := NewRouteService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + routeS := NewRouteService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(routeS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -66,10 +67,11 @@ func TestRouteSReload(t *testing.T) { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "cluelrn"), - Section: config.RouteSJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "cluelrn"), + Section: config.RouteSJson, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/routes_test.go b/services/routes_test.go index af882c2c9..23267c153 100644 --- a/services/routes_test.go +++ b/services/routes_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestSupplierSCoverage for cover testing @@ -40,8 +40,8 @@ func TestSupplierSCoverage(t *testing.T) { server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - supS := NewRouteService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + supS := NewRouteService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) if supS.IsRunning() { t.Errorf("Expected service to be down") @@ -54,8 +54,7 @@ func TestSupplierSCoverage(t *testing.T) { server: server, connMgr: nil, routeS: &engine.RouteService{}, - rpc: nil, - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), anz: anz, srvDep: srvDep, } @@ -70,7 +69,11 @@ func TestSupplierSCoverage(t *testing.T) { if !reflect.DeepEqual(shouldRun, false) { t.Errorf("\nExpecting ,\n Received <%+v>", shouldRun) } - supS2.connChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + supS2.connChan <- cacheSrv supS2.Shutdown() if supS.IsRunning() { t.Errorf("Expected service to be down") diff --git a/services/schedulers.go b/services/schedulers.go index 1b21f019a..014f9d69c 100644 --- a/services/schedulers.go +++ b/services/schedulers.go @@ -21,19 +21,19 @@ package services import ( "sync" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/scheduler" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewSchedulerService returns the Scheduler Service func NewSchedulerService(cfg *config.CGRConfig, dm *DataDBService, cacheS *engine.CacheS, fltrSChan chan *engine.FilterS, - server *cores.Server, internalSchedulerrSChan chan rpcclient.ClientConnector, + server *cores.Server, internalSchedulerrSChan chan birpc.ClientConnector, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) *SchedulerService { return &SchedulerService{ @@ -60,14 +60,14 @@ type SchedulerService struct { schS *scheduler.Scheduler rpc *v1.SchedulerSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector connMgr *engine.ConnManager anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the sercive start -func (schS *SchedulerService) Start() (err error) { +func (schS *SchedulerService) Start() error { if schS.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -87,12 +87,17 @@ func (schS *SchedulerService) Start() (err error) { go schS.schS.Loop() schS.rpc = v1.NewSchedulerSv1(schS.cfg, datadb, fltrS) - if !schS.cfg.DispatcherSCfg().Enabled { - schS.server.RpcRegister(schS.rpc) + srv, err := engine.NewService(schS.rpc) + if err != nil { + return err } - schS.connChan <- schS.anz.GetInternalCodec(schS.rpc, utils.SchedulerS) - - return + if !schS.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + schS.server.RpcRegister(s) + } + } + schS.connChan <- schS.anz.GetInternalCodec(srv, utils.SchedulerS) + return nil } // Reload handles the change of config diff --git a/services/schedulers_it_test.go b/services/schedulers_it_test.go index b3e1a669e..52e204bca 100644 --- a/services/schedulers_it_test.go +++ b/services/schedulers_it_test.go @@ -27,12 +27,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestSchedulerSReload(t *testing.T) { @@ -50,11 +51,11 @@ func TestSchedulerSReload(t *testing.T) { srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(schS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -65,10 +66,11 @@ func TestSchedulerSReload(t *testing.T) { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongonew"), - Section: config.SCHEDULER_JSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongonew"), + Section: config.SCHEDULER_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/schedulers_test.go b/services/schedulers_test.go index 0e7021182..6a9d038ad 100644 --- a/services/schedulers_test.go +++ b/services/schedulers_test.go @@ -22,13 +22,13 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/scheduler" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestSchedulerSCoverage for cover testing @@ -42,8 +42,8 @@ func TestSchedulerSCoverage(t *testing.T) { server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) if schS.IsRunning() { t.Errorf("Expected service to be down") diff --git a/services/sessions.go b/services/sessions.go index a7d31f3a5..f9f8cc997 100644 --- a/services/sessions.go +++ b/services/sessions.go @@ -22,6 +22,7 @@ import ( "fmt" "sync" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -30,12 +31,11 @@ import ( "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewSessionService returns the Session Service func NewSessionService(cfg *config.CGRConfig, dm *DataDBService, - server *cores.Server, internalChan chan rpcclient.ClientConnector, + server *cores.Server, internalChan chan birpc.ClientConnector, shdChan *utils.SyncedChan, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { return &SessionService{ @@ -61,18 +61,17 @@ type SessionService struct { sm *sessions.SessionS rpc *v1.SMGenericV1 - rpcv1 *v1.SessionSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector // in order to stop the bircp server if necesary - bircpEnabled bool + birpcEnabled bool connMgr *engine.ConnManager anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the sercive start -func (smg *SessionService) Start() (err error) { +func (smg *SessionService) Start() error { if smg.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -90,29 +89,39 @@ func (smg *SessionService) Start() (err error) { //start sync session in a separate gorutine smg.stopChan = make(chan struct{}) go smg.sm.ListenAndServe(smg.stopChan) - // Pass internal connection via BiRPCClient - smg.connChan <- smg.anz.GetInternalBiRPCCodec(smg.sm, utils.SessionS) + // Pass internal connection + srv, err := engine.NewServiceWithName(v1.NewSessionSv1(smg.sm), "", false) + if err != nil { + return err + } + smg.connChan <- smg.anz.GetInternalCodec(srv, utils.SessionS) // Register RPC handler smg.rpc = v1.NewSMGenericV1(smg.sm) - smg.rpcv1 = v1.NewSessionSv1(smg.sm) // methods with multiple options if !smg.cfg.DispatcherSCfg().Enabled { - smg.server.RpcRegister(smg.rpc) - smg.server.RpcRegister(smg.rpcv1) + for _, s := range srv { + smg.server.RpcRegister(s) + } + + var legacySrv engine.IntService + legacySrv, err := engine.NewService(smg.rpc) + if err != nil { + return err + } + for _, s := range legacySrv { + smg.server.RpcRegister(s) + } } // Register BiRpc handlers if smg.cfg.SessionSCfg().ListenBijson != "" { - smg.bircpEnabled = true - for method, handler := range smg.rpc.Handlers() { - smg.server.BiRPCRegisterName(method, handler) - } - for method, handler := range smg.rpcv1.Handlers() { - smg.server.BiRPCRegisterName(method, handler) + smg.birpcEnabled = true + for n, s := range srv { + smg.server.BiRPCRegisterName(n, s) } // run this in it's own goroutine go smg.start() } - return + return nil } func (smg *SessionService) start() (err error) { @@ -120,7 +129,7 @@ func (smg *SessionService) start() (err error) { smg.cfg.SessionSCfg().ListenBigob, smg.sm.OnBiJSONConnect, smg.sm.OnBiJSONDisconnect); err != nil { utils.Logger.Err(fmt.Sprintf("<%s> serve BiRPC error: %s!", utils.SessionS, err)) smg.Lock() - smg.bircpEnabled = false + smg.birpcEnabled = false smg.Unlock() smg.shdChan.CloseOnce() } @@ -140,13 +149,12 @@ func (smg *SessionService) Shutdown() (err error) { if err = smg.sm.Shutdown(); err != nil { return } - if smg.bircpEnabled { + if smg.birpcEnabled { smg.server.StopBiRPC() - smg.bircpEnabled = false + smg.birpcEnabled = false } smg.sm = nil smg.rpc = nil - smg.rpcv1 = nil <-smg.connChan return } diff --git a/services/sessions_it_test.go b/services/sessions_it_test.go index 8094f1f07..664ae6866 100644 --- a/services/sessions_it_test.go +++ b/services/sessions_it_test.go @@ -28,6 +28,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -44,7 +46,7 @@ type testMockClients struct { calls func(args any, reply any) error } -func (sT *testMockClients) Call(method string, arg any, rply any) error { +func (sT *testMockClients) Call(ctx *context.Context, method string, arg any, rply any) error { return sT.calls(arg, rply) } @@ -78,7 +80,7 @@ func TestSessionSReload1(t *testing.T) { server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - clientConect := make(chan rpcclient.ClientConnector, 1) + clientConect := make(chan birpc.ClientConnector, 1) clientConect <- &testMockClients{ calls: func(args any, reply any) error { rply, cancast := reply.(*[]*engine.ChrgSProcessEventReply) @@ -96,11 +98,11 @@ func TestSessionSReload1(t *testing.T) { return nil }, } - conMng := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + conMng := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): clientConect, }) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - srv := NewSessionService(cfg, new(DataDBService), server, make(chan rpcclient.ClientConnector, 1), shdChan, conMng, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + srv := NewSessionService(cfg, new(DataDBService), server, make(chan birpc.ClientConnector, 1), shdChan, conMng, anz, srvDep) err := srv.Start() if err != nil { t.Fatal(err) @@ -130,7 +132,7 @@ func TestSessionSReload1(t *testing.T) { } rply := new(sessions.V1InitSessionReply) - srv.(*SessionService).sm.BiRPCv1InitiateSession(nil, args, rply) + srv.(*SessionService).sm.BiRPCv1InitiateSession(context.Background(), args, rply) err = srv.Shutdown() if err == nil || err != utils.ErrPartiallyExecuted { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrPartiallyExecuted, err) @@ -162,18 +164,22 @@ func TestSessionSReload2(t *testing.T) { close(chS.GetPrecacheChannel(utils.CacheSharedGroups)) close(chS.GetPrecacheChannel(utils.CacheTimings)) - internalChan := make(chan rpcclient.ClientConnector, 1) + internalChan := make(chan birpc.ClientConnector, 1) internalChan <- nil - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) cfg.StorDbCfg().Type = utils.MetaInternal - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - srv := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), shdChan, nil, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + srv := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) engine.NewConnManager(cfg, nil) srv.(*SessionService).sm = &sessions.SessionS{} @@ -185,7 +191,7 @@ func TestSessionSReload2(t *testing.T) { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err2) } cfg.SessionSCfg().Enabled = false - err := srv.Reload() + err = srv.Reload() if err != nil { t.Fatalf("\nExpecting ,\n Received <%+v>", err) } @@ -224,18 +230,22 @@ func TestSessionSReload3(t *testing.T) { close(chS.GetPrecacheChannel(utils.CacheSharedGroups)) close(chS.GetPrecacheChannel(utils.CacheTimings)) - internalChan := make(chan rpcclient.ClientConnector, 1) + internalChan := make(chan birpc.ClientConnector, 1) internalChan <- nil - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) cfg.StorDbCfg().Type = utils.MetaInternal - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - srv := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), shdChan, nil, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + srv := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) engine.NewConnManager(cfg, nil) srv.(*SessionService).sm = &sessions.SessionS{} diff --git a/services/sessions_test.go b/services/sessions_test.go index d567a770f..bdeff0654 100644 --- a/services/sessions_test.go +++ b/services/sessions_test.go @@ -22,13 +22,13 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/sessions" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestSessionSCoverage for cover testing @@ -41,16 +41,20 @@ func TestSessionSCoverage(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - internalChan := make(chan rpcclient.ClientConnector, 1) + internalChan := make(chan birpc.ClientConnector, 1) internalChan <- nil - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) cfg.StorDbCfg().Type = utils.MetaInternal - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - srv := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), shdChan, nil, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + srv := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) engine.NewConnManager(cfg, nil) if srv.IsRunning() { t.Errorf("Expected service to be down") @@ -60,7 +64,7 @@ func TestSessionSCoverage(t *testing.T) { dm: db, server: server, shdChan: shdChan, - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), connMgr: nil, anz: anz, srvDep: srvDep, diff --git a/services/sipagent_it_test.go b/services/sipagent_it_test.go index 5cd634533..2447616a2 100644 --- a/services/sipagent_it_test.go +++ b/services/sipagent_it_test.go @@ -27,12 +27,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestSIPAgentReload(t *testing.T) { @@ -47,21 +48,24 @@ func TestSIPAgentReload(t *testing.T) { shdChan := utils.NewSyncedChan() shdWg := new(sync.WaitGroup) chS := engine.NewCacheS(cfg, nil, nil) - - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} db := NewDataDBService(cfg, nil, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - sS := NewSessionService(cfg, db, server, make(chan rpcclient.ClientConnector, 1), + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + sS := NewSessionService(cfg, db, server, make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep) srv := NewSIPAgent(cfg, filterSChan, shdChan, nil, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(srv, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Fatal(err) } @@ -69,10 +73,11 @@ func TestSIPAgentReload(t *testing.T) { t.Fatalf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "sipagent_mysql"), - Section: config.SIPAgentJson, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "sipagent_mysql"), + Section: config.SIPAgentJson, + }, &reply); err != nil { t.Fatal(err) } else if reply != utils.OK { t.Fatalf("Expecting OK ,received %s", reply) @@ -87,7 +92,7 @@ func TestSIPAgentReload(t *testing.T) { if srvStart != utils.ErrServiceAlreadyRunning { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, srvStart) } - err := srv.Reload() + err = srv.Reload() if err != nil { t.Fatalf("\nExpecting ,\n Received <%+v>", err) } @@ -112,8 +117,12 @@ func TestSIPAgentReload2(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewSIPAgent(cfg, filterSChan, shdChan, nil, srvDep) if srv.IsRunning() { @@ -128,7 +137,7 @@ func TestSIPAgentReload2(t *testing.T) { }, }, } - err := srv.Start() + err = srv.Start() if err == nil || err.Error() != "no template with id: <>" { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", "no template with id: <>", err) } @@ -145,14 +154,18 @@ func TestSIPAgentReload3(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewSIPAgent(cfg, filterSChan, shdChan, nil, srvDep) if srv.IsRunning() { t.Fatalf("Expected service to be down") } - err := srv.Start() + err = srv.Start() if err != nil { t.Fatalf("\nExpecting <%+v>,\n Received <%+v>", nil, err) } diff --git a/services/sipagent_test.go b/services/sipagent_test.go index 664c14946..b93279563 100644 --- a/services/sipagent_test.go +++ b/services/sipagent_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/agents" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestSIPAgentCoverage for cover testing @@ -38,8 +38,12 @@ func TestSIPAgentCoverage(t *testing.T) { filterSChan <- nil shdChan := utils.NewSyncedChan() chS := engine.NewCacheS(cfg, nil, nil) - cacheSChan := make(chan rpcclient.ClientConnector, 1) - cacheSChan <- chS + cacheSrv, err := engine.NewService(chS) + if err != nil { + t.Fatal(err) + } + cacheSChan := make(chan birpc.ClientConnector, 1) + cacheSChan <- cacheSrv srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} srv := NewSIPAgent(cfg, filterSChan, shdChan, nil, srvDep) if srv.IsRunning() { diff --git a/services/stats.go b/services/stats.go index f5dac6fdf..ad6f5c82b 100644 --- a/services/stats.go +++ b/services/stats.go @@ -22,19 +22,19 @@ import ( "fmt" "sync" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewStatService returns the Stat Service func NewStatService(cfg *config.CGRConfig, dm *DataDBService, cacheS *engine.CacheS, filterSChan chan *engine.FilterS, - server *cores.Server, internalStatSChan chan rpcclient.ClientConnector, + server *cores.Server, internalStatSChan chan birpc.ClientConnector, connMgr *engine.ConnManager, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { return &StatService{ @@ -61,14 +61,13 @@ type StatService struct { connMgr *engine.ConnManager sts *engine.StatService - rpc *v1.StatSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the sercive start -func (sts *StatService) Start() (err error) { +func (sts *StatService) Start() error { if sts.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -91,12 +90,17 @@ func (sts *StatService) Start() (err error) { utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.StatS)) sts.sts.StartLoop() - sts.rpc = v1.NewStatSv1(sts.sts) - if !sts.cfg.DispatcherSCfg().Enabled { - sts.server.RpcRegister(sts.rpc) + srv, err := engine.NewService(v1.NewStatSv1(sts.sts)) + if err != nil { + return err } - sts.connChan <- sts.anz.GetInternalCodec(sts.rpc, utils.StatS) - return + if !sts.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + sts.server.RpcRegister(s) + } + } + sts.connChan <- sts.anz.GetInternalCodec(srv, utils.StatS) + return nil } // Reload handles the change of config @@ -114,7 +118,6 @@ func (sts *StatService) Shutdown() (err error) { defer sts.Unlock() sts.sts.Shutdown() sts.sts = nil - sts.rpc = nil <-sts.connChan return } diff --git a/services/stats_it_test.go b/services/stats_it_test.go index 18f02f963..10836909a 100644 --- a/services/stats_it_test.go +++ b/services/stats_it_test.go @@ -26,8 +26,8 @@ import ( "testing" "time" - "github.com/cgrates/rpcclient" - + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" @@ -56,13 +56,13 @@ func TestStatSReload(t *testing.T) { server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) - sS := NewStatService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) + sS := NewStatService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(tS, sS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -73,10 +73,11 @@ func TestStatSReload(t *testing.T) { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.STATS_JSON, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.STATS_JSON, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/stats_test.go b/services/stats_test.go index c4426805e..e5461ed70 100644 --- a/services/stats_test.go +++ b/services/stats_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestStatSCoverage for cover testing @@ -40,9 +40,9 @@ func TestStatSCoverage(t *testing.T) { chS := engine.NewCacheS(cfg, nil, nil) server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, srvDep) - sS := NewStatService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + sS := NewStatService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) if sS.IsRunning() { t.Errorf("Expected service to be down") } @@ -54,7 +54,7 @@ func TestStatSCoverage(t *testing.T) { server: server, connMgr: nil, sts: &engine.StatService{}, - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), anz: anz, srvDep: srvDep, } diff --git a/services/stordb_it_test.go b/services/stordb_it_test.go index d70b7aebc..a1e0058db 100644 --- a/services/stordb_it_test.go +++ b/services/stordb_it_test.go @@ -26,12 +26,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestStorDBReload(t *testing.T) { @@ -50,19 +51,19 @@ func TestStorDBReload(t *testing.T) { db := NewDataDBService(cfg, nil, srvDep) cfg.StorDbCfg().Password = "CGRateS.org" stordb := NewStorDBService(cfg, srvDep) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - chrS := NewChargerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) - schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) + chrS := NewChargerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) + schS := NewSchedulerService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep) ralS := NewRalService(cfg, chS, server, - make(chan rpcclient.ClientConnector, 1), - make(chan rpcclient.ClientConnector, 1), + make(chan birpc.ClientConnector, 1), + make(chan birpc.ClientConnector, 1), shdChan, nil, anz, srvDep, filterSChan) - cdrsRPC := make(chan rpcclient.ClientConnector, 1) + cdrsRPC := make(chan birpc.ClientConnector, 1) cdrS := NewCDRServer(cfg, db, stordb, filterSChan, server, cdrsRPC, nil, anz, srvDep) srvMngr.AddServices(cdrS, ralS, schS, chrS, NewLoaderService(cfg, db, filterSChan, server, - make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db, stordb) + make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db, stordb) if err := engine.InitStorDb(cfg); err != nil { t.Fatal(err) } @@ -80,10 +81,11 @@ func TestStorDBReload(t *testing.T) { cfg.RalsCfg().Enabled = true var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.CDRS_JSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.CDRS_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) @@ -107,10 +109,11 @@ func TestStorDBReload(t *testing.T) { } time.Sleep(10 * time.Millisecond) cfg.StorDbCfg().Password = "" - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.STORDB_JSN, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.STORDB_JSN, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/thresholds.go b/services/thresholds.go index 130c968d0..cf3fd722a 100644 --- a/services/thresholds.go +++ b/services/thresholds.go @@ -22,19 +22,19 @@ import ( "fmt" "sync" + "github.com/cgrates/birpc" v1 "github.com/cgrates/cgrates/apier/v1" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // NewThresholdService returns the Threshold Service func NewThresholdService(cfg *config.CGRConfig, dm *DataDBService, cacheS *engine.CacheS, filterSChan chan *engine.FilterS, - server *cores.Server, internalThresholdSChan chan rpcclient.ClientConnector, + server *cores.Server, internalThresholdSChan chan birpc.ClientConnector, anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { return &ThresholdService{ connChan: internalThresholdSChan, @@ -58,14 +58,13 @@ type ThresholdService struct { server *cores.Server thrs *engine.ThresholdService - rpc *v1.ThresholdSv1 - connChan chan rpcclient.ClientConnector + connChan chan birpc.ClientConnector anz *AnalyzerService srvDep map[string]*sync.WaitGroup } // Start should handle the sercive start -func (thrs *ThresholdService) Start() (err error) { +func (thrs *ThresholdService) Start() error { if thrs.IsRunning() { return utils.ErrServiceAlreadyRunning } @@ -87,12 +86,17 @@ func (thrs *ThresholdService) Start() (err error) { utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.ThresholdS)) thrs.thrs.StartLoop() - thrs.rpc = v1.NewThresholdSv1(thrs.thrs) - if !thrs.cfg.DispatcherSCfg().Enabled { - thrs.server.RpcRegister(thrs.rpc) + srv, err := engine.NewService(v1.NewThresholdSv1(thrs.thrs)) + if err != nil { + return err } - thrs.connChan <- thrs.anz.GetInternalCodec(thrs.rpc, utils.ThresholdS) - return + if !thrs.cfg.DispatcherSCfg().Enabled { + for _, s := range srv { + thrs.server.RpcRegister(s) + } + } + thrs.connChan <- thrs.anz.GetInternalCodec(srv, utils.ThresholdS) + return nil } // Reload handles the change of config @@ -110,7 +114,6 @@ func (thrs *ThresholdService) Shutdown() (err error) { defer thrs.Unlock() thrs.thrs.Shutdown() thrs.thrs = nil - thrs.rpc = nil <-thrs.connChan return } diff --git a/services/thresholds_it_test.go b/services/thresholds_it_test.go index 59f2caecf..e9c9c1f7b 100644 --- a/services/thresholds_it_test.go +++ b/services/thresholds_it_test.go @@ -27,12 +27,13 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/servmanager" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) func TestThresholdSReload(t *testing.T) { @@ -52,12 +53,12 @@ func TestThresholdSReload(t *testing.T) { server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(tS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -68,10 +69,11 @@ func TestThresholdSReload(t *testing.T) { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.THRESHOLDS_JSON, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.THRESHOLDS_JSON, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) @@ -120,12 +122,12 @@ func TestThresholdSReload2(t *testing.T) { server := cores.NewServer(nil) srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) engine.NewConnManager(cfg, nil) srvMngr.AddServices(tS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) + NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db) if err := srvMngr.StartServices(); err != nil { t.Error(err) } @@ -136,10 +138,11 @@ func TestThresholdSReload2(t *testing.T) { t.Errorf("Expected service to be down") } var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.THRESHOLDS_JSON, - }, &reply); err != nil { + if err := cfg.V1ReloadConfig(context.Background(), + &config.ReloadArgs{ + Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), + Section: config.THRESHOLDS_JSON, + }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expecting OK ,received %s", reply) diff --git a/services/thresholds_test.go b/services/thresholds_test.go index 7d9ea942a..067f327f2 100644 --- a/services/thresholds_test.go +++ b/services/thresholds_test.go @@ -22,11 +22,11 @@ import ( "sync" "testing" + "github.com/cgrates/birpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/cores" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) // TestThresholdSCoverage for cover testing @@ -38,9 +38,9 @@ func TestThresholdSCoverage(t *testing.T) { chS := engine.NewCacheS(cfg, nil, nil) server := cores.NewServer(nil) srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) + anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep) db := NewDataDBService(cfg, nil, srvDep) - tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan rpcclient.ClientConnector, 1), anz, srvDep) + tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep) if tS.IsRunning() { t.Errorf("Expected service to be down") } @@ -52,7 +52,7 @@ func TestThresholdSCoverage(t *testing.T) { filterSChan: filterSChan, server: server, thrs: thrs1, - connChan: make(chan rpcclient.ClientConnector, 1), + connChan: make(chan birpc.ClientConnector, 1), anz: anz, srvDep: srvDep, } diff --git a/servmanager/servmanager.go b/servmanager/servmanager.go index 45a622dfc..0f1328452 100644 --- a/servmanager/servmanager.go +++ b/servmanager/servmanager.go @@ -25,6 +25,7 @@ import ( "strings" "sync" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -55,7 +56,7 @@ type ServiceManager struct { } // Call . -func (srvMngr *ServiceManager) Call(serviceMethod string, args any, reply any) error { +func (srvMngr *ServiceManager) Call(ctx *context.Context, serviceMethod string, args any, reply any) error { parts := strings.Split(serviceMethod, ".") if len(parts) != 2 { return rpcclient.ErrUnsupporteServiceMethod @@ -87,7 +88,7 @@ type ArgStartService struct { } // V1StartService starts a service with ID -func (srvMngr *ServiceManager) V1StartService(args ArgStartService, reply *string) (err error) { +func (srvMngr *ServiceManager) V1StartService(ctx *context.Context, args ArgStartService, reply *string) (err error) { switch args.ServiceID { case utils.MetaScheduler: // stop the service using the config @@ -106,7 +107,7 @@ func (srvMngr *ServiceManager) V1StartService(args ArgStartService, reply *strin } // V1StopService shuts-down a service with ID -func (srvMngr *ServiceManager) V1StopService(args ArgStartService, reply *string) (err error) { +func (srvMngr *ServiceManager) V1StopService(ctx *context.Context, args ArgStartService, reply *string) (err error) { switch args.ServiceID { case utils.MetaScheduler: // stop the service using the config @@ -125,7 +126,7 @@ func (srvMngr *ServiceManager) V1StopService(args ArgStartService, reply *string } // V1ServiceStatus returns the service status -func (srvMngr *ServiceManager) V1ServiceStatus(args ArgStartService, reply *string) error { +func (srvMngr *ServiceManager) V1ServiceStatus(ctx *context.Context, args ArgStartService, reply *string) error { srvMngr.RLock() defer srvMngr.RUnlock() var running bool diff --git a/sessions/lib_test.go b/sessions/lib_test.go index ea157fa8c..761019364 100644 --- a/sessions/lib_test.go +++ b/sessions/lib_test.go @@ -21,26 +21,26 @@ package sessions import ( "errors" "flag" - "net/rpc" - "net/rpc/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" ) var ( dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here") - waitRater = flag.Int("wait_rater", 100, "Number of miliseconds to wait for rater to start and cache") + waitRater = flag.Int("wait_rater", 500, "Number of miliseconds to wait for rater to start and cache") encoding = flag.String("rpc", utils.MetaJSON, "what encoding whould be uused for rpc comunication") dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)") ) -func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) { +func newRPCClient(cfg *config.ListenCfg) (c *birpc.Client, err error) { switch *encoding { case utils.MetaJSON: return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen) case utils.MetaGOB: - return rpc.Dial(utils.TCP, cfg.RPCGOBListen) + return birpc.Dial(utils.TCP, cfg.RPCGOBListen) default: return nil, errors.New("UNSUPPORTED_RPC") } diff --git a/sessions/libsessions.go b/sessions/libsessions.go index fcdf2fc4e..d4e56e40e 100644 --- a/sessions/libsessions.go +++ b/sessions/libsessions.go @@ -23,10 +23,10 @@ import ( "strings" "time" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" jwt "github.com/dgrijalva/jwt-go" ) @@ -41,21 +41,14 @@ var authReqs = engine.MapEvent{ utils.MetaPseudoPrepaid: struct{}{}, } -// BiRPClient is the interface implemented by Agents which are able to +// BiRPCClient is the interface implemented by Agents which are able to // communicate bidirectionally with SessionS and remote Communication Switch -type BiRPClient interface { - rpcclient.BiRPCConector - V1DisconnectSession(args utils.AttrDisconnectSession, reply *string) (err error) - V1GetActiveSessionIDs(ignParam string, sessionIDs *[]*SessionID) (err error) - V1ReAuthorize(originID string, reply *string) (err error) - V1DisconnectPeer(args *utils.DPRArgs, reply *string) (err error) - V1WarnDisconnect(args map[string]any, reply *string) (err error) - - BiRPCv1DisconnectSession(clnt rpcclient.ClientConnector, args utils.AttrDisconnectSession, reply *string) (err error) - BiRPCv1GetActiveSessionIDs(clnt rpcclient.ClientConnector, ignParam string, sessionIDs *[]*SessionID) (err error) - BiRPCv1ReAuthorize(clnt rpcclient.ClientConnector, originID string, reply *string) (err error) - BiRPCv1DisconnectPeer(clnt rpcclient.ClientConnector, args *utils.DPRArgs, reply *string) (err error) - BiRPCv1WarnDisconnect(clnt rpcclient.ClientConnector, args map[string]any, reply *string) (err error) +type BiRPCClient interface { + V1DisconnectSession(ctx *context.Context, args utils.AttrDisconnectSession, reply *string) (err error) + V1GetActiveSessionIDs(ctx *context.Context, ignParam string, sessionIDs *[]*SessionID) (err error) + V1ReAuthorize(ctx *context.Context, originID string, reply *string) (err error) + V1DisconnectPeer(ctx *context.Context, args *utils.DPRArgs, reply *string) (err error) + V1WarnDisconnect(ctx *context.Context, args map[string]any, reply *string) (err error) } // GetSetCGRID will populate the CGRID key if not present and return it diff --git a/sessions/sessions.go b/sessions/sessions.go index ede03729d..e07fb4b50 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -27,13 +27,13 @@ import ( "sync" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/guardian" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" ) var ( @@ -51,7 +51,7 @@ func NewSessionS(cgrCfg *config.CGRConfig, cgrCfg: cgrCfg, dm: dm, connMgr: connMgr, - biJClnts: make(map[rpcclient.ClientConnector]string), + biJClnts: make(map[birpc.ClientConnector]string), biJIDs: make(map[string]*biJClient), aSessions: make(map[string]*Session), aSessionsIdx: make(map[string]map[string]map[string]utils.StringSet), @@ -64,8 +64,8 @@ func NewSessionS(cgrCfg *config.CGRConfig, // biJClient contains info we need to reach back a bidirectional json client type biJClient struct { - conn rpcclient.ClientConnector // connection towards BiJ client - proto float64 // client protocol version + conn birpc.ClientConnector // connection towards BiJ client + proto float64 // client protocol version } // SessionS represents the session service @@ -74,9 +74,9 @@ type SessionS struct { dm *engine.DataManager connMgr *engine.ConnManager - biJMux sync.RWMutex // mux protecting BI-JSON connections - biJClnts map[rpcclient.ClientConnector]string // index BiJSONConnection so we can sync them later - biJIDs map[string]*biJClient // identifiers of bidirectional JSON conns, used to call RPC based on connIDs + biJMux sync.RWMutex // mux protecting BI-JSON connections + biJClnts map[birpc.ClientConnector]string // index BiJSONConnection so we can sync them later + biJIDs map[string]*biJClient // identifiers of bidirectional JSON conns, used to call RPC based on connIDs aSsMux sync.RWMutex // protects aSessions aSessions map[string]*Session // group sessions per sessionId @@ -124,8 +124,8 @@ func (sS *SessionS) Shutdown() (err error) { return } -// OnBiJSONConnect is called by rpc2.Client on each new connection -func (sS *SessionS) OnBiJSONConnect(c *rpc2.Client) { +// OnBiJSONConnect handles new client connections. +func (sS *SessionS) OnBiJSONConnect(c birpc.ClientConnector) { nodeID := utils.UUIDSha1Prefix() // connection identifier, should be later updated as login procedure sS.biJMux.Lock() sS.biJClnts[c] = nodeID @@ -135,8 +135,8 @@ func (sS *SessionS) OnBiJSONConnect(c *rpc2.Client) { sS.biJMux.Unlock() } -// OnBiJSONDisconnect is called by rpc2.Client on each client disconnection -func (sS *SessionS) OnBiJSONDisconnect(c *rpc2.Client) { +// OnBiJSONDisconnect handles client disconnects. +func (sS *SessionS) OnBiJSONDisconnect(c birpc.ClientConnector) { sS.biJMux.Lock() if nodeID, has := sS.biJClnts[c]; has { delete(sS.biJClnts, c) @@ -146,7 +146,7 @@ func (sS *SessionS) OnBiJSONDisconnect(c *rpc2.Client) { } // RegisterIntBiJConn is called on internal BiJ connection towards SessionS -func (sS *SessionS) RegisterIntBiJConn(c rpcclient.ClientConnector, nodeID string) { +func (sS *SessionS) RegisterIntBiJConn(c birpc.ClientConnector, nodeID string) { if nodeID == utils.EmptyString { nodeID = sS.cgrCfg.GeneralCfg().NodeID } @@ -170,7 +170,7 @@ func (sS *SessionS) biJClnt(connID string) (clnt *biJClient) { } // biJClnt returns connection ID based on bidirectional connection received -func (sS *SessionS) biJClntID(c rpcclient.ClientConnector) (clntConnID string) { +func (sS *SessionS) biJClntID(c birpc.ClientConnector) (clntConnID string) { if c == nil { return } @@ -373,7 +373,7 @@ func (sS *SessionS) forceSTerminate(s *Session, extraUsage time.Duration, tUsage argsProc.Flags = append(argsProc.Flags, utils.MetaRALs) } argsProc.SetCloneable(true) - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().CDRsConns, nil, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().CDRsConns, utils.CDRsV1ProcessEvent, argsProc, &reply); err != nil { utils.Logger.Warning( fmt.Sprintf( @@ -397,7 +397,7 @@ func (sS *SessionS) forceSTerminate(s *Session, extraUsage time.Duration, tUsage cgrEv.APIOpts[utils.OptsResourcesUsageID] = s.ResourceID cgrEv.APIOpts[utils.OptsResourcesUnits] = 1 cgrEv.SetCloneable(true) - if err := sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ResSConns, nil, + if err := sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().ResSConns, utils.ResourceSv1ReleaseResources, cgrEv, &reply); err != nil { utils.Logger.Warning( @@ -409,7 +409,7 @@ func (sS *SessionS) forceSTerminate(s *Session, extraUsage time.Duration, tUsage if clntConn := sS.biJClnt(s.ClientConnID); clntConn != nil { go func() { var rply string - if err := clntConn.conn.Call( + if err := clntConn.conn.Call(context.TODO(), utils.SessionSv1DisconnectSession, utils.AttrDisconnectSession{ EventStart: s.EventStart, @@ -451,7 +451,7 @@ func (sS *SessionS) debitSession(s *Session, sRunIdx int, dur time.Duration, sr.CD.DurationIndex += rDur cd := sr.CD.Clone() cc := new(engine.CallCost) - err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, + err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().RALsConns, utils.ResponderMaxDebit, &engine.CallDescriptorWithAPIOpts{ CallDescriptor: cd, @@ -463,7 +463,7 @@ func (sS *SessionS) debitSession(s *Session, sRunIdx int, dur time.Duration, sr.Event.GetStringIgnoreErrors(utils.RequestType) == utils.MetaDynaprepaid { var reply string // execute the actionPlan configured in Scheduler - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().SchedulerConns, nil, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().SchedulerConns, utils.SchedulerSv1ExecuteActionPlans, &utils.AttrsExecuteActionPlans{ ActionPlanIDs: sS.cgrCfg.SchedulerCfg().DynaprepaidActionPlans, Tenant: cd.Tenant, AccountID: cd.Account}, @@ -471,7 +471,7 @@ func (sS *SessionS) debitSession(s *Session, sRunIdx int, dur time.Duration, return } // execute again the MaxDebit operation - err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, + err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().RALsConns, utils.ResponderMaxDebit, &engine.CallDescriptorWithAPIOpts{ CallDescriptor: cd, @@ -673,7 +673,8 @@ func (sS *SessionS) refundSession(s *Session, sRunIdx int, rUsage time.Duration) Increments: incrmts, } var acnt engine.Account - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, utils.ResponderRefundIncrements, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().RALsConns, + utils.ResponderRefundIncrements, &engine.CallDescriptorWithAPIOpts{ CallDescriptor: cd, APIOpts: s.OptsStart, @@ -709,7 +710,8 @@ func (sS *SessionS) storeSCost(s *Session, sRunIdx int) (err error) { } var reply string // use the v1 because it doesn't do rounding refund - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().CDRsConns, nil, utils.CDRsV1StoreSessionCost, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().CDRsConns, + utils.CDRsV1StoreSessionCost, argSmCost, &reply); err != nil && err == utils.ErrExists { utils.Logger.Warning( fmt.Sprintf("<%s> refunding session: <%s> error: <%s>", @@ -746,7 +748,7 @@ func (sS *SessionS) roundCost(s *Session, sRunIdx int) (err error) { cd.RunID = runID cd.Increments = roundIncrements response := new(engine.Account) - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().RALsConns, utils.ResponderRefundRounding, &engine.CallDescriptorWithAPIOpts{CallDescriptor: cd}, response); err != nil { @@ -776,7 +778,7 @@ func (sS *SessionS) disconnectSession(s *Session, rsn string) (err error) { servMethod = "SMGClientV1.DisconnectSession" } var rply string - if err = clnt.conn.Call(servMethod, + if err = clnt.conn.Call(context.TODO(), servMethod, utils.AttrDisconnectSession{ EventStart: s.EventStart, Reason: rsn}, &rply); err != nil { @@ -797,7 +799,7 @@ func (sS *SessionS) warnSession(connID string, ev map[string]any) (err error) { utils.SessionSv1WarnDisconnect, connID) } var rply string - if err = clnt.conn.Call(utils.SessionSv1WarnDisconnect, + if err = clnt.conn.Call(context.TODO(), utils.SessionSv1WarnDisconnect, ev, &rply); err != nil { if err != utils.ErrNotImplemented { utils.Logger.Warning(fmt.Sprintf("<%s> failed to warn session: <%s>, err: <%s>", @@ -825,7 +827,7 @@ func (sS *SessionS) replicateSessions(cgrID string, psv bool, connIDs []string) for _, s := range ss { sCln := s.Clone() var rply string - if err := sS.connMgr.Call(connIDs, nil, + if err := sS.connMgr.Call(context.TODO(), connIDs, utils.SessionSv1SetPassiveSession, sCln, &rply); err != nil { utils.Logger.Warning( @@ -1232,7 +1234,7 @@ func (sS *SessionS) processChargerS(cgrEv *utils.CGREvent) (chrgrs []*engine.Chr if x, ok := engine.Cache.Get(utils.CacheEventCharges, cgrEv.ID); ok && x != nil { return x.([]*engine.ChrgSProcessEventReply), nil } - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ChargerSConns, nil, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().ChargerSConns, utils.ChargerSv1ProcessEvent, cgrEv, &chrgrs); err != nil { err = utils.NewErrChargerS(err) } @@ -1378,7 +1380,7 @@ func (sS *SessionS) syncSessions() { errChan := make(chan error) go func() { var queriedSessionIDs []*SessionID - if err := clnt.conn.Call(utils.SessionSv1GetActiveSessionIDs, + if err := clnt.conn.Call(context.TODO(), utils.SessionSv1GetActiveSessionIDs, utils.EmptyString, &queriedSessionIDs); err != nil { errChan <- err } @@ -1466,7 +1468,7 @@ func (sS *SessionS) authEvent(cgrEv *utils.CGREvent, forceDuration bool) (usage if !authReqs.HasField( sr.Event.GetStringIgnoreErrors(utils.RequestType)) { rplyMaxUsage = eventUsage - } else if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, + } else if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().RALsConns, utils.ResponderGetMaxSessionTime, &engine.CallDescriptorWithAPIOpts{ CallDescriptor: sr.CD, @@ -1594,7 +1596,8 @@ func (sS *SessionS) endSession(s *Session, tUsage, lastUsage *time.Duration, sr.CD.TimeEnd = sr.CD.TimeStart.Add(notCharged) sr.CD.DurationIndex += notCharged cc := new(engine.CallCost) - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, utils.ResponderDebit, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().RALsConns, + utils.ResponderDebit, &engine.CallDescriptorWithAPIOpts{ CallDescriptor: sr.CD, APIOpts: s.OptsStart, @@ -1691,19 +1694,8 @@ func (sS *SessionS) chargeEvent(cgrEv *utils.CGREvent, forceDuration bool) (maxU // APIs start here -// Call is part of RpcClientConnection interface -func (sS *SessionS) Call(serviceMethod string, args any, reply any) error { - return sS.CallBiRPC(nil, serviceMethod, args, reply) -} - -// CallBiRPC is part of utils.BiRPCServer interface to help internal connections do calls over rpcclient.ClientConnector interface -func (sS *SessionS) CallBiRPC(clnt rpcclient.ClientConnector, - serviceMethod string, args any, reply any) error { - return utils.BiRPCCall(sS, clnt, serviceMethod, args, reply) -} - // BiRPCv1GetActiveSessions returns the list of active sessions based on filter -func (sS *SessionS) BiRPCv1GetActiveSessions(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1GetActiveSessions(ctx *context.Context, args *utils.SessionFilter, reply *[]*ExternalSession) (err error) { if args == nil { //protection in case on nil args = &utils.SessionFilter{} @@ -1717,7 +1709,7 @@ func (sS *SessionS) BiRPCv1GetActiveSessions(clnt rpcclient.ClientConnector, } // BiRPCv1GetActiveSessionsCount counts the active sessions -func (sS *SessionS) BiRPCv1GetActiveSessionsCount(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1GetActiveSessionsCount(ctx *context.Context, args *utils.SessionFilter, reply *int) error { if args == nil { //protection in case on nil args = &utils.SessionFilter{} @@ -1727,7 +1719,7 @@ func (sS *SessionS) BiRPCv1GetActiveSessionsCount(clnt rpcclient.ClientConnector } // BiRPCv1GetPassiveSessions returns the passive sessions handled by SessionS -func (sS *SessionS) BiRPCv1GetPassiveSessions(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1GetPassiveSessions(ctx *context.Context, args *utils.SessionFilter, reply *[]*ExternalSession) error { if args == nil { //protection in case on nil args = &utils.SessionFilter{} @@ -1741,7 +1733,7 @@ func (sS *SessionS) BiRPCv1GetPassiveSessions(clnt rpcclient.ClientConnector, } // BiRPCv1GetPassiveSessionsCount counts the passive sessions handled by the system -func (sS *SessionS) BiRPCv1GetPassiveSessionsCount(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1GetPassiveSessionsCount(ctx *context.Context, args *utils.SessionFilter, reply *int) error { if args == nil { //protection in case on nil args = &utils.SessionFilter{} @@ -1751,7 +1743,7 @@ func (sS *SessionS) BiRPCv1GetPassiveSessionsCount(clnt rpcclient.ClientConnecto } // BiRPCv1SetPassiveSession used for replicating Sessions -func (sS *SessionS) BiRPCv1SetPassiveSession(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1SetPassiveSession(ctx *context.Context, s *Session, reply *string) (err error) { if s.CGRID == "" { return utils.NewErrMandatoryIeMissing(utils.CGRID) @@ -1785,7 +1777,7 @@ type ArgsReplicateSessions struct { // BiRPCv1ReplicateSessions will replicate active sessions to either args.Connections or the internal configured ones // args.Filter is used to filter the sessions which are replicated, CGRID is the only one possible for now -func (sS *SessionS) BiRPCv1ReplicateSessions(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1ReplicateSessions(ctx *context.Context, args ArgsReplicateSessions, reply *string) (err error) { sS.replicateSessions(args.CGRID, args.Passive, args.ConnIDs) *reply = utils.OK @@ -1945,7 +1937,7 @@ func (v1AuthReply *V1AuthorizeReply) AsNavigableMap() map[string]*utils.DataNode } // BiRPCv1AuthorizeEvent performs authorization for CGREvent based on specific components -func (sS *SessionS) BiRPCv1AuthorizeEvent(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1AuthorizeEvent(ctx *context.Context, args *V1AuthorizeArgs, authReply *V1AuthorizeReply) (err error) { if args.CGREvent == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) @@ -2024,7 +2016,7 @@ func (sS *SessionS) BiRPCv1AuthorizeEvent(clnt rpcclient.ClientConnector, } args.CGREvent.APIOpts[utils.OptsResourcesUsageID] = originID args.CGREvent.APIOpts[utils.OptsResourcesUnits] = 1 - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ResSConns, nil, utils.ResourceSv1AuthorizeResources, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().ResSConns, utils.ResourceSv1AuthorizeResources, args.CGREvent, &allocMsg); err != nil { return utils.NewErrResourceS(err) } @@ -2079,10 +2071,10 @@ type V1AuthorizeReplyWithDigest struct { // BiRPCv1AuthorizeEventWithDigest performs authorization for CGREvent based on specific components // returning one level fields instead of multiple ones returned by BiRPCv1AuthorizeEvent -func (sS *SessionS) BiRPCv1AuthorizeEventWithDigest(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1AuthorizeEventWithDigest(ctx *context.Context, args *V1AuthorizeArgs, authReply *V1AuthorizeReplyWithDigest) (err error) { var initAuthRply V1AuthorizeReply - if err = sS.BiRPCv1AuthorizeEvent(clnt, args, &initAuthRply); err != nil { + if err = sS.BiRPCv1AuthorizeEvent(ctx, args, &initAuthRply); err != nil { return } if args.GetAttributes && initAuthRply.Attributes != nil { @@ -2232,7 +2224,7 @@ func (v1Rply *V1InitSessionReply) AsNavigableMap() map[string]*utils.DataNode { } // BiRPCv1InitiateSession initiates a new session -func (sS *SessionS) BiRPCv1InitiateSession(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1InitiateSession(ctx *context.Context, args *V1InitSessionArgs, rply *V1InitSessionReply) (err error) { if args.CGREvent == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) @@ -2294,7 +2286,7 @@ func (sS *SessionS) BiRPCv1InitiateSession(clnt rpcclient.ClientConnector, args.CGREvent.APIOpts[utils.OptsResourcesUsageID] = originID args.CGREvent.APIOpts[utils.OptsResourcesUnits] = 1 var allocMessage string - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ResSConns, nil, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().ResSConns, utils.ResourceSv1AllocateResources, args.CGREvent, &allocMessage); err != nil { return utils.NewErrResourceS(err) } @@ -2309,7 +2301,7 @@ func (sS *SessionS) BiRPCv1InitiateSession(clnt rpcclient.ClientConnector, return utils.NewErrRALs(err) } } - s, err := sS.initSession(args.CGREvent, sS.biJClntID(clnt), originID, dbtItvl, + s, err := sS.initSession(args.CGREvent, sS.biJClntID(ctx.Client), originID, dbtItvl, false, args.ForceDuration) if err != nil { return err @@ -2373,10 +2365,10 @@ type V1InitReplyWithDigest struct { } // BiRPCv1InitiateSessionWithDigest returns the formated result of InitiateSession -func (sS *SessionS) BiRPCv1InitiateSessionWithDigest(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1InitiateSessionWithDigest(ctx *context.Context, args *V1InitSessionArgs, initReply *V1InitReplyWithDigest) (err error) { var initSessionRply V1InitSessionReply - if err = sS.BiRPCv1InitiateSession(clnt, args, &initSessionRply); err != nil { + if err = sS.BiRPCv1InitiateSession(ctx, args, &initSessionRply); err != nil { return } @@ -2469,7 +2461,7 @@ func (v1Rply *V1UpdateSessionReply) AsNavigableMap() map[string]*utils.DataNode } // BiRPCv1UpdateSession updates an existing session, returning the duration which the session can still last -func (sS *SessionS) BiRPCv1UpdateSession(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1UpdateSession(ctx *context.Context, args *V1UpdateSessionArgs, rply *V1UpdateSessionReply) (err error) { if args.CGREvent == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) @@ -2532,7 +2524,7 @@ func (sS *SessionS) BiRPCv1UpdateSession(clnt rpcclient.ClientConnector, ev.GetStringIgnoreErrors(utils.OriginID), ev.GetStringIgnoreErrors(utils.OriginHost)) if s == nil { - if s, err = sS.initSession(args.CGREvent, sS.biJClntID(clnt), ev.GetStringIgnoreErrors(utils.OriginID), + if s, err = sS.initSession(args.CGREvent, sS.biJClntID(ctx.Client), ev.GetStringIgnoreErrors(utils.OriginID), dbtItvl, false, args.ForceDuration); err != nil { return err } @@ -2610,7 +2602,7 @@ func (args *V1TerminateSessionArgs) ParseFlags(flags, sep string) { } // BiRPCv1TerminateSession will stop debit loops as well as release any used resources -func (sS *SessionS) BiRPCv1TerminateSession(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1TerminateSession(ctx *context.Context, args *V1TerminateSessionArgs, rply *string) (err error) { if args.CGREvent == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) @@ -2677,7 +2669,7 @@ func (sS *SessionS) BiRPCv1TerminateSession(clnt rpcclient.ClientConnector, continue } isMsg = true - if s, err = sS.initSession(args.CGREvent, sS.biJClntID(clnt), ev.GetStringIgnoreErrors(utils.OriginID), + if s, err = sS.initSession(args.CGREvent, sS.biJClntID(ctx.Client), ev.GetStringIgnoreErrors(utils.OriginID), dbtItvl, isMsg, args.ForceDuration); err != nil { return utils.NewErrRALs(err) } @@ -2713,7 +2705,7 @@ func (sS *SessionS) BiRPCv1TerminateSession(clnt rpcclient.ClientConnector, } args.CGREvent.APIOpts[utils.OptsResourcesUsageID] = originID // same ID should be accepted by first group since the previous resource should be expired args.CGREvent.APIOpts[utils.OptsResourcesUnits] = 1 - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ResSConns, nil, utils.ResourceSv1ReleaseResources, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().ResSConns, utils.ResourceSv1ReleaseResources, args.CGREvent, &reply); err != nil { return utils.NewErrResourceS(err) } @@ -2746,7 +2738,7 @@ func (sS *SessionS) BiRPCv1TerminateSession(clnt rpcclient.ClientConnector, } // BiRPCv1ProcessCDR sends the CDR to CDRs -func (sS *SessionS) BiRPCv1ProcessCDR(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1ProcessCDR(ctx *context.Context, cgrEv *utils.CGREvent, rply *string) (err error) { if cgrEv.Event == nil { return utils.NewErrMandatoryIeMissing(utils.Event) @@ -2934,7 +2926,7 @@ func (v1Rply *V1ProcessMessageReply) AsNavigableMap() map[string]*utils.DataNode } // BiRPCv1ProcessMessage processes one event with the right subsystems based on arguments received -func (sS *SessionS) BiRPCv1ProcessMessage(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1ProcessMessage(ctx *context.Context, args *V1ProcessMessageArgs, rply *V1ProcessMessageReply) (err error) { if args.CGREvent == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) @@ -2995,7 +2987,7 @@ func (sS *SessionS) BiRPCv1ProcessMessage(clnt rpcclient.ClientConnector, args.CGREvent.APIOpts[utils.OptsResourcesUsageID] = originID args.CGREvent.APIOpts[utils.OptsResourcesUnits] = 1 var allocMessage string - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ResSConns, nil, utils.ResourceSv1AllocateResources, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().ResSConns, utils.ResourceSv1AllocateResources, args.CGREvent, &allocMessage); err != nil { return utils.NewErrResourceS(err) } @@ -3145,7 +3137,7 @@ func (v1Rply *V1ProcessEventReply) AsNavigableMap() map[string]*utils.DataNode { } // BiRPCv1ProcessEvent processes one event with the right subsystems based on arguments received -func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1ProcessEvent(ctx *context.Context, args *V1ProcessEventArgs, rply *V1ProcessEventReply) (err error) { if args.CGREvent == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) @@ -3358,7 +3350,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, //check for subflags and convert them into utils.FlagsWithParams switch { case resOpt.Has(utils.MetaAuthorize): - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ResSConns, nil, utils.ResourceSv1AuthorizeResources, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().ResSConns, utils.ResourceSv1AuthorizeResources, args.CGREvent, &resMessage); err != nil { if blockError { return utils.NewErrResourceS(err) @@ -3369,7 +3361,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, withErrors = true } case resOpt.Has(utils.MetaAllocate): - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ResSConns, nil, utils.ResourceSv1AllocateResources, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().ResSConns, utils.ResourceSv1AllocateResources, args.CGREvent, &resMessage); err != nil { if blockError { return utils.NewErrResourceS(err) @@ -3380,7 +3372,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, withErrors = true } case resOpt.Has(utils.MetaRelease): - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ResSConns, nil, utils.ResourceSv1ReleaseResources, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().ResSConns, utils.ResourceSv1ReleaseResources, args.CGREvent, &resMessage); err != nil { if blockError { return utils.NewErrResourceS(err) @@ -3436,7 +3428,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, ForceDuration: ralsOpts.Has(utils.MetaFD), } var cc engine.CallCost - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().RALsConns, utils.ResponderGetCost, &engine.CallDescriptorWithAPIOpts{ CallDescriptor: cd, @@ -3465,7 +3457,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, return utils.NewErrRALs(err) } } - s, err := sS.initSession(args.CGREvent, sS.biJClntID(clnt), originID, dbtItvl, false, + s, err := sS.initSession(args.CGREvent, sS.biJClntID(ctx.Client), originID, dbtItvl, false, ralsOpts.Has(utils.MetaFD)) if err != nil { return err @@ -3494,7 +3486,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, ev.GetStringIgnoreErrors(utils.OriginID), ev.GetStringIgnoreErrors(utils.OriginHost)) if s == nil { - if s, err = sS.initSession(args.CGREvent, sS.biJClntID(clnt), ev.GetStringIgnoreErrors(utils.OriginID), + if s, err = sS.initSession(args.CGREvent, sS.biJClntID(ctx.Client), ev.GetStringIgnoreErrors(utils.OriginID), dbtItvl, false, ralsOpts.Has(utils.MetaFD)); err != nil { return err } @@ -3516,7 +3508,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.ClientConnector, ev.GetStringIgnoreErrors(utils.OriginID), ev.GetStringIgnoreErrors(utils.OriginHost)) if s == nil { - if s, err = sS.initSession(args.CGREvent, sS.biJClntID(clnt), ev.GetStringIgnoreErrors(utils.OriginID), + if s, err = sS.initSession(args.CGREvent, sS.biJClntID(ctx.Client), ev.GetStringIgnoreErrors(utils.OriginID), dbtItvl, false, ralsOpts.Has(utils.MetaFD)); err != nil { return err } @@ -3567,7 +3559,7 @@ type V1GetCostReply struct { } // BiRPCv1GetCost processes one event with the right subsystems based on arguments received -func (sS *SessionS) BiRPCv1GetCost(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1GetCost(ctx *context.Context, args *V1ProcessEventArgs, rply *V1GetCostReply) (err error) { if args.CGREvent == nil { return utils.NewErrMandatoryIeMissing(utils.CGREventString) @@ -3645,7 +3637,7 @@ func (sS *SessionS) BiRPCv1GetCost(clnt rpcclient.ClientConnector, TimeEnd: startTime.Add(me.GetDurationIgnoreErrors(utils.Usage)), } var cc engine.CallCost - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RALsConns, nil, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().RALsConns, utils.ResponderGetCost, &engine.CallDescriptorWithAPIOpts{ CallDescriptor: cd, @@ -3660,7 +3652,7 @@ func (sS *SessionS) BiRPCv1GetCost(clnt rpcclient.ClientConnector, } // BiRPCv1SyncSessions will sync sessions on demand -func (sS *SessionS) BiRPCv1SyncSessions(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1SyncSessions(ctx *context.Context, ignParam *utils.TenantWithAPIOpts, reply *string) error { sS.syncSessions() *reply = utils.OK @@ -3668,7 +3660,7 @@ func (sS *SessionS) BiRPCv1SyncSessions(clnt rpcclient.ClientConnector, } // BiRPCv1ForceDisconnect will force disconnecting sessions matching sessions -func (sS *SessionS) BiRPCv1ForceDisconnect(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1ForceDisconnect(ctx *context.Context, args *utils.SessionFilter, reply *string) (err error) { if args == nil { //protection in case on nil args = &utils.SessionFilter{} @@ -3704,16 +3696,16 @@ func (sS *SessionS) BiRPCv1ForceDisconnect(clnt rpcclient.ClientConnector, } // BiRPCv1RegisterInternalBiJSONConn will register the client for a bidirectional comunication -func (sS *SessionS) BiRPCv1RegisterInternalBiJSONConn(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1RegisterInternalBiJSONConn(ctx *context.Context, connID string, reply *string) error { - sS.RegisterIntBiJConn(clnt, connID) + sS.RegisterIntBiJConn(ctx.Client, connID) *reply = utils.OK return nil } // BiRPCv1ActivateSessions is called to activate a list/all sessions // returns utils.ErrPartiallyExecuted in case of errors -func (sS *SessionS) BiRPCv1ActivateSessions(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1ActivateSessions(ctx *context.Context, sIDs *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) { if len(sIDs.IDs) == 0 { sS.pSsMux.RLock() @@ -3739,7 +3731,7 @@ func (sS *SessionS) BiRPCv1ActivateSessions(clnt rpcclient.ClientConnector, // BiRPCv1DeactivateSessions is called to deactivate a list/all active sessios // returns utils.ErrPartiallyExecuted in case of errors -func (sS *SessionS) BiRPCv1DeactivateSessions(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1DeactivateSessions(ctx *context.Context, sIDs *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) { if len(sIDs.IDs) == 0 { sS.aSsMux.RLock() @@ -3785,7 +3777,7 @@ func (sS *SessionS) processCDR(cgrEv *utils.CGREvent, flags []string, rply *stri CGREvent: *cgrEv, } argsProc.SetCloneable(clnb) - return sS.connMgr.Call(sS.cgrCfg.SessionSCfg().CDRsConns, nil, utils.CDRsV1ProcessEvent, + return sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().CDRsConns, utils.CDRsV1ProcessEvent, argsProc, rply) } @@ -3803,7 +3795,7 @@ func (sS *SessionS) processCDR(cgrEv *utils.CGREvent, flags []string, rply *stri if mp := engine.MapEvent(cgrEv.Event); unratedReqs.HasField(mp.GetStringIgnoreErrors(utils.RequestType)) { // order additional rating for unrated request types argsProc.Flags = append(argsProc.Flags, fmt.Sprintf("%s:true", utils.MetaRALs)) } - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().CDRsConns, nil, utils.CDRsV1ProcessEvent, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().CDRsConns, utils.CDRsV1ProcessEvent, argsProc, rply); err != nil { utils.Logger.Warning( fmt.Sprintf("<%s> error <%s> posting CDR with CGRID: <%s>", @@ -3832,7 +3824,7 @@ func (sS *SessionS) processThreshold(cgrEv *utils.CGREvent, thIDs []string, clnb } cgrEv.SetCloneable(clnb) //initialize the returned variable - err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().ThreshSConns, nil, utils.ThresholdSv1ProcessEvent, cgrEv, &tIDs) + err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().ThreshSConns, utils.ThresholdSv1ProcessEvent, cgrEv, &tIDs) return } @@ -3850,7 +3842,7 @@ func (sS *SessionS) processStats(cgrEv *utils.CGREvent, stsIDs []string, clnb bo } cgrEv.SetCloneable(clnb) //initialize the returned variable - err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().StatSConns, nil, utils.StatSv1ProcessEvent, cgrEv, &sIDs) + err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().StatSConns, utils.StatSv1ProcessEvent, cgrEv, &sIDs) return } @@ -3870,7 +3862,7 @@ func (sS *SessionS) getRoutes(cgrEv *utils.CGREvent, pag utils.Paginator, ignore cgrEv.APIOpts[utils.OptsRoutesIgnoreErrors] = ignoreErrors } cgrEv.SetCloneable(clnb) - if err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().RouteSConns, nil, utils.RouteSv1GetRoutes, + if err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().RouteSConns, utils.RouteSv1GetRoutes, cgrEv, &routesReply); err != nil { return routesReply, utils.NewErrRouteS(err) } @@ -3893,7 +3885,7 @@ func (sS *SessionS) processAttributes(cgrEv *utils.CGREvent, attrIDs []string, utils.IfaceAsString(ctx), utils.MetaSessionS) cgrEv.SetCloneable(clnb) - err = sS.connMgr.Call(sS.cgrCfg.SessionSCfg().AttrSConns, nil, utils.AttributeSv1ProcessEvent, + err = sS.connMgr.Call(context.TODO(), sS.cgrCfg.SessionSCfg().AttrSConns, utils.AttributeSv1ProcessEvent, cgrEv, &rplyEv) if err == nil && !has && utils.IfaceAsString(rplyEv.APIOpts[utils.OptsContext]) == utils.MetaSessionS { delete(rplyEv.APIOpts, utils.OptsContext) @@ -3903,11 +3895,11 @@ func (sS *SessionS) processAttributes(cgrEv *utils.CGREvent, attrIDs []string, // BiRPCV1GetMaxUsage returns the maximum usage as seconds, compatible with OpenSIPS 2.3 // DEPRECATED, it will be removed in future versions -func (sS *SessionS) BiRPCV1GetMaxUsage(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCV1GetMaxUsage(ctx *context.Context, ev engine.MapEvent, maxUsage *float64) (err error) { var rply *V1AuthorizeReply if err = sS.BiRPCv1AuthorizeEvent( - clnt, + ctx, &V1AuthorizeArgs{ GetMaxUsage: true, CGREvent: &utils.CGREvent{ @@ -3928,11 +3920,11 @@ func (sS *SessionS) BiRPCV1GetMaxUsage(clnt rpcclient.ClientConnector, // BiRPCV1InitiateSession is called on session start, returns the maximum number of seconds the session can last // DEPRECATED, it will be removed in future versions // Kept for compatibility with OpenSIPS 2.3 -func (sS *SessionS) BiRPCV1InitiateSession(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCV1InitiateSession(ctx *context.Context, ev engine.MapEvent, maxUsage *float64) (err error) { var rply *V1InitSessionReply if err = sS.BiRPCv1InitiateSession( - clnt, + ctx, &V1InitSessionArgs{ InitSession: true, CGREvent: &utils.CGREvent{ @@ -3953,11 +3945,11 @@ func (sS *SessionS) BiRPCV1InitiateSession(clnt rpcclient.ClientConnector, // BiRPCV1UpdateSession processes interim updates, returns remaining duration from the RALs // DEPRECATED, it will be removed in future versions // Kept for compatibility with OpenSIPS 2.3 -func (sS *SessionS) BiRPCV1UpdateSession(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCV1UpdateSession(ctx *context.Context, ev engine.MapEvent, maxUsage *float64) (err error) { var rply *V1UpdateSessionReply if err = sS.BiRPCv1UpdateSession( - clnt, + ctx, &V1UpdateSessionArgs{ UpdateSession: true, CGREvent: &utils.CGREvent{ @@ -3978,10 +3970,10 @@ func (sS *SessionS) BiRPCV1UpdateSession(clnt rpcclient.ClientConnector, // BiRPCV1TerminateSession is called on session end, should stop debit loop // DEPRECATED, it will be removed in future versions // Kept for compatibility with OpenSIPS 2.3 -func (sS *SessionS) BiRPCV1TerminateSession(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCV1TerminateSession(ctx *context.Context, ev engine.MapEvent, rply *string) (err error) { return sS.BiRPCv1TerminateSession( - clnt, + ctx, &V1TerminateSessionArgs{ TerminateSession: true, CGREvent: &utils.CGREvent{ @@ -3998,10 +3990,10 @@ func (sS *SessionS) BiRPCV1TerminateSession(clnt rpcclient.ClientConnector, // BiRPCV1ProcessCDR should send the CDR to CDRS // DEPRECATED, it will be removed in future versions // Kept for compatibility with OpenSIPS 2.3 -func (sS *SessionS) BiRPCV1ProcessCDR(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCV1ProcessCDR(ctx *context.Context, ev engine.MapEvent, rply *string) (err error) { return sS.BiRPCv1ProcessCDR( - clnt, + ctx, &utils.CGREvent{ Tenant: utils.FirstNonEmpty( ev.GetStringIgnoreErrors(utils.Tenant), @@ -4022,14 +4014,14 @@ func (sS *SessionS) sendRar(s *Session) (err error) { return } var rply string - if err = clnt.conn.Call(utils.SessionSv1ReAuthorize, originID, &rply); err == utils.ErrNotImplemented { + if err = clnt.conn.Call(context.TODO(), utils.SessionSv1ReAuthorize, originID, &rply); err == utils.ErrNotImplemented { err = nil } return } // BiRPCv1ReAuthorize sends a RAR for the matching sessions -func (sS *SessionS) BiRPCv1ReAuthorize(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1ReAuthorize(ctx *context.Context, args *utils.SessionFilter, reply *string) (err error) { if args == nil { //protection in case on nil args = &utils.SessionFilter{} @@ -4064,7 +4056,7 @@ func (sS *SessionS) BiRPCv1ReAuthorize(clnt rpcclient.ClientConnector, } // BiRPCv1DisconnectPeer sends a DPR for the given OriginHost and OriginRealm -func (sS *SessionS) BiRPCv1DisconnectPeer(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1DisconnectPeer(ctx *context.Context, args *utils.DPRArgs, reply *string) (err error) { hasErrors := false clients := make(map[string]*biJClient) @@ -4074,7 +4066,7 @@ func (sS *SessionS) BiRPCv1DisconnectPeer(clnt rpcclient.ClientConnector, } sS.biJMux.RUnlock() for ID, clnt := range clients { - if err = clnt.conn.Call(utils.SessionSv1DisconnectPeer, args, reply); err != nil && err != utils.ErrNotImplemented { + if err = clnt.conn.Call(context.TODO(), utils.SessionSv1DisconnectPeer, args, reply); err != nil && err != utils.ErrNotImplemented { utils.Logger.Warning( fmt.Sprintf( "<%s> failed sending DPR for connection with id: <%s>, err: <%s>", @@ -4090,7 +4082,7 @@ func (sS *SessionS) BiRPCv1DisconnectPeer(clnt rpcclient.ClientConnector, } // BiRPCv1STIRAuthenticate the API for STIR checking -func (sS *SessionS) BiRPCv1STIRAuthenticate(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1STIRAuthenticate(ctx *context.Context, args *V1STIRAuthenticateArgs, reply *string) (err error) { attest := sS.cgrCfg.SessionSCfg().STIRCfg.AllowedAttest if len(args.Attest) != 0 { @@ -4111,7 +4103,7 @@ func (sS *SessionS) BiRPCv1STIRAuthenticate(clnt rpcclient.ClientConnector, } // BiRPCv1STIRIdentity the API for STIR header creation -func (sS *SessionS) BiRPCv1STIRIdentity(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1STIRIdentity(ctx *context.Context, args *V1STIRIdentityArgs, identity *string) (err error) { if args == nil || args.Payload == nil { return utils.NewErrMandatoryIeMissing("Payload") @@ -4134,91 +4126,15 @@ func (sS *SessionS) BiRPCv1STIRIdentity(clnt rpcclient.ClientConnector, } // BiRPCv1STIRIdentity the API for STIR header creation -func (sS *SessionS) BiRPCv1CapsError(clnt rpcclient.ClientConnector, +func (sS *SessionS) BiRPCv1CapsError(ctx *context.Context, args any, identity *string) (err error) { - return utils.ErrMaxConcurrentRPCExceeded + return utils.ErrMaxConcurrentRPCExceededNoCaps } -// Handlers bidirectional methods following -func (sS *SessionS) Handlers() map[string]any { - return map[string]any{ - utils.SessionSv1AuthorizeEvent: func(clnt *rpc2.Client, args *V1AuthorizeArgs, rply *V1AuthorizeReply) (err error) { - return sS.BiRPCv1AuthorizeEvent(clnt, args, rply) - }, - utils.SessionSv1AuthorizeEventWithDigest: func(clnt *rpc2.Client, args *V1AuthorizeArgs, rply *V1AuthorizeReplyWithDigest) (err error) { - return sS.BiRPCv1AuthorizeEventWithDigest(clnt, args, rply) - }, - utils.SessionSv1InitiateSession: func(clnt *rpc2.Client, args *V1InitSessionArgs, rply *V1InitSessionReply) (err error) { - return sS.BiRPCv1InitiateSession(clnt, args, rply) - }, - utils.SessionSv1InitiateSessionWithDigest: func(clnt *rpc2.Client, args *V1InitSessionArgs, rply *V1InitReplyWithDigest) (err error) { - return sS.BiRPCv1InitiateSessionWithDigest(clnt, args, rply) - }, - utils.SessionSv1UpdateSession: func(clnt *rpc2.Client, args *V1UpdateSessionArgs, rply *V1UpdateSessionReply) (err error) { - return sS.BiRPCv1UpdateSession(clnt, args, rply) - }, - utils.SessionSv1SyncSessions: func(clnt *rpc2.Client, args *utils.TenantWithAPIOpts, rply *string) (err error) { - return sS.BiRPCv1SyncSessions(clnt, args, rply) - }, - utils.SessionSv1TerminateSession: func(clnt *rpc2.Client, args *V1TerminateSessionArgs, rply *string) (err error) { - return sS.BiRPCv1TerminateSession(clnt, args, rply) - }, - utils.SessionSv1ProcessCDR: func(clnt *rpc2.Client, args *utils.CGREvent, rply *string) (err error) { - return sS.BiRPCv1ProcessCDR(clnt, args, rply) - }, - utils.SessionSv1ProcessMessage: func(clnt *rpc2.Client, args *V1ProcessMessageArgs, rply *V1ProcessMessageReply) (err error) { - return sS.BiRPCv1ProcessMessage(clnt, args, rply) - }, - utils.SessionSv1ProcessEvent: func(clnt *rpc2.Client, args *V1ProcessEventArgs, rply *V1ProcessEventReply) (err error) { - return sS.BiRPCv1ProcessEvent(clnt, args, rply) - }, - utils.SessionSv1GetCost: func(clnt *rpc2.Client, args *V1ProcessEventArgs, rply *V1GetCostReply) (err error) { - return sS.BiRPCv1GetCost(clnt, args, rply) - }, - utils.SessionSv1GetActiveSessions: func(clnt *rpc2.Client, args *utils.SessionFilter, rply *[]*ExternalSession) (err error) { - return sS.BiRPCv1GetActiveSessions(clnt, args, rply) - }, - utils.SessionSv1GetActiveSessionsCount: func(clnt *rpc2.Client, args *utils.SessionFilter, rply *int) (err error) { - return sS.BiRPCv1GetActiveSessionsCount(clnt, args, rply) - }, - utils.SessionSv1GetPassiveSessions: func(clnt *rpc2.Client, args *utils.SessionFilter, rply *[]*ExternalSession) (err error) { - return sS.BiRPCv1GetPassiveSessions(clnt, args, rply) - }, - utils.SessionSv1GetPassiveSessionsCount: func(clnt *rpc2.Client, args *utils.SessionFilter, rply *int) (err error) { - return sS.BiRPCv1GetPassiveSessionsCount(clnt, args, rply) - }, - utils.SessionSv1ForceDisconnect: func(clnt *rpc2.Client, args *utils.SessionFilter, rply *string) (err error) { - return sS.BiRPCv1ForceDisconnect(clnt, args, rply) - }, - utils.SessionSv1RegisterInternalBiJSONConn: func(clnt *rpc2.Client, args string, rply *string) (err error) { - return sS.BiRPCv1RegisterInternalBiJSONConn(clnt, args, rply) - }, - utils.SessionSv1ReplicateSessions: func(clnt *rpc2.Client, args ArgsReplicateSessions, rply *string) (err error) { - return sS.BiRPCv1ReplicateSessions(clnt, args, rply) - }, - utils.SessionSv1SetPassiveSession: func(clnt *rpc2.Client, args *Session, rply *string) (err error) { - return sS.BiRPCv1SetPassiveSession(clnt, args, rply) - }, - utils.SessionSv1ActivateSessions: func(clnt *rpc2.Client, args *utils.SessionIDsWithArgsDispatcher, rply *string) (err error) { - return sS.BiRPCv1ActivateSessions(clnt, args, rply) - }, - utils.SessionSv1DeactivateSessions: func(clnt *rpc2.Client, args *utils.SessionIDsWithArgsDispatcher, rply *string) (err error) { - return sS.BiRPCv1DeactivateSessions(clnt, args, rply) - }, - utils.SessionSv1ReAuthorize: func(clnt *rpc2.Client, args *utils.SessionFilter, rply *string) (err error) { - return sS.BiRPCv1ReAuthorize(clnt, args, rply) - }, - utils.SessionSv1DisconnectPeer: func(clnt *rpc2.Client, args *utils.DPRArgs, rply *string) (err error) { - return sS.BiRPCv1DisconnectPeer(clnt, args, rply) - }, - utils.SessionSv1STIRAuthenticate: func(clnt *rpc2.Client, args *V1STIRAuthenticateArgs, rply *string) (err error) { - return sS.BiRPCv1STIRAuthenticate(clnt, args, rply) - }, - utils.SessionSv1STIRIdentity: func(clnt *rpc2.Client, args *V1STIRIdentityArgs, rply *string) (err error) { - return sS.BiRPCv1STIRIdentity(clnt, args, rply) - }, - utils.SessionSv1CapsError: func(clnt *rpc2.Client, args any, rply *string) (err error) { - return sS.BiRPCv1CapsError(clnt, args, rply) - }, - } +// BiRPCv1Sleep mimics a request whose process takes the given amount of time to process +func (ssv1 *SessionS) BiRPCv1Sleep(ctx *context.Context, args *utils.DurationArgs, + reply *string) (err error) { + time.Sleep(args.Duration) + *reply = utils.OK + return nil } diff --git a/sessions/sessions_bench_test.go b/sessions/sessions_bench_test.go index 3d72c29ac..cddd75516 100644 --- a/sessions/sessions_bench_test.go +++ b/sessions/sessions_bench_test.go @@ -25,13 +25,14 @@ import ( "flag" "fmt" "log" - "net/rpc" - "net/rpc/jsonrpc" "path" "sync" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" + "github.com/cgrates/birpc/jsonrpc" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -39,7 +40,7 @@ import ( var ( sBenchCfg *config.CGRConfig - sBenchRPC *rpc.Client + sBenchRPC *birpc.Client connOnce sync.Once initRuns = flag.Int("runs", 25000, "number of loops to run in init") cps = flag.Int("cps", 2000, "number of loops to run in init") @@ -68,14 +69,14 @@ func loadTP() { attrs := &utils.AttrLoadTpFromFolder{ FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} var tpLoadInst utils.LoadInstance - if err := sBenchRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, + if err := sBenchRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &tpLoadInst); err != nil { log.Fatal(err) } time.Sleep(100 * time.Millisecond) // Give time for scheduler to execute topups } -func addBalance(sBenchRPC *rpc.Client, sraccount string) { +func addBalance(sBenchRPC *birpc.Client, sraccount string) { attrSetBalance := utils.AttrSetBalance{ Tenant: "cgrates.org", Account: sraccount, @@ -86,7 +87,7 @@ func addBalance(sBenchRPC *rpc.Client, sraccount string) { }, } var reply string - if err := sBenchRPC.Call(utils.APIerSv2SetBalance, + if err := sBenchRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { log.Fatal(err) } @@ -131,7 +132,7 @@ func initSession(i int) { initArgs.Event[utils.Destination] = fmt.Sprintf("1002%v", i) var initRpl *V1InitSessionReply - if err := sBenchRPC.Call(utils.SessionSv1InitiateSession, + if err := sBenchRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { // log.Fatal(err) } @@ -165,7 +166,7 @@ func sendInit() { func getCount() int { var count int - if err := sBenchRPC.Call(utils.SessionSv1GetActiveSessionsCount, utils.SessionFilter{ + if err := sBenchRPC.Call(context.Background(), utils.SessionSv1GetActiveSessionsCount, utils.SessionFilter{ Filters: []string{"*string:~*req.ToR:*voice"}, }, &count); err != nil { log.Fatal(err) @@ -221,7 +222,7 @@ func BenchmarkEncodingGOB(b *testing.B) { log.Fatal(err) } - if sBenchRPC, err = rpc.Dial(utils.TCP, sBenchCfg.ListenCfg().RPCGOBListen); err != nil { + if sBenchRPC, err = birpc.Dial(utils.TCP, sBenchCfg.ListenCfg().RPCGOBListen); err != nil { log.Fatalf("Error at dialing rcp client:%v\n", err) } b.ResetTimer() diff --git a/sessions/sessions_birpc_it_test.go b/sessions/sessions_birpc_it_test.go index 46a7a4e6e..f86e5be65 100644 --- a/sessions/sessions_birpc_it_test.go +++ b/sessions/sessions_birpc_it_test.go @@ -26,7 +26,8 @@ import ( "testing" "time" - "github.com/cenkalti/rpc2" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ var ( sessionsBiRPCCfgPath string sessionsBiRPCCfgDIR string sessionsBiRPCCfg *config.CGRConfig - sessionsBiRPC *rpc2.Client + sessionsBiRPC *birpc.BirpcClient disconnectEvChan = make(chan *utils.AttrDisconnectSession, 1) err error sessionsTests = []func(t *testing.T){ @@ -71,7 +72,9 @@ func TestSessionsBiRPC(t *testing.T) { } } -func handleDisconnectSession(clnt *rpc2.Client, +type smock struct{} + +func (*smock) DisconnectSession(ctx *context.Context, args *utils.AttrDisconnectSession, reply *string) error { disconnectEvChan <- args *reply = utils.OK @@ -110,14 +113,17 @@ func testSessionsBiRPCStartEngine(t *testing.T) { // Connect rpc client to rater func testSessionsBiRPCApierRpcConn(t *testing.T) { - clntHandlers := map[string]any{utils.SessionSv1DisconnectSession: handleDisconnectSession} + srv, err := birpc.NewService(new(smock), utils.SessionSv1, true) + if err != nil { + t.Fatal(err) + } dummyClnt, err := utils.NewBiJSONrpcClient(sessionsBiRPCCfg.SessionSCfg().ListenBijson, - clntHandlers) + srv) if err != nil { // First attempt is to make sure multiple clients are supported t.Fatal(err) } if sessionsBiRPC, err = utils.NewBiJSONrpcClient(sessionsBiRPCCfg.SessionSCfg().ListenBijson, - clntHandlers); err != nil { + srv); err != nil { t.Fatal(err) } if sessionsRPC, err = newRPCClient(sessionsBiRPCCfg.ListenCfg()); err != nil { // Connect also simple RPC so we can check accounts and such @@ -130,7 +136,7 @@ func testSessionsBiRPCApierRpcConn(t *testing.T) { func testSessionsBiRPCTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance - if err := sessionsRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -148,7 +154,7 @@ func testSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) { }, } var reply string - if err := sessionsRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -159,7 +165,7 @@ func testSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) { Account: attrSetBalance.Account, } eAcntVal := 0.01 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrGetAcnt, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrGetAcnt, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %f, received: %f", eAcntVal, @@ -189,7 +195,7 @@ func testSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsBiRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsBiRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Fatal(err) } @@ -231,16 +237,16 @@ func testSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) { } var rpl string - if err := sessionsBiRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sessionsBiRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } time.Sleep(100 * time.Millisecond) // Give time for debits to occur - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrGetAcnt, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrGetAcnt, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 0 { t.Errorf("Balance should be empty, have: %f", acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) } - if err := sessionsBiRPC.Call(utils.SessionSv1ProcessCDR, termArgs.CGREvent, &reply); err != nil { + if err := sessionsBiRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, termArgs.CGREvent, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received reply: %s", reply) @@ -249,7 +255,7 @@ func testSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) { var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, DestinationPrefixes: []string{"1004"}} - if err := sessionsRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -274,7 +280,7 @@ func testSessionsBiRPCSessionOriginatorTerminate(t *testing.T) { }, } var reply string - if err := sessionsRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -282,7 +288,7 @@ func testSessionsBiRPCSessionOriginatorTerminate(t *testing.T) { var acnt *engine.Account attrGetAcnt := &utils.AttrGetAccount{Tenant: attrSetBalance.Tenant, Account: attrSetBalance.Account} eAcntVal := 1.0 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrGetAcnt, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrGetAcnt, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) @@ -311,7 +317,7 @@ func testSessionsBiRPCSessionOriginatorTerminate(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsBiRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsBiRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -346,18 +352,18 @@ func testSessionsBiRPCSessionOriginatorTerminate(t *testing.T) { } var rpl string - if err := sessionsBiRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sessionsBiRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } time.Sleep(50 * time.Millisecond) // Give time for debits to occur - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrGetAcnt, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrGetAcnt, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() > 0.995*float64(time.Second) { // FixMe: should be not 0.93? t.Errorf("Balance value: %f", acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) } - if err := sessionsRPC.Call(utils.SessionSv1ProcessCDR, termArgs.CGREvent, &reply); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, termArgs.CGREvent, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received reply: %s", reply) @@ -367,7 +373,7 @@ func testSessionsBiRPCSessionOriginatorTerminate(t *testing.T) { var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, DestinationPrefixes: []string{"1005"}} - if err := sessionsRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -384,7 +390,7 @@ func testSessionsBiRPCStopCgrEngine(t *testing.T) { if err := sessionsBiRPC.Close(); err != nil { // Close the connection so we don't get EOF warnings from client t.Error(err) } - if err := engine.KillEngine(100); err != nil { + if err := engine.KillEngine(*waitRater); err != nil { t.Error(err) } } diff --git a/sessions/sessions_data_it_test.go b/sessions/sessions_data_it_test.go index 40ee991ce..a674d7001 100644 --- a/sessions/sessions_data_it_test.go +++ b/sessions/sessions_data_it_test.go @@ -21,11 +21,12 @@ along with this program. If not, see package sessions import ( - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -35,7 +36,7 @@ var ( dataCfgPath string dataCfgDIR string dataCfg *config.CGRConfig - sDataRPC *rpc.Client + sDataRPC *birpc.Client SessionsDataTests = []func(t *testing.T){ testSessionsDataInitCfg, @@ -118,7 +119,7 @@ func testSessionsDataApierRpcConn(t *testing.T) { func testSessionsDataTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance - if err := sDataRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -128,7 +129,7 @@ func testSessionsDataLastUsedData(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 102400.0 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaData].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", @@ -146,7 +147,7 @@ func testSessionsDataLastUsedData(t *testing.T) { } var cc engine.CallCost // Make sure the cost is what we expect to be for 1MB of data - if err := sDataRPC.Call(utils.ResponderGetCost, &engine.CallDescriptorWithAPIOpts{CallDescriptor: &cd}, &cc); err != nil { + if err := sDataRPC.Call(context.Background(), utils.ResponderGetCost, &engine.CallDescriptorWithAPIOpts{CallDescriptor: &cd}, &cc); err != nil { t.Error("Got error on Responder.GetCost: ", err.Error()) } else if cc.Cost != 1024 { t.Errorf("Calling Responder.GetCost got callcost: %v", cc.Cost) @@ -176,7 +177,7 @@ func testSessionsDataLastUsedData(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sDataRPC.Call(utils.SessionSv1InitiateSession, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -185,7 +186,7 @@ func testSessionsDataLastUsedData(t *testing.T) { } eAcntVal = 97280.0 // 100 -5 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaData].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", @@ -216,7 +217,7 @@ func testSessionsDataLastUsedData(t *testing.T) { } var updateRpl *V1UpdateSessionReply - if err := sDataRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } if updateRpl.MaxUsage.Nanoseconds() != usage { @@ -224,7 +225,7 @@ func testSessionsDataLastUsedData(t *testing.T) { } eAcntVal = 93184.0 // 100-9 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaData].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaData].GetTotalValue()) @@ -253,11 +254,11 @@ func testSessionsDataLastUsedData(t *testing.T) { } var rpl string - if err := sDataRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } eAcntVal = 98304.0 //100-4 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaData].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", @@ -279,12 +280,12 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { }, } var reply string - if err := sDataRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) @@ -314,7 +315,7 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sDataRPC.Call(utils.SessionSv1InitiateSession, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -323,13 +324,13 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { } eAcntVal = 96256 // 100-6 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) } aSessions := make([]*ExternalSession, 0) - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 || aSessions[0].Usage != 6144 { @@ -362,7 +363,7 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { } var updateRpl *V1UpdateSessionReply - if err := sDataRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } if updateRpl.MaxUsage.Nanoseconds() != usage { @@ -370,12 +371,12 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { } eAcntVal = 87040.000000 // 15MB used - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) } - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 || aSessions[0].Usage != 15360 { @@ -410,7 +411,7 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { }, } - if err := sDataRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } if updateRpl.MaxUsage.Nanoseconds() != usage { @@ -418,12 +419,12 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { } eAcntVal = 87040.000000 // the amount is not modified and there will be 1024 extra left in SMG - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) } - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 || aSessions[0].Usage != 13312 { // 14MB in used, 2MB extra reserved @@ -457,7 +458,7 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { }, } - if err := sDataRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } if updateRpl.MaxUsage.Nanoseconds() != usage { @@ -465,12 +466,12 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { } eAcntVal = 87040.000000 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) } - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 || aSessions[0].Usage != 14336 { // 14MB in use @@ -501,21 +502,21 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { } var rpl string - if err := sDataRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } eAcntVal = 89088.000000 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) } - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err, aSessions) } - if err := sDataRPC.Call(utils.SessionSv1ProcessCDR, termArgs.CGREvent, &reply); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, termArgs.CGREvent, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received reply: %s", reply) @@ -526,7 +527,7 @@ func testSessionsDataLastUsedMultipleUpdates(t *testing.T) { var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, Accounts: []string{acntAttrs.Account}} - if err := sDataRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -554,12 +555,12 @@ func testSessionsDataTTLExpired(t *testing.T) { }, } var reply string - if err := sDataRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) @@ -592,7 +593,7 @@ func testSessionsDataTTLExpired(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sDataRPC.Call(utils.SessionSv1InitiateSession, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -601,7 +602,7 @@ func testSessionsDataTTLExpired(t *testing.T) { } eAcntVal = 101376.000000 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if dataVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); dataVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, dataVal) @@ -609,7 +610,7 @@ func testSessionsDataTTLExpired(t *testing.T) { time.Sleep(70 * time.Millisecond) eAcntVal = 100352.000000 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if dataVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); dataVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, dataVal) @@ -618,7 +619,7 @@ func testSessionsDataTTLExpired(t *testing.T) { // verify the cdr usage SessionTTLUsage ( 2048) var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Accounts: []string{acntAttrs.Account}} - if err := sDataRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -646,12 +647,12 @@ func testSessionsDataTTLExpMultiUpdates(t *testing.T) { }, } var reply string - if err := sDataRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) @@ -681,7 +682,7 @@ func testSessionsDataTTLExpMultiUpdates(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sDataRPC.Call(utils.SessionSv1InitiateSession, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Fatal(err) } @@ -691,13 +692,13 @@ func testSessionsDataTTLExpMultiUpdates(t *testing.T) { } eAcntVal = 98304.000000 //96MB - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if dataVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); dataVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, dataVal) } aSessions := make([]*ExternalSession, 0) - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 || int64(aSessions[0].Usage) != 4096 { @@ -734,7 +735,7 @@ func testSessionsDataTTLExpMultiUpdates(t *testing.T) { } var updateRpl *V1UpdateSessionReply - if err := sDataRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } if updateRpl.MaxUsage.Nanoseconds() != usage { @@ -742,7 +743,7 @@ func testSessionsDataTTLExpMultiUpdates(t *testing.T) { } eAcntVal = 97280.000000 // 20480 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaData].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaData].GetTotalValue()) @@ -750,12 +751,12 @@ func testSessionsDataTTLExpMultiUpdates(t *testing.T) { time.Sleep(60 * time.Millisecond) // TTL will kick in eAcntVal = 100352.000000 // initial balance ( 102400 ) - SessionTTLUsage from update ( 2048 ) - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if dataVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); dataVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, dataVal) } - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err, aSessions) } @@ -763,7 +764,7 @@ func testSessionsDataTTLExpMultiUpdates(t *testing.T) { // verify the cdr usage SessionTTLUsage ( 2048) var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Accounts: []string{acntAttrs.Account}} - if err := sDataRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -788,12 +789,12 @@ func testSessionsDataMultipleDataNoUsage(t *testing.T) { }, } var reply string - if err := sDataRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) @@ -823,7 +824,7 @@ func testSessionsDataMultipleDataNoUsage(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sDataRPC.Call(utils.SessionSv1InitiateSession, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Fatal(err) } @@ -832,13 +833,13 @@ func testSessionsDataMultipleDataNoUsage(t *testing.T) { } eAcntVal = 100352.000000 // 1054720 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if dataVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); dataVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, dataVal) } aSessions := make([]*ExternalSession, 0) - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 || int64(aSessions[0].Usage) != 2048 { @@ -873,7 +874,7 @@ func testSessionsDataMultipleDataNoUsage(t *testing.T) { } var updateRpl *V1UpdateSessionReply - if err := sDataRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Fatal(err) } if updateRpl.MaxUsage.Nanoseconds() != usage { @@ -881,13 +882,13 @@ func testSessionsDataMultipleDataNoUsage(t *testing.T) { } eAcntVal = 100352.000000 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if dataVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); dataVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, dataVal) } aSessions = make([]*ExternalSession, 0) - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 || int64(aSessions[0].Usage) != 2048 { @@ -922,7 +923,7 @@ func testSessionsDataMultipleDataNoUsage(t *testing.T) { } updateRpl = new(V1UpdateSessionReply) // because gob doesn't overwrite 0 value fields - if err := sDataRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Fatal(err) } if *encoding != utils.MetaGOB { @@ -936,13 +937,13 @@ func testSessionsDataMultipleDataNoUsage(t *testing.T) { } eAcntVal = 100352.000000 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if dataVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); dataVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, dataVal) } aSessions = make([]*ExternalSession, 0) - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 || int64(aSessions[0].Usage) != 1024 { @@ -972,18 +973,18 @@ func testSessionsDataMultipleDataNoUsage(t *testing.T) { } var rpl string - if err := sDataRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } eAcntVal = 101376.000000 // refunded last 1MB reserved and unused - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaData].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaData].GetTotalValue()) } - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err, aSessions) @@ -1006,12 +1007,12 @@ func testSessionsDataTTLUsageProtection(t *testing.T) { }, } var reply string - if err := sDataRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) @@ -1041,7 +1042,7 @@ func testSessionsDataTTLUsageProtection(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sDataRPC.Call(utils.SessionSv1InitiateSession, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Fatal(err) } @@ -1050,20 +1051,20 @@ func testSessionsDataTTLUsageProtection(t *testing.T) { } eAcntVal = 100352.000000 // 1054720 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if dataVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); dataVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, dataVal) } aSessions := make([]*ExternalSession, 0) - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 || int64(aSessions[0].Usage) != 2048 { t.Errorf("wrong active sessions usage: %d", int64(aSessions[0].Usage)) } time.Sleep(60 * time.Millisecond) - if err := sDataRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err, utils.ToJSON(aSessions)) } @@ -1083,12 +1084,12 @@ func testSessionsDataTTLLastUsage(t *testing.T) { }, } var reply string - if err := sDataRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) } - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if totalVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); totalVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, totalVal) @@ -1121,7 +1122,7 @@ func testSessionsDataTTLLastUsage(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sDataRPC.Call(utils.SessionSv1InitiateSession, + if err := sDataRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -1130,7 +1131,7 @@ func testSessionsDataTTLLastUsage(t *testing.T) { } eAcntVal = 101376.000000 - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if dataVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); dataVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, dataVal) @@ -1138,7 +1139,7 @@ func testSessionsDataTTLLastUsage(t *testing.T) { time.Sleep(70 * time.Millisecond) eAcntVal = 99328.000000 // 101376.000000 ( units remains after init session ) - SessionTTLLastUsage ( 2048 ) - if err := sDataRPC.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil { t.Error(err) } else if dataVal := acnt.BalanceMap[utils.MetaData].GetTotalValue(); dataVal != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, dataVal) @@ -1147,7 +1148,7 @@ func testSessionsDataTTLLastUsage(t *testing.T) { // verify the cdr usage to be 3072 ( init usage ( 1024 ) + SessionTTLLastUsage ( 2048 ) ) var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{Accounts: []string{acntAttrs.Account}} - if err := sDataRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sDataRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) diff --git a/sessions/sessions_it_test.go b/sessions/sessions_it_test.go index f76bb431b..68c8e804c 100644 --- a/sessions/sessions_it_test.go +++ b/sessions/sessions_it_test.go @@ -22,11 +22,12 @@ package sessions import ( "fmt" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ var ( sItCfgPath string sItCfgDIR string sItCfg *config.CGRConfig - sItRPC *rpc.Client + sItRPC *birpc.Client sessionsITtests = []func(t *testing.T){ testSessionsItInitCfg, @@ -115,7 +116,7 @@ func testSessionsItApierRpcConn(t *testing.T) { func testSessionsItTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")} var loadInst utils.LoadInstance - if err := sItRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := sItRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -125,7 +126,7 @@ func testSessionsItTerminatNonexist(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 10.0 - if err := sItRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sItRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -158,19 +159,19 @@ func testSessionsItTerminatNonexist(t *testing.T) { } var rpl string - if err := sItRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sItRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } time.Sleep(100 * time.Millisecond) eAcntVal = 9.299800 - if err := sItRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sItRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) } time.Sleep(100 * time.Millisecond) - if err := sItRPC.Call(utils.SessionSv1ProcessCDR, termArgs.CGREvent, &rpl); err != nil { + if err := sItRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, termArgs.CGREvent, &rpl); err != nil { t.Error(err) } else if rpl != utils.OK { t.Errorf("Received reply: %s", rpl) @@ -181,7 +182,7 @@ func testSessionsItTerminatNonexist(t *testing.T) { DestinationPrefixes: []string{"1002"}, RunIDs: []string{utils.MetaDefault}, } - if err := sItRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sItRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Errorf("Unexpected number of CDRs returned: %v \n cdrs=%s", len(cdrs), utils.ToJSON(cdrs)) @@ -200,7 +201,7 @@ func testSessionsItUpdateNonexist(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 9.299800 - if err := sItRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sItRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -233,7 +234,7 @@ func testSessionsItUpdateNonexist(t *testing.T) { } var updtRpl V1UpdateSessionReply - if err := sItRPC.Call(utils.SessionSv1UpdateSession, updtArgs, &updtRpl); err != nil { + if err := sItRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updtArgs, &updtRpl); err != nil { t.Error(err) } if updtRpl.MaxUsage == nil || *updtRpl.MaxUsage != usage { @@ -243,7 +244,7 @@ func testSessionsItUpdateNonexist(t *testing.T) { time.Sleep(10 * time.Millisecond) eAcntVal = 8.599600 - if err := sItRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sItRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -271,7 +272,7 @@ func testSessionsItUpdateNonexist(t *testing.T) { }, } - if err := sItRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sItRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } } @@ -308,7 +309,7 @@ func testSessionsItTerminatePassive(t *testing.T) { var rply string //transfer the session from active to pasive - if err := sItRPC.Call(utils.SessionSv1SetPassiveSession, + if err := sItRPC.Call(context.Background(), utils.SessionSv1SetPassiveSession, s, &rply); err != nil { t.Error(err) } else if rply != utils.OK { @@ -316,7 +317,7 @@ func testSessionsItTerminatePassive(t *testing.T) { } var pSessions []*ExternalSession //check if the passive session was created - if err := sItRPC.Call(utils.SessionSv1GetPassiveSessions, + if err := sItRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, &utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123789"), @@ -352,13 +353,13 @@ func testSessionsItTerminatePassive(t *testing.T) { } var rpl string - if err := sItRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sItRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } time.Sleep(10 * time.Millisecond) //check if the passive session was terminate - if err := sItRPC.Call(utils.SessionSv1GetPassiveSessions, + if err := sItRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123789"), @@ -382,7 +383,7 @@ func testSessionsItEventCostCompressing(t *testing.T) { }, } var reply string - if err := sItRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sItRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -404,7 +405,7 @@ func testSessionsItEventCostCompressing(t *testing.T) { }, } var initRpl *V1InitSessionReply - if err := sItRPC.Call(utils.SessionSv1InitiateSession, + if err := sItRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -423,15 +424,15 @@ func testSessionsItEventCostCompressing(t *testing.T) { }, } var updateRpl *V1UpdateSessionReply - if err := sItRPC.Call(utils.SessionSv1UpdateSession, + if err := sItRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } - if err := sItRPC.Call(utils.SessionSv1UpdateSession, + if err := sItRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } - if err := sItRPC.Call(utils.SessionSv1UpdateSession, + if err := sItRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } @@ -451,19 +452,19 @@ func testSessionsItEventCostCompressing(t *testing.T) { }, } var rpl string - if err := sItRPC.Call(utils.SessionSv1TerminateSession, + if err := sItRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } - if err := sItRPC.Call(utils.SessionSv1ProcessCDR, + if err := sItRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, termArgs.CGREvent, &reply); err != nil { t.Error(err) } time.Sleep(20 * time.Millisecond) cgrID := utils.Sha1("TestSessionsItEventCostCompressing", "") var ec *engine.EventCost - if err := sItRPC.Call(utils.APIerSv1GetEventCost, + if err := sItRPC.Call(context.Background(), utils.APIerSv1GetEventCost, &utils.AttrGetCallCost{CgrId: cgrID, RunId: utils.MetaDefault}, &ec); err != nil { t.Fatal(err) diff --git a/sessions/sessions_rpl_it_test.go b/sessions/sessions_rpl_it_test.go index 4d4200877..6c2b7dc4d 100644 --- a/sessions/sessions_rpl_it_test.go +++ b/sessions/sessions_rpl_it_test.go @@ -22,11 +22,12 @@ package sessions import ( "fmt" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ var ( smgRplcMasterCfgPath, smgRplcSlaveCfgPath string smgRplcMasterCfgDIR, smgRplcSlaveCfgDIR string smgRplcMasterCfg, smgRplcSlaveCfg *config.CGRConfig - smgRplcMstrRPC, smgRplcSlvRPC *rpc.Client + smgRplcMstrRPC, smgRplcSlvRPC *birpc.Client SessionsRplTests = []func(t *testing.T){ testSessionSRplInitCfg, @@ -122,7 +123,7 @@ func testSessionSRplApierRpcConn(t *testing.T) { func testSessionSRplTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance - if err := smgRplcMstrRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -131,11 +132,11 @@ func testSessionSRplTPFromFolder(t *testing.T) { func testSessionSRplInitiate(t *testing.T) { var aSessions []*ExternalSession //make sure we don't have active sessions on master and passive on slave - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } @@ -164,7 +165,7 @@ func testSessionSRplInitiate(t *testing.T) { } var initRpl V1InitSessionReply - if err := smgRplcMstrRPC.Call(utils.SessionSv1InitiateSession, + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1InitiateSession, argsInit, &initRpl); err != nil { t.Error(err) } @@ -175,7 +176,7 @@ func testSessionSRplInitiate(t *testing.T) { time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Wait for the sessions to be populated //check if the session was createad as active session on master - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123451"), @@ -190,7 +191,7 @@ func testSessionSRplInitiate(t *testing.T) { //check if the session was created as passive session on slave var pSessions []*ExternalSession - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123451"), @@ -229,7 +230,7 @@ func testSessionSRplUpdate(t *testing.T) { }, } var updtRpl V1UpdateSessionReply - if err := smgRplcSlvRPC.Call(utils.SessionSv1UpdateSession, + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1UpdateSession, argsUpdate, &updtRpl); err != nil { t.Error(err) } @@ -239,7 +240,7 @@ func testSessionSRplUpdate(t *testing.T) { time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Wait for the sessions to be populated var aSessions []*ExternalSession - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetActiveSessions, + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123451"), @@ -254,13 +255,13 @@ func testSessionSRplUpdate(t *testing.T) { var pSessions []*ExternalSession // Make sure we don't have passive session on active host - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } // Master should not longer have activeSession - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123451"), @@ -272,7 +273,7 @@ func testSessionSRplUpdate(t *testing.T) { cgrID := GetSetCGRID(engine.NewMapEvent(argsUpdate.Event)) // Make sure session was replicated - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetPassiveSessions, + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil { t.Error(err) } else if len(pSessions) != 1 { @@ -307,13 +308,13 @@ func testSessionSRplTerminate(t *testing.T) { }, } var reply string - if err := smgRplcMstrRPC.Call(utils.SessionSv1TerminateSession, args, &reply); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1TerminateSession, args, &reply); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Wait for the sessions to be populated var aSessions []*ExternalSession //check if the session was terminated on master - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.OriginID, "123451"), @@ -323,17 +324,17 @@ func testSessionSRplTerminate(t *testing.T) { t.Errorf("Error: %v with len(aSessions)=%v , session : %+v", err, len(aSessions), utils.ToIJSON(aSessions)) } //check if the session was terminated on slave - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetActiveSessions, + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error: %v with len(aSessions)=%v , session : %+v", err, len(aSessions), utils.ToIJSON(aSessions)) } // check to don't have passive session on master and slave var pSessions []*ExternalSession - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error: %v with len(pSessions)=%v , session : %+v", err, len(pSessions), utils.ToIJSON(pSessions)) } - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Errorf("Error: %v with len(pSessions)=%v , session : %+v", err, len(pSessions), utils.ToIJSON(pSessions)) } @@ -394,7 +395,7 @@ func testSessionSRplManualReplicate(t *testing.T) { for _, args := range []*V1InitSessionArgs{argsInit1, argsInit2} { var initRpl *V1InitSessionReply - if err := smgRplcMstrRPC.Call(utils.SessionSv1InitiateSession, args, &initRpl); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1InitiateSession, args, &initRpl); err != nil { t.Error(err) } if initRpl.MaxUsage == nil || *initRpl.MaxUsage != 90*time.Second { @@ -403,7 +404,7 @@ func testSessionSRplManualReplicate(t *testing.T) { } //verify if the sessions was created on master and are active var aSessions []*ExternalSession - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 2 { t.Errorf("Unexpected number of sessions received: %+v", utils.ToJSON(aSessions)) @@ -425,7 +426,7 @@ func testSessionSRplManualReplicate(t *testing.T) { t.Fatal(err) } // when we start slave after master we expect to don't have sessions - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err == nil || + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err, aSessions) } @@ -434,11 +435,11 @@ func testSessionSRplManualReplicate(t *testing.T) { } //replicate manually the session from master to slave var repply string - if err := smgRplcMstrRPC.Call(utils.SessionSv1ReplicateSessions, &argsRepl, &repply); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1ReplicateSessions, &argsRepl, &repply); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Wait for the sessions to be populated - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 2 { t.Errorf("Unexpected number of sessions received: %+v", aSessions) @@ -450,10 +451,10 @@ func testSessionSRplManualReplicate(t *testing.T) { t.Errorf("Failed to kill process, error: %v", err.Error()) } var status map[string]any - if err := smgRplcMstrRPC.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err == nil { // master should not longer be reachable + if err := smgRplcMstrRPC.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err == nil { // master should not longer be reachable t.Error(err, status) } - if err := smgRplcSlvRPC.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // slave should be still operational + if err := smgRplcSlvRPC.Call(context.Background(), utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &status); err != nil { // slave should be still operational t.Error(err) } // start master @@ -464,10 +465,10 @@ func testSessionSRplManualReplicate(t *testing.T) { t.Fatal(err) } // Master should have no session active/passive - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err, aSessions) } - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err, aSessions) } // recover passive sessions from slave @@ -475,15 +476,15 @@ func testSessionSRplManualReplicate(t *testing.T) { Passive: true, ConnIDs: []string{"rplConn"}, } - if err := smgRplcSlvRPC.Call(utils.SessionSv1ReplicateSessions, &argsRepl, &repply); err != nil { + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1ReplicateSessions, &argsRepl, &repply); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Wait for the sessions to be populated // Master should have no session active/passive - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err, aSessions) } - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 2 { t.Errorf("Unexpected number of sessions received: %+v", aSessions) @@ -499,27 +500,27 @@ func testSessionSRplActivateSessions(t *testing.T) { args := &utils.SessionIDsWithArgsDispatcher{ IDs: []string{"ede927f8e42318a8db02c0f74adc2d9e16770339"}, } - if err := smgRplcMstrRPC.Call(utils.SessionSv1ActivateSessions, args, &reply); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1ActivateSessions, args, &reply); err != nil { t.Error(err) } // Check the sessions on master engine (at this point should have one active and one passive session) - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("Expecting: 1 session, received: %+v sessions", len(aSessions)) } - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("Expecting: 1 session, received: %+v sessions", len(aSessions)) } // Check the sessions on slave engine (at this point should have one active and one passive session) - // if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + // if err := smgRplcSlvRPC.Call(context.Background(),utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err != nil { // t.Error(err) // } else if len(aSessions) != 1 { // t.Errorf("Expecting: 1 session, received: %+v sessions", len(aSessions)) //received 2 // } - // if err := smgRplcSlvRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + // if err := smgRplcSlvRPC.Call(context.Background(),utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { // t.Error(err) //received not found // } else if len(aSessions) != 1 { // t.Errorf("Expecting: 1 session, received: %+v sessions", len(aSessions)) @@ -528,20 +529,20 @@ func testSessionSRplActivateSessions(t *testing.T) { args = &utils.SessionIDsWithArgsDispatcher{ IDs: []string{"3b0417028f8cefc0e02ddbd37a6dda6fbef4f5e0"}, } - if err := smgRplcMstrRPC.Call(utils.SessionSv1ActivateSessions, args, &reply); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1ActivateSessions, args, &reply); err != nil { t.Error(err) } //Check the sessions on master engine (2 active, 0 passive) - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 2 { t.Errorf("Expecting: 2 session, received: %+v sessions", len(aSessions)) } - if err := smgRplcMstrRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { + if err := smgRplcMstrRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } //check the number of passive sessions on slave engine - if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err != nil { + if err := smgRplcSlvRPC.Call(context.Background(), utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &aSessions); err != nil { t.Error(err) } else if len(aSessions) != 2 { t.Errorf("Expecting: 2 session, received: %+v sessions", len(aSessions)) diff --git a/sessions/sessions_test.go b/sessions/sessions_test.go index aa2f9841a..a70b2d431 100644 --- a/sessions/sessions_test.go +++ b/sessions/sessions_test.go @@ -26,12 +26,11 @@ import ( "testing" "time" - "github.com/cenkalti/rpc2" - + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" jwt "github.com/dgrijalva/jwt-go" ) @@ -94,7 +93,7 @@ func TestOnBiJSONConnectDisconnect(t *testing.T) { sessions := NewSessionS(cfg, dm, nil) //connect BiJSON - client := rpc2.NewClient(nil) + client := &birpc.Service{} sessions.OnBiJSONConnect(client) //we'll change the connection identifier just for testing @@ -123,10 +122,10 @@ func TestBiRPCv1RegisterInternalBiJSONConn(t *testing.T) { dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) sessions := NewSessionS(cfg, dm, nil) - client := rpc2.NewClient(nil) - + client := &birpc.Service{} + ctx := context.WithClient(context.Background(), client) var reply string - if err := sessions.BiRPCv1RegisterInternalBiJSONConn(client, utils.EmptyString, &reply); err != nil { + if err := sessions.BiRPCv1RegisterInternalBiJSONConn(ctx, utils.EmptyString, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected %+v, received %+v", reply, utils.OK) @@ -1942,7 +1941,7 @@ func TestNewSessionS(t *testing.T) { eOut := &SessionS{ cgrCfg: cgrCGF, dm: nil, - biJClnts: make(map[rpcclient.ClientConnector]string), + biJClnts: make(map[birpc.ClientConnector]string), biJIDs: make(map[string]*biJClient), aSessions: make(map[string]*Session), aSessionsIdx: make(map[string]map[string]map[string]utils.StringSet), @@ -2468,26 +2467,29 @@ aa+jqv4dwkr/FLEcN1zC76Y/IniI65fId55hVJvN3ORuzUqYEtzD3irmsw== t.Errorf("Expecting: nil, received: %s", err) } var rply string - if err := sS.BiRPCv1STIRAuthenticate(nil, &V1STIRAuthenticateArgs{ - PayloadMaxDuration: "A", - }, &rply); err == nil { + if err := sS.BiRPCv1STIRAuthenticate(context.Background(), + &V1STIRAuthenticateArgs{ + PayloadMaxDuration: "A", + }, &rply); err == nil { t.Error("Expected error") } - if err := sS.BiRPCv1STIRAuthenticate(nil, &V1STIRAuthenticateArgs{ - DestinationTn: "1003", - Identity: "eyJhbGciOiJFUzI1NiIsInBwdCI6InNoYWtlbiIsInR5cCI6InBhc3Nwb3J0IiwieDV1IjoiaHR0cHM6Ly93d3cuZXhhbXBsZS5vcmcvY2VydC5jZXIifQ.eyJhdHRlc3QiOiJBIiwiZGVzdCI6eyJ0biI6WyIxMDAyIl19LCJpYXQiOjE1ODcwMTk4MjIsIm9yaWciOnsidG4iOiIxMDAxIn0sIm9yaWdpZCI6IjEyMzQ1NiJ9.4ybtWmgqdkNyJLS9Iv3PuJV8ZxR7yZ_NEBhCpKCEu2WBiTchqwoqoWpI17Q_ALm38tbnpay32t95ZY_LhSgwJg;info=;ppt=shaken", - OriginatorTn: "1001", - }, &rply); err == nil { + if err := sS.BiRPCv1STIRAuthenticate(context.Background(), + &V1STIRAuthenticateArgs{ + DestinationTn: "1003", + Identity: "eyJhbGciOiJFUzI1NiIsInBwdCI6InNoYWtlbiIsInR5cCI6InBhc3Nwb3J0IiwieDV1IjoiaHR0cHM6Ly93d3cuZXhhbXBsZS5vcmcvY2VydC5jZXIifQ.eyJhdHRlc3QiOiJBIiwiZGVzdCI6eyJ0biI6WyIxMDAyIl19LCJpYXQiOjE1ODcwMTk4MjIsIm9yaWciOnsidG4iOiIxMDAxIn0sIm9yaWdpZCI6IjEyMzQ1NiJ9.4ybtWmgqdkNyJLS9Iv3PuJV8ZxR7yZ_NEBhCpKCEu2WBiTchqwoqoWpI17Q_ALm38tbnpay32t95ZY_LhSgwJg;info=;ppt=shaken", + OriginatorTn: "1001", + }, &rply); err == nil { t.Error("Expected invalid identity") } - if err := sS.BiRPCv1STIRAuthenticate(nil, &V1STIRAuthenticateArgs{ - Attest: []string{"A"}, - PayloadMaxDuration: "-1", - DestinationTn: "1002", - Identity: "eyJhbGciOiJFUzI1NiIsInBwdCI6InNoYWtlbiIsInR5cCI6InBhc3Nwb3J0IiwieDV1IjoiaHR0cHM6Ly93d3cuZXhhbXBsZS5vcmcvY2VydC5jZXIifQ.eyJhdHRlc3QiOiJBIiwiZGVzdCI6eyJ0biI6WyIxMDAyIl19LCJpYXQiOjE1ODcwMTk4MjIsIm9yaWciOnsidG4iOiIxMDAxIn0sIm9yaWdpZCI6IjEyMzQ1NiJ9.4ybtWmgqdkNyJLS9Iv3PuJV8ZxR7yZ_NEBhCpKCEu2WBiTchqwoqoWpI17Q_ALm38tbnpay32t95ZY_LhSgwJg;info=;ppt=shaken", - OriginatorTn: "1001", - }, &rply); err != nil { + if err := sS.BiRPCv1STIRAuthenticate(context.Background(), + &V1STIRAuthenticateArgs{ + Attest: []string{"A"}, + PayloadMaxDuration: "-1", + DestinationTn: "1002", + Identity: "eyJhbGciOiJFUzI1NiIsInBwdCI6InNoYWtlbiIsInR5cCI6InBhc3Nwb3J0IiwieDV1IjoiaHR0cHM6Ly93d3cuZXhhbXBsZS5vcmcvY2VydC5jZXIifQ.eyJhdHRlc3QiOiJBIiwiZGVzdCI6eyJ0biI6WyIxMDAyIl19LCJpYXQiOjE1ODcwMTk4MjIsIm9yaWciOnsidG4iOiIxMDAxIn0sIm9yaWdpZCI6IjEyMzQ1NiJ9.4ybtWmgqdkNyJLS9Iv3PuJV8ZxR7yZ_NEBhCpKCEu2WBiTchqwoqoWpI17Q_ALm38tbnpay32t95ZY_LhSgwJg;info=;ppt=shaken", + OriginatorTn: "1001", + }, &rply); err != nil { t.Fatal(err) } } @@ -2531,24 +2533,26 @@ aa+jqv4dwkr/FLEcN1zC76Y/IniI65fId55hVJvN3ORuzUqYEtzD3irmsw== } var rcv string - if err := sS.BiRPCv1STIRIdentity(nil, &V1STIRIdentityArgs{ - Payload: payload, - PublicKeyPath: "https://www.example.org/cert.cer", - PrivateKeyPath: "https://www.example.org/private.pem", - OverwriteIAT: true, - }, &rcv); err == nil { + if err := sS.BiRPCv1STIRIdentity(context.Background(), + &V1STIRIdentityArgs{ + Payload: payload, + PublicKeyPath: "https://www.example.org/cert.cer", + PrivateKeyPath: "https://www.example.org/private.pem", + OverwriteIAT: true, + }, &rcv); err == nil { t.Error("Expected error") } if err := engine.Cache.Set(utils.CacheSTIR, "https://www.example.org/private.pem", prvKey, nil, true, utils.NonTransactional); err != nil { t.Errorf("Expecting: nil, received: %s", err) } - if err := sS.BiRPCv1STIRIdentity(nil, &V1STIRIdentityArgs{ - Payload: payload, - PublicKeyPath: "https://www.example.org/cert.cer", - PrivateKeyPath: "https://www.example.org/private.pem", - OverwriteIAT: true, - }, &rcv); err != nil { + if err := sS.BiRPCv1STIRIdentity(context.Background(), + &V1STIRIdentityArgs{ + Payload: payload, + PublicKeyPath: "https://www.example.org/cert.cer", + PrivateKeyPath: "https://www.example.org/private.pem", + OverwriteIAT: true, + }, &rcv); err != nil { t.Error(err) } else if err := AuthStirShaken(rcv, "1001", "", "1002", "", utils.NewStringSet([]string{utils.MetaAny}), -1); err != nil { t.Fatal(err) @@ -2559,7 +2563,7 @@ type mockConnWarnDisconnect1 struct { *testRPCClientConnection } -func (mk *mockConnWarnDisconnect1) Call(method string, args any, rply any) error { +func (mk *mockConnWarnDisconnect1) Call(ctx *context.Context, method string, args any, rply any) error { return utils.ErrNotImplemented } @@ -2567,7 +2571,7 @@ type mockConnWarnDisconnect2 struct { *testRPCClientConnection } -func (mk *mockConnWarnDisconnect2) Call(method string, args any, rply any) error { +func (mk *mockConnWarnDisconnect2) Call(ctx *context.Context, method string, args any, rply any) error { return utils.ErrNoActiveSession } @@ -2597,13 +2601,13 @@ func TestWarnSession(t *testing.T) { type clMock func(_ string, _ any, _ any) error -func (c clMock) Call(m string, a any, r any) error { +func (c clMock) Call(_ *context.Context, m string, a any, r any) error { return c(m, a, r) } func TestInitSession(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} - clientConect := make(chan rpcclient.ClientConnector, 1) + clientConect := make(chan birpc.ClientConnector, 1) clientConect <- clMock(func(_ string, args any, reply any) error { rply, cancast := reply.(*[]*engine.ChrgSProcessEventReply) if !cancast { @@ -2619,7 +2623,7 @@ func TestInitSession(t *testing.T) { } return nil }) - conMng := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + conMng := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): clientConect, }) sS := NewSessionS(cfg, nil, conMng) @@ -2666,17 +2670,13 @@ func TestInitSession(t *testing.T) { } } -func TestSessionSAsBiRPC(t *testing.T) { - _ = rpcclient.BiRPCConector(new(SessionS)) -} - func TestBiJClntID(t *testing.T) { client := &mockConnWarnDisconnect1{} cfg := config.NewDefaultCGRConfig() data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) sessions := NewSessionS(cfg, dm, nil) - sessions.biJClnts = map[rpcclient.ClientConnector]string{ + sessions.biJClnts = map[birpc.ClientConnector]string{ client: "First_connector", } expected := "First_connector" @@ -2720,9 +2720,9 @@ func TestBiRPCv1AuthorizeEventNoTenant(t *testing.T) { return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.Attributes): chanClnt, }) db := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -2749,7 +2749,7 @@ func TestBiRPCv1AuthorizeEventNoTenant(t *testing.T) { rply := &V1AuthorizeReply{ Attributes: new(engine.AttrSProcessEventReply), } - if err := ss.BiRPCv1AuthorizeEvent(nil, args, + if err := ss.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err != nil { t.Error(err) } @@ -2790,9 +2790,9 @@ func TestBiRPCv1AuthorizeEventWithDigestNoTenant(t *testing.T) { return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.Attributes): chanClnt, }) db := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -2817,7 +2817,7 @@ func TestBiRPCv1AuthorizeEventWithDigestNoTenant(t *testing.T) { } rply := &V1AuthorizeReplyWithDigest{} - if err := ss.BiRPCv1AuthorizeEventWithDigest(nil, args, + if err := ss.BiRPCv1AuthorizeEventWithDigest(context.Background(), args, rply); err != nil { t.Error(err) } @@ -2858,9 +2858,9 @@ func TestBiRPCv1InitiateSessionNoTenant(t *testing.T) { return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.Attributes): chanClnt, }) db := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -2886,7 +2886,7 @@ func TestBiRPCv1InitiateSessionNoTenant(t *testing.T) { reply := &V1InitSessionReply{ Attributes: new(engine.AttrSProcessEventReply), } - if err := ss.BiRPCv1InitiateSession(nil, args, reply); err != nil { + if err := ss.BiRPCv1InitiateSession(context.Background(), args, reply); err != nil { t.Error(err) } } @@ -2925,9 +2925,9 @@ func TestBiRPCv1InitiateSessionWithDigestNoTenant(t *testing.T) { } return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.Attributes): chanClnt, }) db := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -2951,7 +2951,7 @@ func TestBiRPCv1InitiateSessionWithDigestNoTenant(t *testing.T) { }, } reply := &V1InitReplyWithDigest{} - if err := ss.BiRPCv1InitiateSessionWithDigest(nil, args, reply); err != nil { + if err := ss.BiRPCv1InitiateSessionWithDigest(context.Background(), args, reply); err != nil { t.Error(err) } } @@ -2990,9 +2990,9 @@ func TestBiRPCv1UpdateSessionNoTenant(t *testing.T) { } return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.Attributes): chanClnt, }) db := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -3016,7 +3016,7 @@ func TestBiRPCv1UpdateSessionNoTenant(t *testing.T) { }, } rply := &V1UpdateSessionReply{} - if err := ss.BiRPCv1UpdateSession(nil, args, rply); err != nil { + if err := ss.BiRPCv1UpdateSession(context.Background(), args, rply); err != nil { t.Error(err) } } @@ -3040,9 +3040,9 @@ func TestBiRPCv1TerminateSessionNoTenant(t *testing.T) { *rply = []*engine.ChrgSProcessEventReply{} return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanClnt, }) db := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -3066,7 +3066,7 @@ func TestBiRPCv1TerminateSessionNoTenant(t *testing.T) { }, } var reply string - if err := ss.BiRPCv1TerminateSession(nil, args, + if err := ss.BiRPCv1TerminateSession(context.Background(), args, &reply); err != nil { t.Error(err) } @@ -3106,9 +3106,9 @@ func TestBiRPCv1ProcessMessageNoTenant(t *testing.T) { } return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.Attributes): chanClnt, }) db := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -3174,9 +3174,9 @@ func TestBiRPCv1ProcessEventNoTenant(t *testing.T) { } return nil }) - chanClnt := make(chan rpcclient.ClientConnector, 1) + chanClnt := make(chan birpc.ClientConnector, 1) chanClnt <- clMock - connMngr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMngr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.Attributes): chanClnt, }) db := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -3202,7 +3202,7 @@ func TestBiRPCv1ProcessEventNoTenant(t *testing.T) { reply := &V1ProcessEventReply{ Attributes: make(map[string]*engine.AttrSProcessEventReply), } - if err := ss.BiRPCv1ProcessEvent(nil, args, reply); err != nil { + if err := ss.BiRPCv1ProcessEvent(context.Background(), args, reply); err != nil { t.Error(err) } } diff --git a/sessions/sessions_voice_it_test.go b/sessions/sessions_voice_it_test.go index d51ddb349..e28313ac8 100644 --- a/sessions/sessions_voice_it_test.go +++ b/sessions/sessions_voice_it_test.go @@ -22,11 +22,12 @@ package sessions import ( "fmt" - "net/rpc" "path" "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -36,7 +37,7 @@ var ( voiceCfgPath string voiceCfgDIR string voiceCfg *config.CGRConfig - sessionsRPC *rpc.Client + sessionsRPC *birpc.Client sessionsVoiceTests = []func(t *testing.T){ testSessionsVoiceInitCfg, @@ -120,7 +121,7 @@ func testSessionsVoiceApierRpcConn(t *testing.T) { func testSessionsVoiceTPFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")} var loadInst utils.LoadInstance - if err := sessionsRPC.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -151,7 +152,7 @@ func testSessionsVoiceMonetaryRefund(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -161,7 +162,7 @@ func testSessionsVoiceMonetaryRefund(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 8.700010 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -191,12 +192,12 @@ func testSessionsVoiceMonetaryRefund(t *testing.T) { } var rpl string - if err := sessionsRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } eAcntVal = 8.8 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -228,7 +229,7 @@ func testSessionsVoiceVoiceRefund(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -239,7 +240,7 @@ func testSessionsVoiceVoiceRefund(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 120.0 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", @@ -270,12 +271,12 @@ func testSessionsVoiceVoiceRefund(t *testing.T) { } var rpl string - if err := sessionsRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } eAcntVal = 150.0 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) @@ -285,7 +286,7 @@ func testSessionsVoiceVoiceRefund(t *testing.T) { func testSessionsVoiceMixedRefund(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } @@ -313,7 +314,7 @@ func testSessionsVoiceMixedRefund(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -325,7 +326,7 @@ func testSessionsVoiceMixedRefund(t *testing.T) { //attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eVoiceVal := 90.0 * float64(time.Second) eMoneyVal := 8.7399 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eVoiceVal || acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eMoneyVal { @@ -358,13 +359,13 @@ func testSessionsVoiceMixedRefund(t *testing.T) { } var rpl string - if err := sessionsRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } eVoiceVal = 90.0 * float64(time.Second) eMoneyVal = 8.79 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eVoiceVal || acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eMoneyVal { @@ -380,7 +381,7 @@ func testSessionsVoiceLastUsed(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 8.790000 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -410,7 +411,7 @@ func testSessionsVoiceLastUsed(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -419,7 +420,7 @@ func testSessionsVoiceLastUsed(t *testing.T) { } eAcntVal = 7.39002 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -448,7 +449,7 @@ func testSessionsVoiceLastUsed(t *testing.T) { } var updateRpl *V1UpdateSessionReply - if err := sessionsRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } if updateRpl.MaxUsage == nil || *updateRpl.MaxUsage != usage { @@ -456,7 +457,7 @@ func testSessionsVoiceLastUsed(t *testing.T) { } eAcntVal = 7.09005 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -486,7 +487,7 @@ func testSessionsVoiceLastUsed(t *testing.T) { }, } - if err := sessionsRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } if updateRpl.MaxUsage == nil || *updateRpl.MaxUsage != usage { @@ -494,7 +495,7 @@ func testSessionsVoiceLastUsed(t *testing.T) { } eAcntVal = 6.590100 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -524,12 +525,12 @@ func testSessionsVoiceLastUsed(t *testing.T) { } var rpl string - if err := sessionsRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } eAcntVal = 7.59 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", @@ -541,7 +542,7 @@ func testSessionsVoiceLastUsedEnd(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 7.59000 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -571,7 +572,7 @@ func testSessionsVoiceLastUsedEnd(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -580,7 +581,7 @@ func testSessionsVoiceLastUsedEnd(t *testing.T) { } eAcntVal = 6.190020 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -609,7 +610,7 @@ func testSessionsVoiceLastUsedEnd(t *testing.T) { } var updateRpl *V1UpdateSessionReply - if err := sessionsRPC.Call(utils.SessionSv1UpdateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } @@ -618,7 +619,7 @@ func testSessionsVoiceLastUsedEnd(t *testing.T) { } eAcntVal = 6.090030 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", @@ -646,12 +647,12 @@ func testSessionsVoiceLastUsedEnd(t *testing.T) { } var rpl string - if err := sessionsRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } eAcntVal = 6.590000 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", @@ -663,7 +664,7 @@ func testSessionsVoiceLastUsedNotFixed(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 6.59000 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -693,7 +694,7 @@ func testSessionsVoiceLastUsedNotFixed(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -702,7 +703,7 @@ func testSessionsVoiceLastUsedNotFixed(t *testing.T) { } eAcntVal = 5.190020 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -732,7 +733,7 @@ func testSessionsVoiceLastUsedNotFixed(t *testing.T) { } var updateRpl *V1UpdateSessionReply - if err := sessionsRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } if updateRpl.MaxUsage == nil || *updateRpl.MaxUsage != usage { @@ -740,7 +741,7 @@ func testSessionsVoiceLastUsedNotFixed(t *testing.T) { } eAcntVal = 5.123360 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", @@ -768,12 +769,12 @@ func testSessionsVoiceLastUsedNotFixed(t *testing.T) { } var rpl string - if err := sessionsRPC.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } eAcntVal = 5.590000 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", @@ -785,7 +786,7 @@ func testSessionsVoiceSessionTTL(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"} eAcntVal := 5.590000 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", @@ -816,7 +817,7 @@ func testSessionsVoiceSessionTTL(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -827,7 +828,7 @@ func testSessionsVoiceSessionTTL(t *testing.T) { } var aSessions []*ExternalSession - if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -838,7 +839,7 @@ func testSessionsVoiceSessionTTL(t *testing.T) { err.Error() != utils.ErrNotFound.Error() { t.Error(err, aSessions) } - if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -853,7 +854,7 @@ func testSessionsVoiceSessionTTL(t *testing.T) { } eAcntVal = 4.190020 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -883,7 +884,7 @@ func testSessionsVoiceSessionTTL(t *testing.T) { } var updateRpl *V1UpdateSessionReply - if err := sessionsRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Fatal(err) } time.Sleep(10 * time.Millisecond) @@ -891,7 +892,7 @@ func testSessionsVoiceSessionTTL(t *testing.T) { t.Errorf("Expected: %+v, received: %+v", usage, updateRpl.MaxUsage) } - if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -906,14 +907,14 @@ func testSessionsVoiceSessionTTL(t *testing.T) { } eAcntVal = 4.090030 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) } time.Sleep(200 * time.Millisecond) eAcntVal = 4.0566 // rounding issue; old values : 4.0565 , 4.0566 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue()) @@ -921,7 +922,7 @@ func testSessionsVoiceSessionTTL(t *testing.T) { var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, DestinationPrefixes: []string{"1008"}} - if err := sessionsRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -947,7 +948,7 @@ func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { }, } var reply string - if err := sessionsRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -958,7 +959,7 @@ func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { Account: attrSetBalance.Account, } eAcntVal := 300.0 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %f, received: %f", @@ -989,7 +990,7 @@ func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -999,7 +1000,7 @@ func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { } var aSessions []*ExternalSession - if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -1013,7 +1014,7 @@ func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { t.Errorf("Expecting 2m, received usage: %v", aSessions[0].Usage) } eAcntVal = 180.0 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %f, received: %f", @@ -1047,7 +1048,7 @@ func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { } var updateRpl *V1UpdateSessionReply - if err := sessionsRPC.Call(utils.SessionSv1UpdateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } @@ -1056,7 +1057,7 @@ func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { } time.Sleep(20 * time.Millisecond) - if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -1070,7 +1071,7 @@ func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { t.Errorf("Expecting 2m30s, received usage: %v", aSessions[0].Usage) } eAcntVal = 150.0 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %f, received: %f", @@ -1079,13 +1080,13 @@ func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { time.Sleep(200 * time.Millisecond) // should trigger the TTL from config eAcntVal = 149.95 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) } - if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -1097,7 +1098,7 @@ func testSessionsVoiceSessionTTLWithRelocate(t *testing.T) { time.Sleep(100 * time.Millisecond) var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, DestinationPrefixes: []string{"1009"}} - if err := sessionsRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -1120,7 +1121,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { }, } var reply string - if err := sessionsRPC.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received: %s", reply) @@ -1131,7 +1132,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { Account: attrSetBalance.Account, } eAcntVal := 300.0 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %f, received: %f", eAcntVal, @@ -1162,7 +1163,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { } var initRpl *V1InitSessionReply - if err := sessionsRPC.Call(utils.SessionSv1InitiateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1InitiateSession, initArgs, &initRpl); err != nil { t.Error(err) } @@ -1172,7 +1173,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { time.Sleep(20 * time.Millisecond) var aSessions []*ExternalSession - if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -1186,7 +1187,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { t.Errorf("Expecting 2m, received usage: %v", aSessions[0].Usage) } eAcntVal = 180.0 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %f, received: %f", eAcntVal, @@ -1220,7 +1221,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { } var updateRpl *V1UpdateSessionReply - if err := sessionsRPC.Call(utils.SessionSv1UpdateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil { t.Error(err) } @@ -1229,7 +1230,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { } time.Sleep(20 * time.Millisecond) - if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -1243,7 +1244,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { t.Errorf("Expecting 2m30s, received usage: %v", aSessions[0].Usage) } eAcntVal = 150.0 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expecting: %f, received: %f", @@ -1273,13 +1274,13 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { } var rpl string - if err := sessionsRPC.Call(utils.SessionSv1TerminateSession, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK { t.Error(err) } time.Sleep(10 * time.Millisecond) - if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions, + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1GetActiveSessions, utils.SessionFilter{ Filters: []string{ fmt.Sprintf("*string:~*req.%s:%s", utils.RunID, utils.MetaDefault), @@ -1290,7 +1291,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { t.Error(err, aSessions) } eAcntVal = 240 * float64(time.Second) - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { @@ -1298,7 +1299,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { eAcntVal, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) } - if err := sessionsRPC.Call(utils.SessionSv1ProcessCDR, termArgs.CGREvent, &reply); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.SessionSv1ProcessCDR, termArgs.CGREvent, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Received reply: %s", reply) @@ -1307,7 +1308,7 @@ func testSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) { var cdrs []*engine.ExternalCDR req := utils.RPCCDRsFilter{RunIDs: []string{utils.MetaDefault}, DestinationPrefixes: []string{"12371"}} - if err := sessionsRPC.Call(utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { + if err := sessionsRPC.Call(context.Background(), utils.APIerSv2GetCDRs, &req, &cdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } else if len(cdrs) != 1 { t.Error("Unexpected number of CDRs returned: ", len(cdrs)) @@ -1324,7 +1325,7 @@ func TestSMGDataDerivedChargingNoCredit(t *testing.T) { var acnt *engine.Account attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1011"} eAcntVal := 50000.0 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(),utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) @@ -1344,7 +1345,7 @@ func TestSMGDataDerivedChargingNoCredit(t *testing.T) { utils.Usage: "100", } var maxUsage float64 - if err := sessionsRPC.Call(utils.SMGenericV2InitiateSession, smgEv, &maxUsage); err != nil { + if err := sessionsRPC.Call(context.Background(),utils.SMGenericV2InitiateSession, smgEv, &maxUsage); err != nil { t.Error(err) } // the second derived charging run has no credit @@ -1353,7 +1354,7 @@ func TestSMGDataDerivedChargingNoCredit(t *testing.T) { t.Error("Bad max usage: ", maxUsage) } eAcntVal = 50000.0 - if err := sessionsRPC.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil { + if err := sessionsRPC.Call(context.Background(),utils.APIerSv2GetAccount, attrs, &acnt); err != nil { t.Error(err) } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal { t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaVoice].GetTotalValue()) diff --git a/sessions/sessionscover_test.go b/sessions/sessionscover_test.go index a1e634712..da7dd25da 100644 --- a/sessions/sessionscover_test.go +++ b/sessions/sessionscover_test.go @@ -29,6 +29,8 @@ import ( "testing" "time" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/context" "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" @@ -280,7 +282,7 @@ func TestForceSTerminatorPostCDRs(t *testing.T) { cfg.SessionSCfg().CDRsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs): nil, }) sessions := NewSessionS(cfg, dm, connMgr) @@ -317,7 +319,7 @@ func TestForceSTerminatorReleaseSession(t *testing.T) { cfg.SessionSCfg().ResSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): nil, }) sessions := NewSessionS(cfg, dm, connMgr) @@ -354,7 +356,7 @@ type testMockClientConn struct { *testRPCClientConnection } -func (sT *testMockClientConn) Call(method string, arg any, rply any) error { +func (sT *testMockClientConn) Call(ctx *context.Context, method string, arg any, rply any) error { return utils.ErrNoActiveSession } @@ -366,7 +368,7 @@ func TestForceSTerminatorClientCall(t *testing.T) { cfg.GeneralCfg().NodeID = "ClientConnID" data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): nil, }) sessions := NewSessionS(cfg, dm, connMgr) @@ -455,7 +457,7 @@ type testMockClients struct { calls map[string]func(args any, reply any) error } -func (sT *testMockClients) Call(method string, arg any, rply any) error { +func (sT *testMockClients) Call(ctx *context.Context, method string, arg any, rply any) error { if call, has := sT.calls[method]; !has { return rpcclient.ErrUnsupporteServiceMethod } else { @@ -482,13 +484,13 @@ func TestDebitSessionResponderMaxDebit(t *testing.T) { }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): sMock, }) @@ -550,13 +552,13 @@ func TestDebitSessionResponderMaxDebitError(t *testing.T) { }, } - internalRpcChan := make(chan rpcclient.ClientConnector, 1) + internalRpcChan := make(chan birpc.ClientConnector, 1) internalRpcChan <- sMock cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} cfg.SessionSCfg().SchedulerConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaScheduler)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): internalRpcChan, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaScheduler): internalRpcChan}) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -593,9 +595,9 @@ func TestDebitSessionResponderMaxDebitError(t *testing.T) { sMock.calls[utils.SchedulerSv1ExecuteActionPlans] = func(args any, reply any) error { return utils.ErrNotImplemented } - newInternalRpcChan := make(chan rpcclient.ClientConnector, 1) + newInternalRpcChan := make(chan birpc.ClientConnector, 1) newInternalRpcChan <- sMock - connMgr = engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr = engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): internalRpcChan, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaScheduler): internalRpcChan}) dm = engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -648,7 +650,7 @@ type testMockClientConnDiscSess struct { *testRPCClientConnection } -func (sT *testMockClientConnDiscSess) Call(method string, arg any, rply any) error { +func (sT *testMockClientConnDiscSess) Call(ctx *context.Context, method string, arg any, rply any) error { return nil } @@ -703,9 +705,9 @@ func TestDebitLoopSessionErrorDebiting(t *testing.T) { }, }, } - internalRpcChan := make(chan rpcclient.ClientConnector, 1) + internalRpcChan := make(chan birpc.ClientConnector, 1) internalRpcChan <- sMock - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): internalRpcChan, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaScheduler): internalRpcChan}) dm = engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -738,13 +740,13 @@ func TestDebitLoopSession(t *testing.T) { }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): sMock, }) @@ -801,13 +803,13 @@ func TestDebitLoopSessionFrcDiscLowerDbtInterval(t *testing.T) { }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): sMock, }) @@ -854,14 +856,14 @@ func TestDebitLoopSessionLowBalance(t *testing.T) { }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} cfg.SessionSCfg().MinDurLowBalance = 1 * time.Second data := engine.NewInternalDB(nil, nil, true,cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): sMock, }) @@ -916,7 +918,7 @@ func TestDebitLoopSessionWarningSessions(t *testing.T) { }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} @@ -924,7 +926,7 @@ func TestDebitLoopSessionWarningSessions(t *testing.T) { cfg.SessionSCfg().MinDurLowBalance = 1 * time.Second data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): sMock, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): sMock}) @@ -973,7 +975,7 @@ func TestDebitLoopSessionDisconnectSession(t *testing.T) { }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() cfg.GeneralCfg().NodeID = "ClientConnID" @@ -982,7 +984,7 @@ func TestDebitLoopSessionDisconnectSession(t *testing.T) { cfg.SessionSCfg().MinDurLowBalance = 1 * time.Second data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): sMock, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): sMock}) @@ -1040,13 +1042,13 @@ func TestStoreSCost(t *testing.T) { }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().CDRsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs): sMock}) sessions := NewSessionS(cfg, dm, connMgr) @@ -1095,13 +1097,13 @@ func TestRefundSession(t *testing.T) { }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): sMock}) sessions := NewSessionS(cfg, dm, connMgr) @@ -1200,13 +1202,13 @@ func TestRoundCost(t *testing.T) { }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): sMock}) sessions := NewSessionS(cfg, dm, connMgr) @@ -1312,13 +1314,13 @@ func TestReplicateSessions(t *testing.T) { }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().ReplicationConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): sMock}) sessions := NewSessionS(cfg, dm, connMgr) @@ -1351,11 +1353,11 @@ func TestNewSession(t *testing.T) { }, }, } - sMock := make(chan rpcclient.ClientConnector, 1) + sMock := make(chan birpc.ClientConnector, 1) sMock <- testMock1 cfg := config.NewDefaultCGRConfig() data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): sMock}) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -1433,8 +1435,8 @@ func TestProcessChargerS(t *testing.T) { cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheEventCharges].Limit = -1 - sMock := make(chan rpcclient.ClientConnector, 1) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + sMock := make(chan birpc.ClientConnector, 1) + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): sMock}) dm := engine.NewDataManager(engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items), cfg.CacheCfg(), connMgr) engine.Cache = engine.NewCacheS(cfg, dm, nil) @@ -1477,7 +1479,7 @@ func TestProcessChargerS(t *testing.T) { } cacheS := engine.NewCacheS(cfg, nil, nil) engine.Cache = cacheS - connMgr = engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr = engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): sMock}) engine.SetConnManager(connMgr) @@ -1612,7 +1614,7 @@ func TestLibsessionsSetMockErrors(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- sTestMock cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().ReplicationConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} @@ -1621,7 +1623,7 @@ func TestLibsessionsSetMockErrors(t *testing.T) { } cacheS := engine.NewCacheS(cfg, nil, nil) engine.Cache = cacheS - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): chanInternal}) engine.SetConnManager(connMgr) @@ -1655,7 +1657,7 @@ type testMockClientSyncSessions struct { *testRPCClientConnection } -func (sT *testMockClientSyncSessions) Call(method string, arg any, rply any) error { +func (sT *testMockClientSyncSessions) Call(ctx *context.Context, method string, arg any, rply any) error { queriedSessionIDs := []*SessionID{ { OriginID: "ORIGIN_ID", @@ -1682,7 +1684,7 @@ func TestSyncSessions(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- sTestMock cfg := config.NewDefaultCGRConfig() //cfg.GeneralCfg().ReplyTimeout = 1 @@ -1692,7 +1694,7 @@ func TestSyncSessions(t *testing.T) { Replicate: true, } data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): chanInternal}) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) sessions := NewSessionS(cfg, dm, connMgr) @@ -1711,7 +1713,7 @@ func TestSyncSessions(t *testing.T) { sessions.cgrCfg.GeneralCfg().ReplyTimeout = 1 cacheS := engine.NewCacheS(cfg, nil, nil) engine.Cache = cacheS - connMgr = engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr = engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): chanInternal}) engine.SetConnManager(connMgr) sessions.aSessions = map[string]*Session{ @@ -1719,7 +1721,7 @@ func TestSyncSessions(t *testing.T) { } var reply string - if err := sessions.BiRPCv1SyncSessions(nil, nil, &reply); err != nil { + if err := sessions.BiRPCv1SyncSessions(context.Background(), nil, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected to be OK") @@ -1757,12 +1759,12 @@ func TestAuthEvent(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- sTestMock cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal}) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -1830,11 +1832,11 @@ func TestAuthEventMockCall(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- sTestMock cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal}) data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) @@ -1904,14 +1906,14 @@ func TestChargeEvent(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- sTestMock cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().ReplicationConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} cfg.CacheCfg().Partitions[utils.CacheClosedSessions] = &config.CacheParamCfg{ Replicate: true, } - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, }) @@ -1936,7 +1938,7 @@ func TestChargeEvent(t *testing.T) { cacheS := engine.NewCacheS(cfg, nil, nil) engine.Cache = cacheS - connMgr = engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr = engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): chanInternal}) engine.SetConnManager(connMgr) @@ -2021,12 +2023,12 @@ func TestEndSession(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- sTestMock cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} cfg.SessionSCfg().CDRsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs)} - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs): chanInternal, }) @@ -2110,35 +2112,6 @@ func TestEndSession(t *testing.T) { } } -func TestCallBiRPC(t *testing.T) { - log.SetOutput(io.Discard) - cfg := config.NewDefaultCGRConfig() - data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) - sessions := NewSessionS(cfg, dm, nil) - - sTestMock := &testMockClients{} - valid := "BiRPCv1TerminateSession" - args := new(V1TerminateSessionArgs) - var reply *string - - if err := sessions.CallBiRPC(sTestMock, valid, args, reply); err == nil || err != rpcclient.ErrUnsupporteServiceMethod { - t.Errorf("Expected %+v, received %+v", rpcclient.ErrUnsupporteServiceMethod, err) - } - - valid = "BiRPC.TerminateSession" - if err := sessions.CallBiRPC(sTestMock, valid, args, reply); err == nil || err != rpcclient.ErrUnsupporteServiceMethod { - t.Errorf("Expected %+v, received %+v", rpcclient.ErrUnsupporteServiceMethod, err) - } - - valid = "BiRPCv1.TerminateSession" - expected := "MANDATORY_IE_MISSING: [CGREvent]" - if err := sessions.Call(valid, args, reply); err == nil || err.Error() != expected { - t.Errorf("Expected %+v, received %+v", expected, err) - } - -} - func TestBiRPCv1GetActivePassiveSessions(t *testing.T) { log.SetOutput(io.Discard) clnt := &testMockClients{} @@ -2151,8 +2124,9 @@ func TestBiRPCv1GetActivePassiveSessions(t *testing.T) { dm := engine.NewDataManager(data, cfg.CacheCfg(), nil) sessions := NewSessionS(cfg, dm, nil) + ctx := context.WithClient(context.Background(), clnt) var reply []*ExternalSession - if err := sessions.BiRPCv1GetActiveSessions(clnt, nil, &reply); err == nil || err != utils.ErrNotFound { + if err := sessions.BiRPCv1GetActiveSessions(ctx, nil, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err) } @@ -2243,7 +2217,7 @@ func TestBiRPCv1GetActivePassiveSessions(t *testing.T) { } args := &utils.SessionFilter{Filters: []string{fmt.Sprintf("*string:~*req.ToR:%s|%s", utils.MetaVoice, utils.MetaData)}} - if err := sessions.BiRPCv1GetActiveSessions(clnt, args, &reply); err != nil { + if err := sessions.BiRPCv1GetActiveSessions(ctx, args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(expSess, reply) { t.Errorf("Expected %s , received: %s", utils.ToJSON(expSess), utils.ToJSON(reply)) @@ -2251,13 +2225,13 @@ func TestBiRPCv1GetActivePassiveSessions(t *testing.T) { var newReply1 int //nil args, but it will be an empty SessionFilter - if err := sessions.BiRPCv1GetActiveSessionsCount(clnt, nil, &newReply1); err != nil { + if err := sessions.BiRPCv1GetActiveSessionsCount(ctx, nil, &newReply1); err != nil { t.Error(err) } else if newReply1 != 2 { t.Errorf("Expected %+v, received: %+v", 2, newReply1) } - if err := sessions.BiRPCv1GetActiveSessionsCount(clnt, args, &newReply1); err != nil { + if err := sessions.BiRPCv1GetActiveSessionsCount(ctx, args, &newReply1); err != nil { t.Error(err) } else if newReply1 != 1 { t.Errorf("Expected %+v, received: %+v", 1, newReply1) @@ -2265,7 +2239,7 @@ func TestBiRPCv1GetActivePassiveSessions(t *testing.T) { //Passive session reply = []*ExternalSession{} - if err := sessions.BiRPCv1GetPassiveSessions(clnt, nil, &reply); err == nil || err != utils.ErrNotFound { + if err := sessions.BiRPCv1GetPassiveSessions(ctx, nil, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err) } @@ -2288,13 +2262,13 @@ func TestBiRPCv1GetActivePassiveSessions(t *testing.T) { ExtraFields: map[string]string{}, }, } - if err := sessions.BiRPCv1GetPassiveSessions(clnt, args, &reply); err != nil { + if err := sessions.BiRPCv1GetPassiveSessions(ctx, args, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(reply, expSess) { t.Errorf("Expected %+v\n, received: %+v", utils.ToJSON(expSess), utils.ToJSON(reply)) } - if err := sessions.BiRPCv1GetPassiveSessionsCount(clnt, nil, &newReply1); err != nil { + if err := sessions.BiRPCv1GetPassiveSessionsCount(ctx, nil, &newReply1); err != nil { t.Error(err) } } @@ -2314,14 +2288,15 @@ func TestBiRPCv1SetPassiveSession(t *testing.T) { SRuns: []*SRun{}, } expected := "MANDATORY_IE_MISSING: [CGRID]" - if err := sessions.BiRPCv1SetPassiveSession(clnt, ss, &reply); err == nil || err.Error() != expected { + ctx := context.WithClient(context.Background(), clnt) + if err := sessions.BiRPCv1SetPassiveSession(ctx, ss, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v\n, received: %+v", expected, err) } else if reply != utils.EmptyString { t.Errorf("Expected %+v\n, received: %+v", utils.EmptyString, err) } ss.CGRID = "CGR_ID" - if err := sessions.BiRPCv1SetPassiveSession(clnt, ss, &reply); err == nil || err != utils.ErrNotFound { + if err := sessions.BiRPCv1SetPassiveSession(ctx, ss, &reply); err == nil || err != utils.ErrNotFound { t.Errorf("Expected %+v\n, received: %+v", utils.ErrNotFound, err) } else if reply != utils.EmptyString { t.Errorf("Expected %+v\n, received: %+v", utils.EmptyString, err) @@ -2330,7 +2305,7 @@ func TestBiRPCv1SetPassiveSession(t *testing.T) { sessions.pSessions = map[string]*Session{ "CGR_ID": ss, } - if err := sessions.BiRPCv1SetPassiveSession(clnt, ss, &reply); err != nil { + if err := sessions.BiRPCv1SetPassiveSession(ctx, ss, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected %+v\n, received: %+v", utils.OK, err) @@ -2340,7 +2315,7 @@ func TestBiRPCv1SetPassiveSession(t *testing.T) { "CGR_ID": ss, } ss.EventStart = engine.MapEvent{} - if err := sessions.BiRPCv1SetPassiveSession(clnt, ss, &reply); err != nil { + if err := sessions.BiRPCv1SetPassiveSession(ctx, ss, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected %+v\n, received: %+v", utils.OK, err) @@ -2357,11 +2332,11 @@ func TestBiRPCv1ReplicateSessions(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ "conn1": chanInternal, }) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -2373,13 +2348,14 @@ func TestBiRPCv1ReplicateSessions(t *testing.T) { ConnIDs: []string{}, } + ctx := context.WithClient(context.Background(), clnt) var reply string - if err := sessions.BiRPCv1ReplicateSessions(clnt, args, &reply); err != nil { + if err := sessions.BiRPCv1ReplicateSessions(ctx, args, &reply); err != nil { t.Error(err) } args.ConnIDs = []string{"conn1"} - if err := sessions.BiRPCv1ReplicateSessions(clnt, args, &reply); err != nil { + if err := sessions.BiRPCv1ReplicateSessions(ctx, args, &reply); err != nil { t.Error(err) } } @@ -2404,11 +2380,11 @@ func TestBiRPCv1AuthorizeEvent(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanInternal, }) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -2432,7 +2408,7 @@ func TestBiRPCv1AuthorizeEvent(t *testing.T) { } expected := "MANDATORY_IE_MISSING: [CGREvent]" - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -2450,12 +2426,12 @@ func TestBiRPCv1AuthorizeEvent(t *testing.T) { engine.Cache = caches caches.SetWithoutReplicate(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.SessionSv1AuthorizeEvent, args.CGREvent.ID), value, nil, true, utils.NonTransactional) - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err != nil { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err != nil { t.Error(err) } engine.Cache = tmp - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -2468,13 +2444,13 @@ func TestBiRPCv1AuthorizeEvent(t *testing.T) { args.CGREvent.Tenant = "cgrates.org" expected = "ATTRIBUTES_ERROR:NOT_CONNECTED: AttributeS" - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } expected = "NOT_CONNECTED: RouteS" sessions.cgrCfg.SessionSCfg().AttrSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -2520,12 +2496,12 @@ func TestBiRPCv1AuthorizeEvent2(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 0 data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRoutes): chanInternal, @@ -2554,13 +2530,13 @@ func TestBiRPCv1AuthorizeEvent2(t *testing.T) { //GetMaxUsage expected := "ChargerS is disabled" - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } args.CGREvent.ID = "TestID" sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err != nil { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err != nil { t.Error(err) } @@ -2569,18 +2545,18 @@ func TestBiRPCv1AuthorizeEvent2(t *testing.T) { false, []string{}, false, []string{}, true, false, false, false, false, cgrEvent, utils.Paginator{}, false, "") expected = "NOT_CONNECTED: ResourceS" - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().ResSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err != nil { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err != nil { t.Error(err) } args.CGREvent.Tenant = "new_tenant" expected = "RESOURCES_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -2589,12 +2565,12 @@ func TestBiRPCv1AuthorizeEvent2(t *testing.T) { false, []string{}, false, []string{}, false, false, true, false, false, cgrEvent, utils.Paginator{}, false, "") expected = "NOT_CONNECTED: RouteS" - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().RouteSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRoutes)} - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err != nil { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err != nil { t.Error(err) } @@ -2602,7 +2578,7 @@ func TestBiRPCv1AuthorizeEvent2(t *testing.T) { args = NewV1AuthorizeArgs(false, []string{}, true, []string{"TestID"}, false, []string{}, false, false, true, false, false, cgrEvent, utils.Paginator{}, false, "") - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err == nil || err != utils.ErrPartiallyExecuted { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err == nil || err != utils.ErrPartiallyExecuted { t.Errorf("Expected %+v, received %+v", utils.ErrPartiallyExecuted, err) } @@ -2610,7 +2586,7 @@ func TestBiRPCv1AuthorizeEvent2(t *testing.T) { args = NewV1AuthorizeArgs(false, []string{}, false, []string{}, true, []string{"TestID"}, false, false, true, false, false, cgrEvent, utils.Paginator{}, false, "") - if err := sessions.BiRPCv1AuthorizeEvent(nil, args, rply); err == nil || err != utils.ErrPartiallyExecuted { + if err := sessions.BiRPCv1AuthorizeEvent(context.Background(), args, rply); err == nil || err != utils.ErrPartiallyExecuted { t.Errorf("Expected %+v, received %+v", utils.ErrPartiallyExecuted, err) } } @@ -2672,7 +2648,7 @@ func TestBiRPCv1AuthorizeEventWithDigest(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().AttrSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} @@ -2683,7 +2659,7 @@ func TestBiRPCv1AuthorizeEventWithDigest(t *testing.T) { cfg.SessionSCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)} cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 0 data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRoutes): chanInternal, @@ -2714,7 +2690,7 @@ func TestBiRPCv1AuthorizeEventWithDigest(t *testing.T) { Thresholds: utils.StringPointer(utils.EmptyString), StatQueues: utils.StringPointer(utils.EmptyString), } - if err := sessions.BiRPCv1AuthorizeEventWithDigest(nil, args, authReply); err != nil { + if err := sessions.BiRPCv1AuthorizeEventWithDigest(context.Background(), args, authReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(authReply, expectedRply) { t.Errorf("Expected %+v, received %+v", utils.ToJSON(expectedRply), utils.ToJSON(authReply)) @@ -2722,7 +2698,7 @@ func TestBiRPCv1AuthorizeEventWithDigest(t *testing.T) { sessions.cgrCfg.SessionSCfg().ChargerSConns = nil expected := "ChargerS is disabled" - if err := sessions.BiRPCv1AuthorizeEventWithDigest(nil, args, authReply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1AuthorizeEventWithDigest(context.Background(), args, authReply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -2783,7 +2759,7 @@ func TestBiRPCv1InitiateSession1(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 @@ -2791,7 +2767,7 @@ func TestBiRPCv1InitiateSession1(t *testing.T) { cfg.SessionSCfg().ResSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} cfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanInternal, @@ -2812,12 +2788,12 @@ func TestBiRPCv1InitiateSession1(t *testing.T) { rply := &V1InitSessionReply{} expected := "MANDATORY_IE_MISSING: [CGREvent]" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } args.CGREvent = cgrEvent - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err != nil { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err != nil { t.Error(err) } @@ -2836,7 +2812,7 @@ func TestBiRPCv1InitiateSession1(t *testing.T) { engine.Cache = caches engine.Cache.SetWithoutReplicate(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.SessionSv1InitiateSession, args.CGREvent.ID), value, nil, true, utils.NonTransactional) - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err != nil { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err != nil { t.Error(err) } engine.Cache = tmp @@ -2844,7 +2820,7 @@ func TestBiRPCv1InitiateSession1(t *testing.T) { args.CGREvent.Tenant = utils.EmptyString args.AttributeIDs = []string{"attr1"} expected = "ATTRIBUTES_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -2852,7 +2828,7 @@ func TestBiRPCv1InitiateSession1(t *testing.T) { args.AttributeIDs = []string{} sessions.cgrCfg.SessionSCfg().ResSConns = []string{} expected = "NOT_CONNECTED: ResourceS" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().ResSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} @@ -2862,7 +2838,7 @@ func TestBiRPCv1InitiateSession1(t *testing.T) { cgrEvent, true) delete(args.CGREvent.Event, utils.OriginID) expected = "MANDATORY_IE_MISSING: [OriginID]" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -2878,7 +2854,7 @@ func TestBiRPCv1InitiateSession1(t *testing.T) { false, []string{}, false, []string{}, true, false, cgrEvent, true) expected = "RESOURCES_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -2887,7 +2863,7 @@ func TestBiRPCv1InitiateSession1(t *testing.T) { false, []string{}, false, []string{}, false, false, cgrEvent, true) expected = "MANDATORY_IE_MISSING: [subsystems]" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -2926,14 +2902,14 @@ func TestBiRPCv1InitiateSession2(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 cfg.SessionSCfg().ThreshSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)} cfg.SessionSCfg().ResSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds): chanInternal, @@ -2958,25 +2934,25 @@ func TestBiRPCv1InitiateSession2(t *testing.T) { rply := &V1InitSessionReply{} expected := "RALS_ERROR:time: invalid duration \"invalid_DUR_FORMAT\"" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } args.CGREvent.APIOpts[utils.OptsDebitInterval] = "10s" expected = "ChargerS is disabled" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} expected = "RALS_ERROR:time: invalid duration \"invalid_usage\"" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } sessions = NewSessionS(cfg, dm, connMgr) args.CGREvent.Event[utils.Usage] = "10s" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err != nil { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err != nil { t.Error(err) } @@ -2985,7 +2961,7 @@ func TestBiRPCv1InitiateSession2(t *testing.T) { true, []string{}, true, []string{}, false, true, cgrEvent, true) sessions = NewSessionS(cfg, dm, connMgr) - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err != utils.ErrPartiallyExecuted { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err != utils.ErrPartiallyExecuted { t.Errorf("Expected %+v, received %+v", utils.ErrPartiallyExecuted, err) } @@ -3004,7 +2980,7 @@ func TestBiRPCv1InitiateSession2(t *testing.T) { true, []string{}, true, []string{}, false, true, cgrEvent, true) expected = "EXISTS" - if err := sessions.BiRPCv1InitiateSession(nil, args, rply); err == nil || err != utils.ErrPartiallyExecuted { + if err := sessions.BiRPCv1InitiateSession(context.Background(), args, rply); err == nil || err != utils.ErrPartiallyExecuted { t.Errorf("Expected %+v, received %+v", utils.ErrPartiallyExecuted, err) } @@ -3063,7 +3039,7 @@ func TestBiRPCv1InitiateSessionWithDigest(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().AttrSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} @@ -3074,7 +3050,7 @@ func TestBiRPCv1InitiateSessionWithDigest(t *testing.T) { cfg.SessionSCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)} cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 0 data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRoutes): chanInternal, @@ -3106,7 +3082,7 @@ func TestBiRPCv1InitiateSessionWithDigest(t *testing.T) { Thresholds: utils.StringPointer(utils.EmptyString), StatQueues: utils.StringPointer(utils.EmptyString), } - if err := sessions.BiRPCv1InitiateSessionWithDigest(nil, args, authReply); err != nil { + if err := sessions.BiRPCv1InitiateSessionWithDigest(context.Background(), args, authReply); err != nil { t.Error(err) } else if !reflect.DeepEqual(authReply, expectedRply) { t.Errorf("Expected %+v, received %+v", utils.ToJSON(expectedRply), utils.ToJSON(authReply)) @@ -3114,7 +3090,8 @@ func TestBiRPCv1InitiateSessionWithDigest(t *testing.T) { sessions.cgrCfg.SessionSCfg().ChargerSConns = nil expected := "MANDATORY_IE_MISSING: [OriginID]" - if err := sessions.BiRPCv1InitiateSessionWithDigest(nil, args, authReply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1InitiateSessionWithDigest(context.Background(), args, + authReply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } } @@ -3135,13 +3112,13 @@ func TestBiRPCv1UpdateSession1(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 cfg.SessionSCfg().AttrSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanInternal, }) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -3158,7 +3135,7 @@ func TestBiRPCv1UpdateSession1(t *testing.T) { rply := new(V1UpdateSessionReply) expected := "MANDATORY_IE_MISSING: [CGREvent]" - if err := sessions.BiRPCv1UpdateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1UpdateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3175,7 +3152,7 @@ func TestBiRPCv1UpdateSession1(t *testing.T) { engine.Cache = caches engine.Cache.SetWithoutReplicate(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.SessionSv1UpdateSession, args.CGREvent.ID), value, nil, true, utils.NonTransactional) - if err := sessions.BiRPCv1UpdateSession(nil, args, rply); err != nil { + if err := sessions.BiRPCv1UpdateSession(context.Background(), args, rply); err != nil { t.Error(err) } engine.Cache = tmp @@ -3184,20 +3161,20 @@ func TestBiRPCv1UpdateSession1(t *testing.T) { args = NewV1UpdateSessionArgs(true, []string{"attrr1"}, false, cgrEvent, true) expected = "ATTRIBUTES_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1UpdateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1UpdateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args = NewV1UpdateSessionArgs(true, []string{}, false, cgrEvent, true) - if err := sessions.BiRPCv1UpdateSession(nil, args, rply); err != nil { + if err := sessions.BiRPCv1UpdateSession(context.Background(), args, rply); err != nil { t.Error(err) } args = NewV1UpdateSessionArgs(false, []string{}, false, cgrEvent, true) expected = "MANDATORY_IE_MISSING: [subsystems]" - if err := sessions.BiRPCv1UpdateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1UpdateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } } @@ -3224,11 +3201,11 @@ func TestBiRPCv1UpdateSession2(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, }) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -3248,7 +3225,7 @@ func TestBiRPCv1UpdateSession2(t *testing.T) { cgrEvent, true) rply := new(V1UpdateSessionReply) expected := "RALS_ERROR:time: invalid duration \"invalid_dur_format\"" - if err := sessions.BiRPCv1UpdateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1UpdateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.APIOpts[utils.OptsDebitInterval] = "10s" @@ -3256,20 +3233,20 @@ func TestBiRPCv1UpdateSession2(t *testing.T) { args = NewV1UpdateSessionArgs(false, []string{}, true, cgrEvent, true) expected = "ChargerS is disabled" - if err := sessions.BiRPCv1UpdateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1UpdateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} expected = "RALS_ERROR:time: invalid duration \"invalid_dur_format\"" - if err := sessions.BiRPCv1UpdateSession(nil, args, rply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1UpdateSession(context.Background(), args, rply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.Event[utils.Usage] = time.Minute args = NewV1UpdateSessionArgs(false, []string{}, true, cgrEvent, true) - if err := sessions.BiRPCv1UpdateSession(nil, args, rply); err != nil { + if err := sessions.BiRPCv1UpdateSession(context.Background(), args, rply); err != nil { t.Error(err) } } @@ -3302,13 +3279,13 @@ func TestBiRPCv1TerminateSession1(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 cfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, }) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -3325,14 +3302,14 @@ func TestBiRPCv1TerminateSession1(t *testing.T) { args := NewV1TerminateSessionArgs(true, false, false, nil, false, nil, nil, true) var reply string expected := "MANDATORY_IE_MISSING: [CGREvent]" - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.ID = utils.EmptyString args = NewV1TerminateSessionArgs(false, false, false, nil, false, nil, cgrEvent, true) expected = "MANDATORY_IE_MISSING: [subsystems]" - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.ID = "test_id" @@ -3345,7 +3322,7 @@ func TestBiRPCv1TerminateSession1(t *testing.T) { engine.Cache = caches engine.Cache.SetWithoutReplicate(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.SessionSv1TerminateSession, args.CGREvent.ID), value, nil, true, utils.NonTransactional) - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err != nil { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err != nil { t.Errorf("Exepected %+v, received %+v", expected, err) } engine.Cache = tmp @@ -3353,7 +3330,7 @@ func TestBiRPCv1TerminateSession1(t *testing.T) { cgrEvent.Event[utils.OriginID] = utils.EmptyString args = NewV1TerminateSessionArgs(true, false, false, nil, false, nil, cgrEvent, true) expected = "MANDATORY_IE_MISSING: [OriginID]" - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.Event[utils.OriginID] = "ORIGIN_ID" @@ -3362,7 +3339,7 @@ func TestBiRPCv1TerminateSession1(t *testing.T) { cgrEvent.APIOpts[utils.OptsDebitInterval] = "invalid_time_format" args = NewV1TerminateSessionArgs(true, false, false, nil, false, nil, cgrEvent, true) expected = "RALS_ERROR:time: invalid duration \"invalid_time_format\"" - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.APIOpts[utils.OptsDebitInterval] = "1m" @@ -3373,7 +3350,7 @@ func TestBiRPCv1TerminateSession1(t *testing.T) { "CGR_ID": {}, } args = NewV1TerminateSessionArgs(true, false, false, nil, false, nil, cgrEvent, true) - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err != nil { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err != nil { t.Error(err) } cgrEvent.Event[utils.CGRID] = "CHANGED_CGRID" @@ -3381,7 +3358,7 @@ func TestBiRPCv1TerminateSession1(t *testing.T) { args = NewV1TerminateSessionArgs(true, false, false, nil, false, nil, cgrEvent, true) sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{} expected = "RALS_ERROR:ChargerS is disabled" - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} @@ -3390,7 +3367,7 @@ func TestBiRPCv1TerminateSession1(t *testing.T) { cgrEvent.Event[utils.Usage] = "invalid_dur_time" args = NewV1TerminateSessionArgs(true, false, false, nil, false, nil, cgrEvent, true) expected = "time: invalid duration \"invalid_dur_time\"" - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.Event[utils.Usage] = "1m" @@ -3409,7 +3386,7 @@ func TestBiRPCv1TerminateSession1(t *testing.T) { } cfg.SessionSCfg().ReplicationConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} cfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} - connMgr = engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr = engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): chanInternal, }) @@ -3418,7 +3395,7 @@ func TestBiRPCv1TerminateSession1(t *testing.T) { engine.Cache = caches args = NewV1TerminateSessionArgs(true, false, false, nil, false, nil, cgrEvent, true) expected = "RALS_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } engine.Cache = tmp @@ -3437,12 +3414,12 @@ func TestBiRPCv1TerminateSession2(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().ResSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): chanInternal, }) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -3459,14 +3436,14 @@ func TestBiRPCv1TerminateSession2(t *testing.T) { args := NewV1TerminateSessionArgs(false, true, false, nil, false, nil, cgrEvent, true) var reply string expected := "RESOURCES_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.Event[utils.OriginID] = utils.EmptyString args = NewV1TerminateSessionArgs(false, true, false, nil, false, nil, cgrEvent, true) expected = "MANDATORY_IE_MISSING: [OriginID]" - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.Event[utils.OriginID] = "ORIGIN_ID" @@ -3474,14 +3451,14 @@ func TestBiRPCv1TerminateSession2(t *testing.T) { args = NewV1TerminateSessionArgs(false, true, false, nil, false, nil, cgrEvent, true) expected = "NOT_CONNECTED: ResourceS" sessions.cgrCfg.SessionSCfg().ResSConns = []string{} - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().ResSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} cgrEvent.Tenant = "CHANGED_ID" args = NewV1TerminateSessionArgs(false, true, true, nil, true, nil, cgrEvent, true) - if err := sessions.BiRPCv1TerminateSession(nil, args, &reply); err == nil || err != utils.ErrPartiallyExecuted { + if err := sessions.BiRPCv1TerminateSession(context.Background(), args, &reply); err == nil || err != utils.ErrPartiallyExecuted { t.Errorf("Exepected %+v, received %+v", utils.ErrPartiallyExecuted, err) } } @@ -3506,7 +3483,7 @@ func TestBiRPCv1ProcessCDR(t *testing.T) { cgrEvent.ID = utils.EmptyString expected := "MANDATORY_IE_MISSING: [connIDs]" - if err := sessions.BiRPCv1ProcessCDR(nil, cgrEvent, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessCDR(context.Background(), cgrEvent, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.ID = "test_id" @@ -3519,7 +3496,7 @@ func TestBiRPCv1ProcessCDR(t *testing.T) { engine.Cache = caches engine.Cache.SetWithoutReplicate(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.SessionSv1ProcessCDR, cgrEvent.ID), value, nil, true, utils.NonTransactional) - if err := sessions.BiRPCv1ProcessCDR(nil, cgrEvent, &reply); err != nil { + if err := sessions.BiRPCv1ProcessCDR(context.Background(), cgrEvent, &reply); err != nil { t.Errorf("Exepected %+v, received %+v", expected, err) } engine.Cache = tmp @@ -3540,13 +3517,13 @@ func TestBiRPCv1ProcessMessage1(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 cfg.SessionSCfg().AttrSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanInternal, }) dm := engine.NewDataManager(data, cfg.CacheCfg(), connMgr) @@ -3565,7 +3542,7 @@ func TestBiRPCv1ProcessMessage1(t *testing.T) { true, false, false, nil, utils.Paginator{}, false, "1") reply := V1ProcessMessageReply{} expected := "MANDATORY_IE_MISSING: [CGREvent]" - if err := sessions.BiRPCv1ProcessMessage(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessMessage(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3574,7 +3551,7 @@ func TestBiRPCv1ProcessMessage1(t *testing.T) { false, []string{}, false, []string{}, true, false, false, false, false, cgrEvent, utils.Paginator{}, false, "1") expected = "ATTRIBUTES_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1ProcessMessage(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessMessage(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3583,7 +3560,7 @@ func TestBiRPCv1ProcessMessage1(t *testing.T) { false, []string{}, false, []string{}, true, false, false, false, false, cgrEvent, utils.Paginator{}, false, "1") expected = "NOT_CONNECTED: ResourceS" - if err := sessions.BiRPCv1ProcessMessage(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessMessage(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } @@ -3600,7 +3577,7 @@ func TestBiRPCv1ProcessMessage1(t *testing.T) { false, false, false, cgrEvent, utils.Paginator{}, false, "1") engine.Cache.SetWithoutReplicate(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.SessionSv1ProcessMessage, args.CGREvent.ID), value, nil, true, utils.NonTransactional) - if err := sessions.BiRPCv1ProcessMessage(nil, args, &reply); err != nil { + if err := sessions.BiRPCv1ProcessMessage(context.Background(), args, &reply); err != nil { t.Error(err) } engine.Cache = tmp @@ -3644,13 +3621,13 @@ func TestBiRPCv1ProcessMessage2(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 cfg.SessionSCfg().ResSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRoutes): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, @@ -3671,7 +3648,7 @@ func TestBiRPCv1ProcessMessage2(t *testing.T) { true, false, false, cgrEvent, utils.Paginator{}, false, "1") reply := V1ProcessMessageReply{} expected := "MANDATORY_IE_MISSING: [OriginID]" - if err := sessions.BiRPCv1ProcessMessage(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessMessage(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } cgrEvent.Event[utils.OriginID] = "ID" @@ -3681,7 +3658,7 @@ func TestBiRPCv1ProcessMessage2(t *testing.T) { false, false, false, cgrEvent, utils.Paginator{}, false, "1") reply = V1ProcessMessageReply{} expected = "RESOURCES_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1ProcessMessage(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessMessage(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3690,13 +3667,13 @@ func TestBiRPCv1ProcessMessage2(t *testing.T) { false, []string{}, false, []string{}, true, true, true, false, false, cgrEvent, utils.Paginator{}, false, "1") expected = "NOT_CONNECTED: RouteS" - if err := sessions.BiRPCv1ProcessMessage(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessMessage(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().RouteSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRoutes)} expected = "ChargerS is disabled" - if err := sessions.BiRPCv1ProcessMessage(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessMessage(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3705,7 +3682,7 @@ func TestBiRPCv1ProcessMessage2(t *testing.T) { true, false, false, cgrEvent, utils.Paginator{}, false, "1") sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} - if err := sessions.BiRPCv1ProcessMessage(nil, args, &reply); err == nil || err != utils.ErrPartiallyExecuted { + if err := sessions.BiRPCv1ProcessMessage(context.Background(), args, &reply); err == nil || err != utils.ErrPartiallyExecuted { t.Errorf("Exepected %+v, received %+v", utils.ErrPartiallyExecuted, err) } } @@ -3766,12 +3743,12 @@ func TestBiRPCv1ProcessEvent(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRoutes): chanInternal, @@ -3793,7 +3770,7 @@ func TestBiRPCv1ProcessEvent(t *testing.T) { } reply := V1ProcessEventReply{} expected := "MANDATORY_IE_MISSING: [CGREvent]" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.CGREvent = cgrEvent @@ -3809,14 +3786,14 @@ func TestBiRPCv1ProcessEvent(t *testing.T) { engine.Cache = caches engine.Cache.SetWithoutReplicate(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.SessionSv1ProcessEvent, args.CGREvent.ID), value, nil, true, utils.NonTransactional) - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err != nil { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err != nil { t.Error(err) } engine.Cache = tmp cgrEvent.ID = utils.EmptyString expected = "CHARGERS_ERROR:MANDATORY_IE_MISSING: [connIDs]" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3825,7 +3802,7 @@ func TestBiRPCv1ProcessEvent(t *testing.T) { sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} sessions.cgrCfg.SessionSCfg().AttrSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} expected = "ATTRIBUTES_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3833,7 +3810,7 @@ func TestBiRPCv1ProcessEvent(t *testing.T) { args.Flags = append(args.Flags, utils.MetaRoutes) sessions.cgrCfg.SessionSCfg().RouteSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRoutes)} expected = "ROUTES_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3841,14 +3818,14 @@ func TestBiRPCv1ProcessEvent(t *testing.T) { args.CGREvent.ID = "SECOND_ID" sessions.cgrCfg.SessionSCfg().ThreshSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)} expected = "PARTIALLY_EXECUTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.Flags = []string{utils.MetaThresholds, utils.MetaBlockerError} sessions.cgrCfg.SessionSCfg().ThreshSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds)} expected = "THRESHOLDS_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3878,13 +3855,13 @@ func TestBiRPCv1ProcessEventStats(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().StatSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats)} cfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, }) @@ -3905,13 +3882,13 @@ func TestBiRPCv1ProcessEventStats(t *testing.T) { } reply := V1ProcessEventReply{} expected := "PARTIALLY_EXECUTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.Flags = []string{utils.MetaStats, utils.MetaBlockerError} expected = "STATS_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3919,7 +3896,7 @@ func TestBiRPCv1ProcessEventStats(t *testing.T) { args.CGREvent.APIOpts = make(map[string]any) args.CGREvent.APIOpts[utils.OptsStirATest] = "stir;test;opts" expected = "*stir_authenticate: missing parts of the message header" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -3927,12 +3904,12 @@ func TestBiRPCv1ProcessEventStats(t *testing.T) { args.CGREvent.APIOpts = make(map[string]any) args.CGREvent.APIOpts[utils.OptsStirATest] = "stir;test;opts" expected = "*stir_authenticate: open : no such file or directory" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.CGREvent.APIOpts[utils.OptsStirOriginatorURI] = "+407590336423;USER_ID" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } } @@ -3949,12 +3926,12 @@ func TestBiRPCv1ProcessEventResources(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, }) @@ -3982,27 +3959,27 @@ func TestBiRPCv1ProcessEventResources(t *testing.T) { reply := V1ProcessEventReply{} expected := "NOT_CONNECTED: ResourceS" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().ResSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaResources)} args.Flags = append(args.Flags, utils.MetaResources) expected = "MANDATORY_IE_MISSING: [OriginID]" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.CGREvent.Event[utils.OriginID] = "ORIGIN_ID" args.Flags = append(args.Flags, utils.MetaBlockerError) expected = "RESOURCES_ERROR:UNSUPPORTED_SERVICE_METHOD" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.Flags = args.Flags[:len(args.Flags)-1] expected = "PARTIALLY_EXECUTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -4011,13 +3988,13 @@ func TestBiRPCv1ProcessEventResources(t *testing.T) { utils.MetaChargers} args.Flags = append(args.Flags, utils.MetaBlockerError) expected = "RESOURCES_ERROR:UNSUPPORTED_SERVICE_METHOD" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.Flags = args.Flags[:len(args.Flags)-1] expected = "PARTIALLY_EXECUTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -4026,13 +4003,13 @@ func TestBiRPCv1ProcessEventResources(t *testing.T) { utils.MetaChargers} args.Flags = append(args.Flags, utils.MetaBlockerError) expected = "RESOURCES_ERROR:UNSUPPORTED_SERVICE_METHOD" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.Flags = args.Flags[:len(args.Flags)-1] expected = "PARTIALLY_EXECUTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } } @@ -4067,14 +4044,14 @@ func TestBiRPCv1ProcessEventRals1(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheEventCharges].Limit = -1 cfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, }) @@ -4100,7 +4077,7 @@ func TestBiRPCv1ProcessEventRals1(t *testing.T) { } reply := V1ProcessEventReply{} - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err != utils.ErrNotImplemented { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err != utils.ErrNotImplemented { t.Errorf("Exepected %+v, received %+v", utils.ErrNotImplemented, err) } @@ -4112,12 +4089,12 @@ func TestBiRPCv1ProcessEventRals1(t *testing.T) { utils.MetaChargers} args.CGREvent.Event[utils.Usage] = "invalid_usage_format" expected := "time: invalid duration \"invalid_usage_format\"" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.CGREvent.Event[utils.Usage] = "1m" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err != nil { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err != nil { t.Error(expected) } @@ -4127,14 +4104,14 @@ func TestBiRPCv1ProcessEventRals1(t *testing.T) { args.APIOpts = make(map[string]any) args.APIOpts[utils.OptsDebitInterval] = "invalid_dbtitrvl_format" expected = "RALS_ERROR:time: invalid duration \"invalid_dbtitrvl_format\"" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.APIOpts[utils.OptsDebitInterval] = "5s" sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{} expected = "ChargerS is disabled" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} @@ -4142,7 +4119,7 @@ func TestBiRPCv1ProcessEventRals1(t *testing.T) { args.CGREvent.Event[utils.Usage] = "invalid_format" args.CGREvent.Tenant = "cgrates.org" expected = "RALS_ERROR:time: invalid duration \"invalid_format\"" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.CGREvent.Event[utils.Usage] = "10s" @@ -4178,7 +4155,7 @@ func TestBiRPCv1ProcessEventRals2(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheEventCharges].Limit = -1 @@ -4186,7 +4163,7 @@ func TestBiRPCv1ProcessEventRals2(t *testing.T) { cfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} cfg.SessionSCfg().ReplicationConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaReplicator): chanInternal, @@ -4215,7 +4192,7 @@ func TestBiRPCv1ProcessEventRals2(t *testing.T) { reply := V1ProcessEventReply{} - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err != nil { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err != nil { t.Error(err) } @@ -4224,7 +4201,7 @@ func TestBiRPCv1ProcessEventRals2(t *testing.T) { utils.MetaChargers} args.APIOpts[utils.OptsDebitInterval] = "invalid_format" expected := "RALS_ERROR:time: invalid duration \"invalid_format\"" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.APIOpts[utils.OptsDebitInterval] = "10s" @@ -4232,7 +4209,7 @@ func TestBiRPCv1ProcessEventRals2(t *testing.T) { args.Event[utils.CGRID] = "test_id_new" sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{} expected = "ChargerS is disabled" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} @@ -4240,7 +4217,7 @@ func TestBiRPCv1ProcessEventRals2(t *testing.T) { args.CGREvent.Event[utils.Usage] = "invalid_format" expected = "RALS_ERROR:time: invalid duration \"invalid_format\"" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.CGREvent.Event[utils.Usage] = "10" @@ -4249,7 +4226,7 @@ func TestBiRPCv1ProcessEventRals2(t *testing.T) { utils.ConcatenatedKey(utils.MetaRALs, utils.MetaUpdate), utils.MetaChargers} delete(args.APIOpts, utils.OptsDebitInterval) - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err != nil { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err != nil { t.Error(err) } @@ -4258,7 +4235,7 @@ func TestBiRPCv1ProcessEventRals2(t *testing.T) { utils.MetaChargers} args.APIOpts[utils.OptsDebitInterval] = "invalid_format" expected = "RALS_ERROR:time: invalid duration \"invalid_format\"" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.APIOpts[utils.OptsDebitInterval] = "10s" @@ -4266,7 +4243,7 @@ func TestBiRPCv1ProcessEventRals2(t *testing.T) { args.Event[utils.CGRID] = "test_id_new" sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{} expected = "ChargerS is disabled" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} @@ -4281,7 +4258,7 @@ func TestBiRPCv1ProcessEventRals2(t *testing.T) { engine.Cache = cacheS engine.SetConnManager(connMgr) expected = "RALS_ERROR:NOT_IMPLEMENTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -4314,13 +4291,13 @@ func TestBiRPCv1ProcessEventCDRs11(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.SessionSCfg().ChargerSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers)} cfg.SessionSCfg().CDRsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs)} data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaChargers): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCDRs): chanInternal, }) @@ -4367,7 +4344,7 @@ func TestBiRPCv1ProcessEventCDRs11(t *testing.T) { reply := V1ProcessEventReply{} expected := "PARTIALLY_EXECUTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } @@ -4386,7 +4363,7 @@ func TestBiRPCv1ProcessEventCDRs11(t *testing.T) { expectedLogger := "[WARNING] ProcessCDR called for active session with CGRID: " expected = "CDRS_ERROR:PARTIALLY_EXECUTED" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Expected %+v, received %+v", expected, err) } else if rcv := buff.String(); !strings.Contains(rcv, expectedLogger) { t.Errorf("Expected %+v, received %+v", expectedLogger, rcv) @@ -4395,7 +4372,7 @@ func TestBiRPCv1ProcessEventCDRs11(t *testing.T) { sessions.cgrCfg.SessionSCfg().CDRsConns = []string{} expected = "NOT_CONNECTED: CDRs" - if err := sessions.BiRPCv1ProcessEvent(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1ProcessEvent(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } } @@ -4425,12 +4402,12 @@ func TestBiRPCv1GetCost(t *testing.T) { }, }, } - chanInternal := make(chan rpcclient.ClientConnector, 1) + chanInternal := make(chan birpc.ClientConnector, 1) chanInternal <- clnt cfg := config.NewDefaultCGRConfig() cfg.CacheCfg().Partitions[utils.CacheRPCResponses].Limit = 1 data := engine.NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items) - connMgr := engine.NewConnManager(cfg, map[string]chan rpcclient.ClientConnector{ + connMgr := engine.NewConnManager(cfg, map[string]chan birpc.ClientConnector{ utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs): chanInternal, utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes): chanInternal, }) @@ -4455,7 +4432,7 @@ func TestBiRPCv1GetCost(t *testing.T) { } reply := V1GetCostReply{} expected := "MANDATORY_IE_MISSING: [CGREvent]" - if err := sessions.BiRPCv1GetCost(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1GetCost(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } args.CGREvent = cgrEvent @@ -4472,20 +4449,20 @@ func TestBiRPCv1GetCost(t *testing.T) { engine.Cache = caches engine.Cache.SetWithoutReplicate(utils.CacheRPCResponses, utils.ConcatenatedKey(utils.SessionSv1GetCost, args.CGREvent.ID), value, nil, true, utils.NonTransactional) - if err := sessions.BiRPCv1GetCost(nil, args, &reply); err != nil { + if err := sessions.BiRPCv1GetCost(context.Background(), args, &reply); err != nil { t.Error(err) } engine.Cache = tmp args.CGREvent.ID = utils.EmptyString expected = "ATTRIBUTES_ERROR:NOT_CONNECTED: AttributeS" - if err := sessions.BiRPCv1GetCost(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1GetCost(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().AttrSConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAttributes)} expected = "MANDATORY_IE_MISSING: [connIDs]" - if err := sessions.BiRPCv1GetCost(nil, args, &reply); err == nil || err.Error() != expected { + if err := sessions.BiRPCv1GetCost(context.Background(), args, &reply); err == nil || err.Error() != expected { t.Errorf("Exepected %+v, received %+v", expected, err) } sessions.cgrCfg.SessionSCfg().RALsConns = []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaRALs)} @@ -4513,7 +4490,7 @@ func TestBiRPCv1GetCost(t *testing.T) { }, } expectedVal.EventCost.Compute() - if err := sessions.BiRPCv1GetCost(nil, args, &reply); err != nil { + if err := sessions.BiRPCv1GetCost(context.Background(), args, &reply); err != nil { t.Errorf("Exepected %+v, received %+v", expected, err) } /* @@ -4548,7 +4525,7 @@ func TestSyncSessionsSync(t *testing.T) { sessions.aSessions = map[string]*Session{} var reply string - if err := sessions.BiRPCv1SyncSessions(nil, nil, &reply); err != nil { + if err := sessions.BiRPCv1SyncSessions(context.Background(), nil, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected to be OK") diff --git a/utils/birpcint_client.go b/utils/birpcint_client.go index 56dbfa933..4a338c138 100644 --- a/utils/birpcint_client.go +++ b/utils/birpcint_client.go @@ -21,20 +21,19 @@ package utils import ( "net" - "github.com/cenkalti/rpc2" - rpc2_jsonrpc "github.com/cenkalti/rpc2/jsonrpc" + "github.com/cgrates/birpc" + "github.com/cgrates/birpc/jsonrpc" ) // NewBiJSONrpcClient will create a bidirectional JSON client connection -func NewBiJSONrpcClient(addr string, handlers map[string]any) (*rpc2.Client, error) { +func NewBiJSONrpcClient(addr string, obj birpc.ClientConnector) (*birpc.BirpcClient, error) { conn, err := net.Dial(TCP, addr) if err != nil { return nil, err } - clnt := rpc2.NewClientWithCodec(rpc2_jsonrpc.NewJSONCodec(conn)) - for method, handlerFunc := range handlers { - clnt.Handle(method, handlerFunc) + clnt := birpc.NewBirpcClientWithCodec(jsonrpc.NewJSONBirpcCodec(conn)) + if obj != nil { + clnt.Register(obj) } - go clnt.Run() return clnt, nil } diff --git a/utils/birpcint_client_test.go b/utils/birpcint_client_test.go deleted file mode 100644 index 31b3394b2..000000000 --- a/utils/birpcint_client_test.go +++ /dev/null @@ -1,50 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package utils - -import ( - "net" - "testing" - - "github.com/cenkalti/rpc2" -) - -func TestNewBiJSONrpcClient(t *testing.T) { - //empty check - addr := "127.0.0.1:4024" - handlers := map[string]any{} - rcv, err := NewBiJSONrpcClient(addr, handlers) - if err == nil || rcv != nil { - t.Error("Expencting: \"connection refused\", received : nil") - } - - l, err := net.Listen(TCP, addr) - if err != nil { - t.Error(err) - } - handlers = map[string]any{ - "": func(*rpc2.Client, *struct{}, *string) error { return nil }, - } - - _, err = NewBiJSONrpcClient(addr, handlers) - if err != nil { - t.Error(err) - } - l.Close() -} diff --git a/utils/consts.go b/utils/consts.go index 109bf79f4..9682c8e40 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -970,23 +970,27 @@ const ( // Services const ( - SessionS = "SessionS" - AttributeS = "AttributeS" - RouteS = "RouteS" - ResourceS = "ResourceS" - StatService = "StatS" - FilterS = "FilterS" - ThresholdS = "ThresholdS" - DispatcherS = "DispatcherS" - RegistrarC = "RegistrarC" - LoaderS = "LoaderS" - ChargerS = "ChargerS" - CacheS = "CacheS" AnalyzerS = "AnalyzerS" - CDRServer = "CDRServer" - ResponderS = "ResponderS" - GuardianS = "GuardianS" ApierS = "ApierS" + AttributeS = "AttributeS" + CacheS = "CacheS" + CDRServer = "CDRServer" + ChargerS = "ChargerS" + ConfigS = "ConfigS" + DispatcherS = "DispatcherS" + EeS = "EeS" + FilterS = "FilterS" + GuardianS = "GuardianS" + LoaderS = "LoaderS" + RALs = "RALs" + RegistrarC = "RegistrarC" + ReplicatorS = "ReplicatorS" + ResourceS = "ResourceS" + ResponderS = "ResponderS" + RouteS = "RouteS" + SessionS = "SessionS" + StatService = "StatS" + ThresholdS = "ThresholdS" ) // Lower service names @@ -1481,7 +1485,6 @@ const ( APIerSv2GetActions = "APIerSv2.GetActions" APIerSv2GetDestinations = "APIerSv2.GetDestinations" APIerSv2GetCacheStats = "APIerSv2.GetCacheStats" - APIerSv2ExecuteAction = "APIerSv2.ExecuteAction" APIerSv2ResetAccountActionTriggers = "APIerSv2.ResetAccountActionTriggers" APIerSv2RemoveActions = "APIerSv2.RemoveActions" APIerSv2ExportCdrsToFile = "APIerSv2.ExportCdrsToFile" diff --git a/utils/coreutils.go b/utils/coreutils.go index 99aa1e09e..004f2e3b7 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -868,45 +868,6 @@ func APIerRPCCall(inst any, serviceMethod string, args any, reply any) error { return err } -// BiRPCCall is a generic method calling BiRPC on a struct instance -// serviceMethod is assumed to be in the form InstanceV1.Method -// where BiRPCV1Method will become RPC method called on instance -// the subsystem is not checked -func BiRPCCall(inst any, clnt rpcclient.ClientConnector, serviceMethod string, args any, reply any) error { - parts := strings.Split(serviceMethod, ".") - if len(parts) != 2 { - return rpcclient.ErrUnsupporteServiceMethod - } - // get method BiRPCV1.Method - method := reflect.ValueOf(inst).MethodByName( - "BiRPC" + parts[0][len(parts[0])-2:] + parts[1]) // Inherit the version V1 in the method name and add prefix - if !method.IsValid() { - return rpcclient.ErrUnsupporteServiceMethod - } - // construct the params - var clntVal reflect.Value - if clnt == nil { - clntVal = reflect.New( - reflect.TypeOf(new(rpcclient.BiRPCInternalServer))).Elem() // Kinda cheat since we make up a type here - } else { - clntVal = reflect.ValueOf(clnt) - } - params := []reflect.Value{clntVal, reflect.ValueOf(args), - reflect.ValueOf(reply)} - ret := method.Call(params) - if len(ret) != 1 { - return ErrServerError - } - if ret[0].Interface() == nil { - return nil - } - err, ok := ret[0].Interface().(error) - if !ok { - return ErrServerError - } - return err -} - // CachedRPCResponse is used to cache a RPC response type CachedRPCResponse struct { Result any diff --git a/utils/coreutils_test.go b/utils/coreutils_test.go index d1ee664d1..fa4780e51 100644 --- a/utils/coreutils_test.go +++ b/utils/coreutils_test.go @@ -28,6 +28,7 @@ import ( "golang.org/x/crypto/bcrypt" + "github.com/cgrates/birpc" "github.com/cgrates/rpcclient" ) @@ -1724,87 +1725,23 @@ func (c client) Call(serviceMethod string, args any, reply any) (err error) { return } -func (srv *server) BiRPCv1ValidMethod(cl rpcclient.ClientConnector, args any, req any) error { +func (srv *server) BiRPCv1ValidMethod(cl birpc.ClientConnector, args any, req any) error { return nil } -func (srv *server) BiRPCv1MultipleParams(cl rpcclient.ClientConnector, args any, req any) (int, error) { +func (srv *server) BiRPCv1MultipleParams(cl birpc.ClientConnector, args any, req any) (int, error) { return 1, nil } -func (srv *server) BiRPCv1NoErrorReturn(cl rpcclient.ClientConnector, args any, req any) int { +func (srv *server) BiRPCv1NoErrorReturn(cl birpc.ClientConnector, args any, req any) int { return 1 } -func (srv *server) BiRPCv1FinalError(cl rpcclient.ClientConnector, args any, req any) (err error) { +func (srv *server) BiRPCv1FinalError(cl birpc.ClientConnector, args any, req any) (err error) { err = ErrExists return } -func TestCoreUtilsBiRPCCall(t *testing.T) { - srv := new(server) - var clnt rpcclient.ClientConnector - var args int - var reply *int - serviceMethod := "testv1.v2.v3" - - expected := rpcclient.ErrUnsupporteServiceMethod - err := BiRPCCall(srv, clnt, serviceMethod, args, reply) - - if err == nil || err != expected { - t.Errorf("\nExpected: <%v>, \nReceived: <%v>", expected, err) - } - - serviceMethod = "testv1.fail" - - err = BiRPCCall(srv, clnt, serviceMethod, args, reply) - - if err == nil || err != expected { - t.Errorf("\nExpected: <%v>, \nReceived: <%v>", expected, err) - } - - serviceMethod = "Testv1.ValidMethod" - - err = BiRPCCall(srv, clnt, serviceMethod, args, reply) - - if err != nil { - t.Errorf("\nExpected: <%v>, \nReceived: <%v>", nil, err) - } - - serviceMethod = "Testv1.MultipleParams" - - expected = ErrServerError - err = BiRPCCall(srv, clnt, serviceMethod, args, reply) - - if err == nil || err != expected { - t.Errorf("\nExpected: <%v>, \nReceived: <%v>", expected, err) - } - - serviceMethod = "Testv1.NoErrorReturn" - err = BiRPCCall(srv, clnt, serviceMethod, args, reply) - - expected = ErrServerError - if err == nil || err != expected { - t.Errorf("\nExpected: <%v>, \nReceived: <%v>", expected, err) - } - - serviceMethod = "Testv1.FinalError" - err = BiRPCCall(srv, clnt, serviceMethod, args, reply) - - expected = ErrExists - if err == nil || err != expected { - t.Errorf("\nExpected: <%v>, \nReceived: <%v>", expected, err) - } - - var c client - c.Call("testString", args, reply) - - err = BiRPCCall(srv, c, serviceMethod, args, reply) - if err == nil || err != expected { - t.Errorf("\nExpected: <%+v>, \nReceived: <%+v>", expected, err) - } -} - func TestCoreUtilsGenerateDBItemOpts(t *testing.T) { apiKey := "testKey1" routeID := "testKey2" diff --git a/utils/rpc_params.go b/utils/rpc_params.go index 6ed8f069b..832e83211 100644 --- a/utils/rpc_params.go +++ b/utils/rpc_params.go @@ -19,8 +19,11 @@ along with this program. If not, see package utils import ( + "fmt" "reflect" "sync" + + "github.com/cgrates/birpc" ) var ( @@ -28,40 +31,52 @@ var ( rpcParamsLock sync.Mutex ) +// RpcParams holds the parameters for an RPC method, including the object, input, and output parameters. type RpcParams struct { Object any InParam any OutParam any } -func RegisterRpcParams(name string, obj any) { - objType := reflect.TypeOf(obj) - if name == "" { - val := reflect.ValueOf(obj) - name = objType.Name() - if val.Kind() == reflect.Ptr { - name = objType.Elem().Name() +// RegisterRpcParams takes a receiver of any type and if it is of type *birpc.Service or can be wrapped within one, it attempts to +// populate the rpcParamsMap. Each entry in the map associates a method name with an RpcParams struct containing the parameters +// for that method. +// The name parameter is taken into consideration only if the receiver is not already of type *birpc.Service. +func RegisterRpcParams(name string, rcvr any) { + + // Attempt to cast the receiver to a *birpc.Service. + srv, isService := rcvr.(*birpc.Service) + if !isService { + useName := name != EmptyString + + // If the cast fails, create a new service instance. + var err error + srv, err = birpc.NewService(rcvr, name, useName) + if err != nil { + Logger.Err(fmt.Sprintf("failed to register rpc parameters, service initialization error: %s", err)) + return } } - for i := 0; i < objType.NumMethod(); i++ { - method := objType.Method(i) - methodType := method.Type - if methodType.NumIn() == 3 { // if it has three parameters (one is self and two are rpc params) - out := methodType.In(2) - if out.Kind() == reflect.Ptr { - out = out.Elem() - } - rpcParamsLock.Lock() - rpcParamsMap[name+"."+method.Name] = &RpcParams{ - Object: obj, - InParam: reflect.New(methodType.In(1)).Interface(), - OutParam: reflect.New(out).Interface(), - } - rpcParamsLock.Unlock() + rpcParamsLock.Lock() + defer rpcParamsLock.Unlock() + for mName, mValue := range srv.Methods { + params := &RpcParams{ + Object: srv, + + // ReplyType will always be a pointer, therefore it is safe to be dereferenced + // and then create a new pointer to the underlying value. + OutParam: reflect.New(mValue.ReplyType.Elem()).Interface(), } + if mValue.ArgType.Kind() == reflect.Ptr { + params.InParam = reflect.New(mValue.ArgType.Elem()).Interface() + } else { + params.InParam = reflect.New(mValue.ArgType).Elem().Interface() + } + rpcParamsMap[srv.Name+"."+mName] = params } } +// GetRpcParams retrieves the RpcParams for a given method name. func GetRpcParams(method string) (params *RpcParams, err error) { var found bool rpcParamsLock.Lock() diff --git a/utils/rpc_params_test.go b/utils/rpc_params_test.go index 497f92e8f..daa312de7 100644 --- a/utils/rpc_params_test.go +++ b/utils/rpc_params_test.go @@ -21,6 +21,7 @@ import ( "reflect" "testing" + "github.com/cgrates/birpc/context" "github.com/mitchellh/mapstructure" ) @@ -32,15 +33,11 @@ type Attr struct { Age float64 } -func (rpc *RpcStruct) Method1(normal Attr, out *float64) error { +func (rpc *RpcStruct) Method1(ctx *context.Context, normal Attr, out *float64) error { return nil } -func (rpc *RpcStruct) Method2(pointer *Attr, out *float64) error { - return nil -} - -func (rpc *RpcStruct) Call(string, any, any) error { +func (rpc *RpcStruct) Method2(ctx *context.Context, pointer *Attr, out *float64) error { return nil } @@ -54,7 +51,7 @@ func TestRPCObjectPointer(t *testing.T) { t.Errorf("error getting rpcobject: %v (%+v)", rpcParamsMap, x) } a := x.InParam - if err := mapstructure.Decode(map[string]any{"Name": "a", "Surname": "b", "Age": 10.2}, a); err != nil || a.(*Attr).Name != "a" || a.(*Attr).Surname != "b" || a.(*Attr).Age != 10.2 { + if err := mapstructure.Decode(map[string]any{"Name": "a", "Surname": "b", "Age": 10.2}, &a); err != nil || a.(Attr).Name != "a" || a.(Attr).Surname != "b" || a.(Attr).Age != 10.2 { t.Errorf("error converting to struct: %+v (%v)", a, err) } } @@ -67,7 +64,7 @@ func TestGetRpcParamsError(t *testing.T) { } func TestGetRpcParams(t *testing.T) { - testStruct := &Attr{"", "", 0} + testStruct := Attr{"", "", 0} RegisterRpcParams("", &RpcStruct{}) if result, err := GetRpcParams("RpcStruct.Method1"); err != nil { t.Errorf("Expected , received <%+v>", err)