13#include <database/db_messages.h>
16#include <boost/algorithm/string.hpp>
17#include <boost/foreach.hpp>
29 ParameterMap::const_iterator param = parameters_.find(name);
30 if (param == parameters_.end()) {
33 return (param->second);
40 if (!dbaccess.empty()) {
41 vector<string> tokens;
47 boost::split(tokens, dbaccess, boost::is_any_of(
string(
"\t ")));
48 BOOST_FOREACH(std::string token, tokens) {
49 size_t pos = token.find(
"=");
50 if (pos != string::npos) {
51 string name = token.substr(0, pos);
52 string value = token.substr(pos + 1);
53 mapped_tokens.insert(make_pair(name, value));
57 <<
", expected format is name=value");
62 return (mapped_tokens);
70 for (DatabaseConnection::ParameterMap::const_iterator i = parameters.begin();
71 i != parameters.end(); ++i) {
74 if (!access.empty()) {
84 if (i->first == std::string(
"password")) {
96 std::string readonly_value =
"false";
99 boost::algorithm::to_lower(readonly_value);
105 if ((readonly_value !=
"false") && (readonly_value !=
"true")) {
107 <<
"' specified for boolean parameter 'readonly'");
110 return (readonly_value ==
"true");
116 string type =
"unknown";
117 unsigned int retries = 0;
118 unsigned int interval = 0;
127 std::string parm_str;
130 retries = boost::lexical_cast<unsigned int>(parm_str);
137 interval = boost::lexical_cast<unsigned int>(parm_str);
160 for (
auto param: params) {
161 std::string keyword = param.first;
162 std::string value = param.second;
164 if ((keyword ==
"lfc-interval") ||
165 (keyword ==
"connect-timeout") ||
166 (keyword ==
"request-timeout") ||
167 (keyword ==
"port") ||
168 (keyword ==
"max-reconnect-tries") ||
169 (keyword ==
"reconnect-wait-time") ||
170 (keyword ==
"tcp-keepalive")) {
175 int_value = boost::lexical_cast<int64_t>(value);
179 .arg(
"integer").arg(keyword).arg(value);
181 }
else if ((keyword ==
"persist") ||
182 (keyword ==
"readonly") ||
183 (keyword ==
"tcp-nodelay")) {
185 if (value ==
"true") {
187 }
else if (value ==
"false") {
191 .arg(
"boolean").arg(keyword).arg(value);
193 }
else if ((keyword ==
"type") ||
194 (keyword ==
"user") ||
195 (keyword ==
"password") ||
196 (keyword ==
"host") ||
197 (keyword ==
"name") ||
198 (keyword ==
"contact-points") ||
199 (keyword ==
"keyspace")) {
203 .arg(
"unknown").arg(keyword).arg(value);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
bool configuredReadOnly() const
Convenience method checking if database should be opened with read only access.
boost::function< bool(ReconnectCtlPtr db_retry)> DbLostCallback
Defines a callback prototype for propogating events upward.
std::string getParameter(const std::string &name) const
Returns value of a connection parameter.
static std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
static isc::data::ElementPtr toElement(const ParameterMap ¶ms)
Unparse a parameter map.
static isc::data::ElementPtr toElementDbAccessString(const std::string &dbaccess)
Unparse an access string.
static DbLostCallback db_lost_callback
Optional call back function to invoke if a successfully open connection subsequently fails.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
bool invokeDbLostCallback() const
Invokes the connection's lost connectivity callback.
virtual ReconnectCtlPtr makeReconnectCtl() const
Instantiates a ReconnectCtl based on the connection's reconnect parameters.
static const time_t MAX_DB_TIME
Defines maximum value for time that can be reliably stored.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
Invalid 'readonly' value specification.
Warehouses DB reconnect control values.
We want to reuse the database backend connection and exchange code for other uses,...
#define DB_LOG_ERROR(MESSAGE)
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
boost::shared_ptr< Element > ElementPtr
isc::log::Logger database_logger("database")
Common database library logger.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Defines the logger used by the top-level component of kea-dhcp-ddns.