提交 ee7fb368 编写于 作者: Y yudong.cai

MS-574 add config check


Former-commit-id: ac1ed68cc7fcd08cde02bccbd574ac34fdbfdb97
上级 0d0d08c2
......@@ -18,7 +18,8 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-562 - Add JobMgr and TaskCreator in Scheduler
- MS-566 - Refactor cmake
- MS-555 - Remove old scheduler
- MS-578 - Makesure milvus5.0 don't crack 0.3.1 data
- MS-574 - Milvus configuration refactor
- MS-578 - Make sure milvus5.0 don't crack 0.3.1 data
## New Feature
......
此差异已折叠。
......@@ -95,64 +95,92 @@ static const char* CONFIG_RESOURCE_POOL = "pool";
class Config {
public:
static Config &GetInstance();
static Config& GetInstance();
Status LoadConfigFile(const std::string& filename);
Status ValidateConfig();
void PrintAll() const;
void PrintAll();
private:
ConfigNode& GetConfigNode(const std::string& name);
Status CheckServerConfig();
Status CheckDBConfig();
Status CheckMetricConfig();
Status CheckCacheConfig();
Status CheckEngineConfig();
Status CheckResourceConfig();
Status GetConfigValueInMem(const std::string& parent_key,
const std::string& child_key,
std::string& value);
Status SetConfigValueInMem(const std::string& parent_key,
void SetConfigValueInMem(const std::string& parent_key,
const std::string& child_key,
std::string& value);
private:
void PrintConfigSection(const std::string& config_node_name);
///////////////////////////////////////////////////////////////////////////
/* server config */
Status CheckServerConfigAddress(std::string& value);
Status CheckServerConfigPort(std::string& value);
Status CheckServerConfigMode(std::string& value);
Status CheckServerConfigTimeZone(std::string& value);
/* db config */
Status CheckDBConfigPath(const std::string& value);
Status CheckDBConfigSlavePath(const std::string& value);
Status CheckDBConfigBackendUrl(const std::string& value);
Status CheckDBConfigArchiveDiskThreshold(const std::string& value);
Status CheckDBConfigArchiveDaysThreshold(const std::string& value);
Status CheckDBConfigBufferSize(const std::string& value);
Status CheckDBConfigBuildIndexGPU(const std::string& value);
/* metric config */
Status CheckMetricConfigAutoBootup(const std::string& value);
Status CheckMetricConfigPrometheusPort(const std::string& value);
/* cache config */
Status CheckCacheConfigCpuMemCapacity(const std::string& value);
Status CheckCacheConfigCpuMemThreshold(const std::string& value);
Status CheckCacheConfigGpuMemCapacity(const std::string& value);
Status CheckCacheConfigGpuMemThreshold(const std::string& value);
Status CheckCacheConfigCacheInsertData(const std::string& value);
/* engine config */
Status CheckEngineConfigBlasThreshold(const std::string& value);
Status CheckEngineConfigOmpThreadNum(const std::string& value);
/* resource config */
Status CheckResourceConfigMode(const std::string& value);
Status CheckResourceConfigPool(const std::vector<std::string>& value);
///////////////////////////////////////////////////////////////////////////
/* server config */
Status GetServerConfigStrAddress(std::string& value);
Status GetServerConfigStrPort(std::string& value);
Status GetServerConfigStrMode(std::string& value);
Status GetServerConfigStrTimeZone(std::string& value);
std::string GetServerConfigStrAddress();
std::string GetServerConfigStrPort();
std::string GetServerConfigStrMode();
std::string GetServerConfigStrTimeZone();
/* db config */
Status GetDBConfigStrPath(std::string& value);
Status GetDBConfigStrSlavePath(std::string& value);
Status GetDBConfigStrBackendUrl(std::string& value);
Status GetDBConfigStrArchiveDiskThreshold(std::string& value);
Status GetDBConfigStrArchiveDaysThreshold(std::string& value);
Status GetDBConfigStrBufferSize(std::string& value);
Status GetDBConfigStrBuildIndexGPU(std::string& value);
std::string GetDBConfigStrPath();
std::string GetDBConfigStrSlavePath();
std::string GetDBConfigStrBackendUrl();
std::string GetDBConfigStrArchiveDiskThreshold();
std::string GetDBConfigStrArchiveDaysThreshold();
std::string GetDBConfigStrBufferSize();
std::string GetDBConfigStrBuildIndexGPU();
/* metric config */
Status GetMetricConfigStrAutoBootup(std::string& value);
Status GetMetricConfigStrCollector(std::string& value);
Status GetMetricConfigStrPrometheusPort(std::string& value);
std::string GetMetricConfigStrAutoBootup();
std::string GetMetricConfigStrCollector();
std::string GetMetricConfigStrPrometheusPort();
/* cache config */
Status GetCacheConfigStrCpuMemCapacity(std::string& value);
Status GetCacheConfigStrCpuMemThreshold(std::string& value);
Status GetCacheConfigStrGpuMemCapacity(std::string& value);
Status GetCacheConfigStrGpuMemThreshold(std::string& value);
Status GetCacheConfigStrCacheInsertData(std::string& value);
std::string GetCacheConfigStrCpuMemCapacity();
std::string GetCacheConfigStrCpuMemThreshold();
std::string GetCacheConfigStrGpuMemCapacity();
std::string GetCacheConfigStrGpuMemThreshold();
std::string GetCacheConfigStrCacheInsertData();
/* engine config */
Status GetEngineConfigStrBlasThreshold(std::string& value);
Status GetEngineConfigStrOmpThreadNum(std::string& value);
std::string GetEngineConfigStrBlasThreshold();
std::string GetEngineConfigStrOmpThreadNum();
/* resource config */
Status GetResourceConfigStrMode(std::string& value);
std::string GetResourceConfigStrMode();
public:
/* server config */
......
......@@ -235,14 +235,12 @@ Server::Stop() {
ErrorCode
Server::LoadConfig() {
Config& server_config = Config::GetInstance();
server_config.LoadConfigFile(config_filename_);
auto status = server_config.ValidateConfig();
if (!status.ok()) {
Config& config = Config::GetInstance();
Status s = config.LoadConfigFile(config_filename_);
if (!s.ok()) {
std::cerr << "Failed to load config file: " << config_filename_ << std::endl;
exit(0);
}
return SERVER_SUCCESS;
}
......
......@@ -206,38 +206,40 @@ ValidationUtil::ValidateIpAddress(const std::string &ip_address) {
}
Status
ValidationUtil::ValidateStringIsNumber(const std::string &string) {
if (!string.empty() && std::all_of(string.begin(), string.end(), ::isdigit)) {
return Status::OK();
ValidationUtil::ValidateStringIsNumber(const std::string &str) {
if (str.empty() || !std::all_of(str.begin(), str.end(), ::isdigit)) {
return Status(SERVER_INVALID_ARGUMENT, "Invalid number");
}
else {
return Status(SERVER_INVALID_ARGUMENT, "Not a number");
try {
int32_t value = std::stoi(str);
} catch(...) {
return Status(SERVER_INVALID_ARGUMENT, "Invalid number");
}
return Status::OK();
}
Status
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()) {
ValidationUtil::ValidateStringIsBool(const std::string &str) {
std::string s = str;
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
if (s == "true" || s == "on" || s == "yes" || s == "1" ||
s == "false" || s == "off" || s == "no" || s == "0" ||
s.empty()) {
return Status::OK();
}
else {
return Status(SERVER_INVALID_ARGUMENT, "Not a boolean: " + str);
return Status(SERVER_INVALID_ARGUMENT, "Invalid boolean: " + str);
}
}
Status
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 Status::OK();
}
else {
return Status(SERVER_INVALID_ARGUMENT, "Not a double value: " + str);
ValidationUtil::ValidateStringIsFloat(const std::string &str) {
try {
float val = std::stof(str);
} catch(...) {
return Status(SERVER_INVALID_ARGUMENT, "Invalid float: " + str);
}
return Status::OK();
}
Status
......
......@@ -67,10 +67,10 @@ public:
ValidateStringIsNumber(const std::string &str);
static Status
ValidateStringIsBool(std::string &str);
ValidateStringIsBool(const std::string &str);
static Status
ValidateStringIsDouble(const std::string &str, double &val);
ValidateStringIsFloat(const std::string &str);
static Status
ValidateDbURI(const std::string &uri);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册