-// Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2023 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
if ((keyword == "lfc-interval") ||
(keyword == "connect-timeout") ||
+ (keyword == "read-timeout") ||
+ (keyword == "write-timeout") ||
+ (keyword == "tcp-user-timeout") ||
(keyword == "reconnect-wait-time") ||
(keyword == "max-reconnect-tries") ||
(keyword == "port") ||
int_value = boost::lexical_cast<int64_t>(value);
result->set(keyword, isc::data::Element::create(int_value));
} catch (...) {
- LOG_ERROR(database_logger, DATABASE_TO_JSON_ERROR)
- .arg("integer").arg(keyword).arg(value);
+ LOG_ERROR(database_logger, DATABASE_TO_JSON_INTEGER_ERROR)
+ .arg(keyword).arg(value);
}
} else if ((keyword == "persist") ||
(keyword == "readonly")) {
} else if (value == "false") {
result->set(keyword, isc::data::Element::create(false));
} else {
- LOG_ERROR(database_logger, DATABASE_TO_JSON_ERROR)
- .arg("boolean").arg(keyword).arg(value);
+ LOG_ERROR(database_logger, DATABASE_TO_JSON_BOOLEAN_ERROR)
+ .arg(keyword).arg(value);
}
} else if ((keyword == "type") ||
(keyword == "user") ||
(keyword == "cipher-list")) {
result->set(keyword, isc::data::Element::create(value));
} else {
- LOG_ERROR(database_logger, DATABASE_TO_JSON_ERROR)
- .arg("unknown").arg(keyword).arg(value);
+ LOG_ERROR(database_logger, DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR)
+ .arg(keyword).arg(value);
}
}
extern const isc::log::MessageID DATABASE_PGSQL_ROLLBACK = "DATABASE_PGSQL_ROLLBACK";
extern const isc::log::MessageID DATABASE_PGSQL_ROLLBACK_SAVEPOINT = "DATABASE_PGSQL_ROLLBACK_SAVEPOINT";
extern const isc::log::MessageID DATABASE_PGSQL_START_TRANSACTION = "DATABASE_PGSQL_START_TRANSACTION";
-extern const isc::log::MessageID DATABASE_TO_JSON_ERROR = "DATABASE_TO_JSON_ERROR";
+extern const isc::log::MessageID DATABASE_TO_JSON_BOOLEAN_ERROR = "DATABASE_TO_JSON_BOOLEAN_ERROR";
+extern const isc::log::MessageID DATABASE_TO_JSON_INTEGER_ERROR = "DATABASE_TO_JSON_INTEGER_ERROR";
+extern const isc::log::MessageID DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR = "DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR";
} // namespace db
} // namespace isc
"DATABASE_PGSQL_ROLLBACK", "rolling back PostgreSQL database",
"DATABASE_PGSQL_ROLLBACK_SAVEPOINT", "rolling back PostgreSQL database to savepoint: $1",
"DATABASE_PGSQL_START_TRANSACTION", "starting a new PostgreSQL transaction",
- "DATABASE_TO_JSON_ERROR", "Internal logic error: unknown %1 element found in state: %2",
+ "DATABASE_TO_JSON_BOOLEAN_ERROR", "Internal logic error: invalid boolean value found in database connection parameters: %1=%2",
+ "DATABASE_TO_JSON_INTEGER_ERROR", "Internal logic error: invalid integer value found in database connection parameters: %1=%2",
+ "DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR", "Internal logic error: unknown element found in database connection parameters: %1=%2",
NULL
};
extern const isc::log::MessageID DATABASE_PGSQL_ROLLBACK;
extern const isc::log::MessageID DATABASE_PGSQL_ROLLBACK_SAVEPOINT;
extern const isc::log::MessageID DATABASE_PGSQL_START_TRANSACTION;
-extern const isc::log::MessageID DATABASE_TO_JSON_ERROR;
+extern const isc::log::MessageID DATABASE_TO_JSON_BOOLEAN_ERROR;
+extern const isc::log::MessageID DATABASE_TO_JSON_INTEGER_ERROR;
+extern const isc::log::MessageID DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR;
} // namespace db
} // namespace isc
-# Copyright (C) 2012-2022 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2012-2023 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
and there may be a need to rollback the whole transaction if
any of these INSERT statements fail.
-% DATABASE_TO_JSON_ERROR Internal logic error: unknown %1 element found in state: %2
+% DATABASE_TO_JSON_BOOLEAN_ERROR Internal logic error: invalid boolean value found in database connection parameters: %1=%2
This error message is printed when conversion to JSON of the internal state is requested,
-but the connection string contains unrecognized parameter. This is a programming error.
+but the connection string contains a boolean parameter with invalid value. It is a programming
+error. The software will continue operation, but the returned JSON data will be syntactically
+valid, but incomplete. The culprit parameter will not be converted.
+
+% DATABASE_TO_JSON_INTEGER_ERROR Internal logic error: invalid integer value found in database connection parameters: %1=%2
+This error message is printed when conversion to JSON of the internal state is requested,
+but the connection string contains the integer parameter with a wrong value. It is a programming
+error. The software will continue operation, but the returned JSON data will be syntactically
+valid, but incomplete. The culprit parameter will not be converted.
+
+% DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR Internal logic error: unknown element found in database connection parameters: %1=%2
+This error message is printed when conversion to JSON of the internal state is requested,
+but the connection string contains unrecognized parameter. It is a programming error.
The software will continue operation, but the returned JSON data will be syntactically
valid, but incomplete. The unknown parameter will not be converted.
-// Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2023 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
TEST(DatabaseConnection, toElementDbAccessStringValid) {
const char* configs[] = {
"{\n"
- "\"connect-timeout\" : 200, \n"
+ "\"connect-timeout\": 200, \n"
"\"on-fail\": \"stop-retry-exit\", \n"
"\"lfc-interval\" : 100, \n"
"\"host\": \"whatevah\", \n"
ASSERT_TRUE(json_elements->equals(*round_trip));
}
+// Check that the toElementDbAccessString() handles Postgres backend
+// specific paramateres.
+TEST(DatabaseConnection, toElementDbAccessStringValidPostgresql) {
+ const char* configs[] = {
+ "{\n"
+ "\"connect-timeout\": 200, \n"
+ "\"tcp-user-timeout\": 10, \n"
+ "\"type\": \"postgresql\", \n"
+ "\"user\": \"user_str\" \n"
+ "}\n"
+ };
+
+ DbAccessParser parser;
+ std::string access_str;
+ ConstElementPtr json_elements;
+
+ ASSERT_NO_THROW(json_elements = Element::fromJSON(configs[0]));
+ ASSERT_NO_THROW(parser.parse(access_str, json_elements));
+
+ ElementPtr round_trip = DatabaseConnection::toElementDbAccessString(access_str);
+
+ ASSERT_TRUE(json_elements->equals(*round_trip));
+}
+
+// Check that the toElementDbAccessString() handles MySQL backend
+// specific paramateres.
+TEST(DatabaseConnection, toElementDbAccessStringValidMySql) {
+ const char* configs[] = {
+ "{\n"
+ "\"connect-timeout\": 200, \n"
+ "\"read-timeout\": 10, \n"
+ "\"write-timeout\": 10, \n"
+ "\"type\": \"mysql\", \n"
+ "\"user\": \"user_str\" \n"
+ "}\n"
+ };
+
+ DbAccessParser parser;
+ std::string access_str;
+ ConstElementPtr json_elements;
+
+ ASSERT_NO_THROW(json_elements = Element::fromJSON(configs[0]));
+ ASSERT_NO_THROW(parser.parse(access_str, json_elements));
+
+ ElementPtr round_trip = DatabaseConnection::toElementDbAccessString(access_str);
+
+ ASSERT_TRUE(json_elements->equals(*round_trip));
+}
+
// Check that toElementDbAccessString() catches invalid parameters.
// Note that because toElementDbAccessString() utilizes
// toElement() this tests both.