refine code

Former-commit-id: 0f8cbbaba8cf518bdec7466169f575c0ef0f93e3
This commit is contained in:
starlord 2019-08-27 13:47:27 +08:00 committed by Yu Kun
parent 148caad58d
commit d15873f0b6
5 changed files with 14 additions and 14 deletions

View File

@ -3,14 +3,14 @@
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#include "IConfigMgr.h"
#include "ConfigMgr.h"
#include "YamlConfigMgr.h"
namespace zilliz {
namespace milvus {
namespace server {
IConfigMgr * IConfigMgr::GetInstance() {
ConfigMgr * ConfigMgr::GetInstance() {
static YamlConfigMgr mgr;
return &mgr;
}

View File

@ -20,15 +20,15 @@ namespace server {
// DDD: 23.5
//
// usage
// const IConfigMgr* mgr = IConfigMgr::GetInstance();
// const ConfigMgr* mgr = ConfigMgr::GetInstance();
// const ConfigNode& node = mgr->GetRootNode();
// std::string val = node.GetValue("AAA"); // return '1'
// const ConfigNode& child = node.GetChild("BBB");
// val = child.GetValue("CCC"); //return 'hello'
class IConfigMgr {
class ConfigMgr {
public:
static IConfigMgr* GetInstance();
static ConfigMgr* GetInstance();
virtual ServerError LoadConfigFile(const std::string &filename) = 0;
virtual void Print() const = 0;//will be deleted

View File

@ -5,7 +5,7 @@
******************************************************************************/
#pragma once
#include "IConfigMgr.h"
#include "ConfigMgr.h"
#include "ConfigNode.h"
#include "utils/Error.h"
@ -15,7 +15,7 @@ namespace zilliz {
namespace milvus {
namespace server {
class YamlConfigMgr : public IConfigMgr {
class YamlConfigMgr : public ConfigMgr {
public:
virtual ServerError LoadConfigFile(const std::string &filename);
virtual void Print() const;

View File

@ -11,7 +11,7 @@
#include <stdlib.h>
#include <iostream>
#include "config/IConfigMgr.h"
#include "config/ConfigMgr.h"
#include "utils/CommonUtil.h"
#include "utils/ValidationUtil.h"
@ -43,7 +43,7 @@ ServerConfig::LoadConfigFile(const std::string& config_filename) {
}
try {
IConfigMgr* mgr = const_cast<IConfigMgr*>(IConfigMgr::GetInstance());
ConfigMgr* mgr = const_cast<ConfigMgr*>(ConfigMgr::GetInstance());
ServerError err = mgr->LoadConfigFile(filename);
if(err != 0) {
std::cout << "Server failed to load config file" << std::endl;
@ -106,7 +106,7 @@ ServerError ServerConfig::ValidateConfig() const {
void
ServerConfig::PrintAll() const {
if(const IConfigMgr* mgr = IConfigMgr::GetInstance()) {
if(const ConfigMgr* mgr = ConfigMgr::GetInstance()) {
std::string str = mgr->DumpString();
// SERVER_LOG_INFO << "\n" << str;
std::cout << "\n" << str << std::endl;
@ -115,14 +115,14 @@ ServerConfig::PrintAll() const {
ConfigNode
ServerConfig::GetConfig(const std::string& name) const {
const IConfigMgr* mgr = IConfigMgr::GetInstance();
const ConfigMgr* mgr = ConfigMgr::GetInstance();
const ConfigNode& root_node = mgr->GetRootNode();
return root_node.GetChild(name);
}
ConfigNode&
ServerConfig::GetConfig(const std::string& name) {
IConfigMgr* mgr = IConfigMgr::GetInstance();
ConfigMgr* mgr = ConfigMgr::GetInstance();
ConfigNode& root_node = mgr->GetRootNode();
return root_node.GetChild(name);
}

View File

@ -6,7 +6,7 @@
#include <gtest/gtest.h>
#include <gtest/gtest-death-test.h>
#include "config/IConfigMgr.h"
#include "config/ConfigMgr.h"
#include "server/ServerConfig.h"
#include "utils/CommonUtil.h"
#include "utils/ValidationUtil.h"
@ -25,7 +25,7 @@ static constexpr uint64_t GB = MB*1024;
}
TEST(ConfigTest, CONFIG_TEST) {
server::IConfigMgr* config_mgr = server::IConfigMgr::GetInstance();
server::ConfigMgr* config_mgr = server::ConfigMgr::GetInstance();
server::ServerError err = config_mgr->LoadConfigFile("");
ASSERT_EQ(err, server::SERVER_UNEXPECTED_ERROR);