1 # Copyright (c) 2019 AT&T Intellectual Property.
2 # Copyright (c) 2018-2019 Nokia.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 # This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 # platform project (RICP).
22 """Shared Data Layer (SDL) database backend module."""
24 from importlib import import_module
25 from ricsdl.configuration import DbBackendType
28 def get_backend_instance(configuration):
30 Select database backend solution and return and instance of it.
32 if configuration.get_params().db_type == DbBackendType.FAKE_DICT:
33 backend_name = 'FakeDictBackend'
34 backend_module_name = 'fake_dict_db'
36 backend_name = 'RedisBackend'
37 backend_module_name = 'redis'
39 package = __package__ or __name__
40 backend_module = import_module('.' + backend_module_name, package=package)
41 backend_class = getattr(backend_module, backend_name)
42 instance = backend_class(configuration)
46 def get_backend_lock_instance(configuration, ns, name, expiration, backend):
48 Select database backend lock solution and return and instance of it.
50 if configuration.get_params().db_type == DbBackendType.FAKE_DICT:
51 backend_lock_name = 'FakeDictBackendLock'
52 backend_module_name = 'fake_dict_db'
54 backend_lock_name = 'RedisBackendLock'
55 backend_module_name = 'redis'
57 package = __package__ or __name__
58 backend_module = import_module('.' + backend_module_name, package=package)
59 backend_lock_class = getattr(backend_module, backend_lock_name)
60 instance = backend_lock_class(ns, name, expiration, backend)