Add implementation of SDL in python
[ric-plt/sdlpy.git] / ricsdl-package / ricsdl / backend / __init__.py
1 # Copyright (c) 2019 AT&T Intellectual Property.
2 # Copyright (c) 2018-2019 Nokia.
3 #
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
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 #
17 # This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 # platform project (RICP).
19 #
20
21
22 """Shared Data Layer (SDL) database backend module."""
23
24 from importlib import import_module
25
26
27 def get_backend_instance(configuration):
28     """
29     Select database backend solution and return and instance of it.
30     For now only Redis backend solution is supported.
31     """
32     backend_name = 'RedisBackend'
33     backend_module_name = 'redis'
34
35     package = __package__ or __name__
36     backend_module = import_module('.' + backend_module_name, package=package)
37     backend_class = getattr(backend_module, backend_name)
38     instance = backend_class(configuration)
39     return instance
40
41
42 def get_backend_lock_instance(ns, name, expiration, backend):
43     """
44     Select database backend lock solution and return and instance of it.
45     For now only Redis backend lock solution is supported.
46     """
47     backend_lock_name = 'RedisBackendLock'
48     backend_module_name = 'redis'
49
50     package = __package__ or __name__
51     backend_module = import_module('.' + backend_module_name, package=package)
52     backend_lock_class = getattr(backend_module, backend_lock_name)
53     instance = backend_lock_class(ns, name, expiration, backend)
54     return instance