e8e5b8df8eede28b61349db3f43fb9ff493398e8
[ric-plt/sdl.git] / include / private / databaseconfiguration.hpp
1 /*
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 /*
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         enum class DbType
38         {
39             UNKNOWN = 0,
40             REDIS_STANDALONE,
41             REDIS_CLUSTER,
42             REDIS_SENTINEL,
43             SDL_STANDALONE_CLUSTER,
44             SDL_SENTINEL_CLUSTER
45         };
46
47         virtual ~DatabaseConfiguration() = default;
48         virtual void checkAndApplyDbType(const std::string& type) = 0;
49         virtual void checkAndApplyServerAddress(const std::string& address) = 0;
50         virtual void checkAndApplySentinelAddress(const std::string& address) = 0;
51         virtual void checkAndApplySentinelMasterName(const std::string& name) = 0;
52         virtual DatabaseConfiguration::DbType getDbType() const = 0;
53         virtual DatabaseConfiguration::Addresses getServerAddresses() const = 0;
54         virtual DatabaseConfiguration::Addresses getServerAddresses(const boost::optional<std::size_t>& addressIndex) const = 0;
55         virtual DatabaseConfiguration::Addresses getDefaultServerAddresses() const = 0;
56         virtual boost::optional<HostAndPort> getSentinelAddress() const = 0; // Optional return value, because empty HostAndPort can't be created.
57         virtual boost::optional<HostAndPort> getSentinelAddress(const boost::optional<std::size_t>& addressIndex) const = 0;
58         virtual std::string getSentinelMasterName() const = 0;
59         virtual bool isEmpty() const = 0;
60
61         DatabaseConfiguration(DatabaseConfiguration&&) = delete;
62         DatabaseConfiguration(const DatabaseConfiguration&) = delete;
63         DatabaseConfiguration& operator = (DatabaseConfiguration&&) = delete;
64         DatabaseConfiguration& operator = (const DatabaseConfiguration&) = delete;
65
66     protected:
67         DatabaseConfiguration() = default;
68     };
69
70     class DatabaseConfiguration::InvalidDbType: public Exception
71     {
72     public:
73         InvalidDbType() = delete;
74
75         explicit InvalidDbType(const std::string& type);
76     };
77 }
78
79 #endif