提交 9f739a93 编写于 作者: Z zhiru

Config file validation


Former-commit-id: a49c32a0b5a9736e0151a5054cd9a10fd8828bae
上级 88a625e6
......@@ -107,6 +107,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-525 - Disable parallel reduce in SearchTask
- MS-527 - Update scheduler_test and enable it
- MS-528 - Hide some config used future
- MS-523 - Config file validation
## New Feature
- MS-343 - Implement ResourceMgr
......
server_config:
address: 0.0.0.0 # milvus server ip address
address: 0.0.0.0 # milvus server ip address (IPv4)
port: 19530 # the port milvus listen to, default: 19530, range: 1025 ~ 65534
gpu_index: 0 # the gpu milvus use, default: 0, range: 0 ~ gpu number - 1
mode: single # milvus deployment type: single, cluster, read_only
......
此差异已折叠。
......@@ -69,11 +69,19 @@ class ServerConfig {
static ServerConfig &GetInstance();
ErrorCode LoadConfigFile(const std::string& config_filename);
ErrorCode ValidateConfig() const;
ErrorCode ValidateConfig();
void PrintAll() const;
ConfigNode GetConfig(const std::string& name) const;
ConfigNode& GetConfig(const std::string& name);
private:
ErrorCode CheckServerConfig();
ErrorCode CheckDBConfig();
ErrorCode CheckMetricConfig();
ErrorCode CheckCacheConfig();
ErrorCode CheckEngineConfig();
ErrorCode CheckResourceConfig();
};
}
......
......@@ -4,6 +4,11 @@
#include <cuda_runtime.h>
#include <arpa/inet.h>
#include <regex>
#include <algorithm>
namespace zilliz {
namespace milvus {
namespace server {
......@@ -139,6 +144,110 @@ ValidationUtil::GetGpuMemory(uint32_t gpu_index, size_t& memory) {
return SERVER_SUCCESS;
}
ErrorCode
ValidationUtil::ValidateIpAddress(const std::string &ip_address) {
struct in_addr address;
int result = inet_pton(AF_INET, ip_address.c_str(), &address);
switch(result) {
case 1:
return SERVER_SUCCESS;
case 0:
SERVER_LOG_ERROR << "Invalid IP address: " << ip_address;
return SERVER_INVALID_ARGUMENT;
default:
SERVER_LOG_ERROR << "inet_pton conversion error";
return SERVER_UNEXPECTED_ERROR;
}
}
ErrorCode
ValidationUtil::ValidateStringIsNumber(const std::string &string) {
if (!string.empty() && std::all_of(string.begin(), string.end(), ::isdigit)) {
return SERVER_SUCCESS;
}
else {
return SERVER_INVALID_ARGUMENT;
}
}
ErrorCode
ValidationUtil::ValidateStringIsBool(std::string &str) {
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
if (str == "true" || str == "on" || str == "yes" || str == "1" ||
str == "false" || str == "off" || str == "no" || str == "0" ||
str.empty()) {
return SERVER_SUCCESS;
}
else {
return SERVER_INVALID_ARGUMENT;
}
}
ErrorCode
ValidationUtil::ValidateStringIsDouble(const std::string &str, double &val) {
char* end = nullptr;
val = std::strtod(str.c_str(), &end);
if (end != str.c_str() && *end == '\0' && val != HUGE_VAL) {
return SERVER_SUCCESS;
}
else {
return SERVER_INVALID_ARGUMENT;
}
}
ErrorCode
ValidationUtil::ValidateDbURI(const std::string &uri) {
std::string dialectRegex = "(.*)";
std::string usernameRegex = "(.*)";
std::string passwordRegex = "(.*)";
std::string hostRegex = "(.*)";
std::string portRegex = "(.*)";
std::string dbNameRegex = "(.*)";
std::string uriRegexStr = dialectRegex + "\\:\\/\\/" +
usernameRegex + "\\:" +
passwordRegex + "\\@" +
hostRegex + "\\:" +
portRegex + "\\/" +
dbNameRegex;
std::regex uriRegex(uriRegexStr);
std::smatch pieces_match;
bool okay = true;
if (std::regex_match(uri, pieces_match, uriRegex)) {
std::string dialect = pieces_match[1].str();
std::transform(dialect.begin(), dialect.end(), dialect.begin(), ::tolower);
if (dialect.find("mysql") == std::string::npos && dialect.find("sqlite") == std::string::npos) {
SERVER_LOG_ERROR << "Invalid dialect in URI: dialect = " << dialect;
okay = false;
}
std::string host = pieces_match[4].str();
if (!host.empty() && host != "localhost") {
if (ValidateIpAddress(host) != SERVER_SUCCESS) {
SERVER_LOG_ERROR << "Invalid host ip address in uri = " << host;
okay = false;
}
}
std::string port = pieces_match[5].str();
if (!port.empty()) {
if (ValidateStringIsNumber(port) != SERVER_SUCCESS) {
SERVER_LOG_ERROR << "Invalid port in uri = " << port;
okay = false;
}
}
} else {
SERVER_LOG_ERROR << "Wrong URI format: URI = " << uri;
okay = false;
}
return (okay ? SERVER_SUCCESS : SERVER_INVALID_ARGUMENT);
}
}
}
}
\ No newline at end of file
......@@ -40,7 +40,19 @@ public:
GetGpuMemory(uint32_t gpu_index, size_t &memory);
static ErrorCode
ValidateConfig();
ValidateIpAddress(const std::string &ip_address);
static ErrorCode
ValidateStringIsNumber(const std::string &str);
static ErrorCode
ValidateStringIsBool(std::string &str);
static ErrorCode
ValidateStringIsDouble(const std::string &str, double &val);
static ErrorCode
ValidateDbURI(const std::string &uri);
};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册