blob: dd151c65a6090283fb2e99435c1e9facae3ca98e [file] [log] [blame]
Rolf Badorekef2bf512019-08-20 11:17:15 +03001/*
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
Timo Tietavainena0745d22019-11-28 09:55:22 +020017/*
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
20*/
21
Rolf Badorekef2bf512019-08-20 11:17:15 +030022#ifndef SHAREDDATALAYER_CONFIGURATIONREADER_HPP_
23#define SHAREDDATALAYER_CONFIGURATIONREADER_HPP_
24
25#define DB_HOST_ENV_VAR_NAME "DBAAS_SERVICE_HOST"
26#define DB_PORT_ENV_VAR_NAME "DBAAS_SERVICE_PORT"
Rolf Badorek2dcf9402019-10-01 18:33:58 +030027#define SENTINEL_PORT_ENV_VAR_NAME "DBAAS_SERVICE_SENTINEL_PORT"
28#define SENTINEL_MASTER_NAME_ENV_VAR_NAME "DBAAS_MASTER_NAME"
Rolf Badorekef2bf512019-08-20 11:17:15 +030029
30#include <iosfwd>
31#include <string>
32#include <unordered_map>
33#include <boost/property_tree/ptree.hpp>
34#include <sdl/exception.hpp>
35#include "private/configurationpaths.hpp"
36#include "private/logger.hpp"
37
38namespace shareddatalayer
39{
40 class DatabaseConfiguration;
41 class NamespaceConfigurations;
42 class System;
43
44 class ConfigurationReader
45 {
46 public:
47 explicit ConfigurationReader(std::shared_ptr<Logger> logger);
48
49 ConfigurationReader(const Directories& directories,
50 System& system,
51 std::shared_ptr<Logger> logger);
52
53 ~ConfigurationReader();
54
55 void readDatabaseConfiguration(DatabaseConfiguration& databaseConfiguration);
56
57 void readNamespaceConfigurations(NamespaceConfigurations& namespaceConfigurations);
58
59 /**
60 * Overrides existing json configuration with json format input stream given as
61 * parameter. Does not override existing configration if existing configration
62 * originates from environment variable. Meant for UT usage.
63 */
64 void readConfigurationFromInputStream(const std::istream& input);
65
66 private:
67 const std::string dbHostEnvVariableName;
68 std::string dbHostEnvVariableValue;
69 const std::string dbPortEnvVariableName;
70 std::string dbPortEnvVariableValue;
Rolf Badorek2dcf9402019-10-01 18:33:58 +030071 const std::string sentinelPortEnvVariableName;
72 std::string sentinelPortEnvVariableValue;
73 const std::string sentinelMasterNameEnvVariableName;
74 std::string sentinelMasterNameEnvVariableValue;
Rolf Badorekef2bf512019-08-20 11:17:15 +030075 boost::optional<boost::property_tree::ptree> jsonDatabaseConfiguration;
76 std::string sourceForDatabaseConfiguration;
77 std::unordered_map<std::string, std::pair<boost::property_tree::ptree, std::string>> jsonNamespaceConfigurations;
78 std::shared_ptr<Logger> logger;
79
80 void readConfigurationFromDirectories(const Directories& directories);
81
82 template<typename T>
83 void readConfiguration(T& input, const std::string& sourceName);
84 };
85}
86
87#endif