b43aeee9c869c1d9713106f0bd6b139de2f0b552
[ric-plt/sdl.git] / include / private / databaseconfiguration.hpp
1 /*
2    Copyright (c) 2018-2022 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 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20 */
21
22 #ifndef SHAREDDATALAYER_DATABASECONFIGURATION_HPP_
23 #define SHAREDDATALAYER_DATABASECONFIGURATION_HPP_
24
25 #include <string>
26 #include <vector>
27 #include <boost/optional.hpp>
28 #include "private/hostandport.hpp"
29
30 namespace shareddatalayer
31 {
32     class DatabaseConfiguration
33     {
34     public:
35         class InvalidDbType;
36         using Addresses = std::vector<HostAndPort>;
37         using SentinelPorts = std::vector<uint16_t>;
38         using SentinelMasterNames = std::vector<std::string>;
39         enum class DbType
40         {
41             UNKNOWN = 0,
42             REDIS_STANDALONE,
43             REDIS_CLUSTER,
44             REDIS_SENTINEL,
45             SDL_STANDALONE_CLUSTER,
46             SDL_SENTINEL_CLUSTER
47         };
48
49         virtual ~DatabaseConfiguration() = default;
50         virtual void checkAndApplyDbType(const std::string& type) = 0;
51         virtual void checkAndApplyServerAddress(const std::string& address) = 0;
52         virtual void checkAndApplySentinelPorts(const std::string& sentinelPortsEnvStr) = 0;
53         virtual void checkAndApplySentinelMasterNames(const std::string& sentinelMasterNamesEnvStr) = 0;
54         virtual DatabaseConfiguration::DbType getDbType() const = 0;
55         virtual DatabaseConfiguration::Addresses getServerAddresses() const = 0;
56         virtual DatabaseConfiguration::Addresses getServerAddresses(const boost::optional<std::size_t>& addressIndex) const = 0;
57         virtual DatabaseConfiguration::Addresses getDefaultServerAddresses() const = 0;
58         virtual boost::optional<HostAndPort> getSentinelAddress(const boost::optional<std::size_t>& addressIndex) const = 0;
59         virtual std::string getSentinelMasterName(const boost::optional<std::size_t>& addressIndex) const = 0;
60         virtual bool isEmpty() const = 0;
61
62         DatabaseConfiguration(DatabaseConfiguration&&) = delete;
63         DatabaseConfiguration(const DatabaseConfiguration&) = delete;
64         DatabaseConfiguration& operator = (DatabaseConfiguration&&) = delete;
65         DatabaseConfiguration& operator = (const DatabaseConfiguration&) = delete;
66
67     protected:
68         DatabaseConfiguration() = default;
69     };
70
71     class DatabaseConfiguration::InvalidDbType: public Exception
72     {
73     public:
74         InvalidDbType() = delete;
75
76         explicit InvalidDbType(const std::string& type);
77     };
78 }
79
80 #endif