Skip to content

Commit

Permalink
add config interface
Browse files Browse the repository at this point in the history
  • Loading branch information
suziliu committed Feb 23, 2017
1 parent b74ec59 commit 362965f
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
89 changes: 89 additions & 0 deletions cpp/framework/ConfigServer/ConfigImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,92 @@ bool ConfigImp::IsLimited(const std::string & app, const std::string & server, c
return bLimited;
}

int ConfigImp::ListAllConfigByInfo(const tars::GetConfigListInfo & configInfo, vector<std::string> &vf, tars::TarsCurrentPtr current)
{
CHECKLIMIT(configInfo.appname,configInfo.servername,current->getIp(),"");

try
{
if(configInfo.bAppOnly)
{
//查ip对应配置
string sSql = "select distinct filename from t_config_files "
"where server_name = '" + _mysqlConfig.escapeString(configInfo.appname) + "' "
"and level=" + TC_Common::tostr<int>(eLevelApp);

TLOGDEBUG("ConfigImp::ListAllConfigByInfo sql:" << sSql << endl);

TC_Mysql::MysqlData res = _mysqlConfig.queryRecord(sSql);

TLOGDEBUG("ConfigImp::ListAllConfigByInfo sql:" << sSql << "|res:" << res.size() << endl);

for(unsigned i=0; i<res.size();i++)
{
vf.push_back(res[i]["filename"]);
}

return 0;
}
else
{
string sHost = configInfo.host;
string sContainer = configInfo.containername;
string sSql = "select distinct filename from t_config_files where server_name = '" + _mysqlConfig.escapeString(configInfo.appname+"."+configInfo.servername) + "' ";

string sCondition("");
if(!sHost.empty())
{
sCondition += " and host='"+_mysqlConfig.escapeString(sHost)+"' ";
sCondition += " and level=" + TC_Common::tostr<int>(eLevelIpServer);
}

if(!configInfo.setdivision.empty())
{
string sSetName,sSetArea,sSetGroup;
if(getSetInfo(sSetName,sSetArea,sSetGroup,configInfo.setdivision))
{
sCondition += " and set_name='" +_mysqlConfig.escapeString(sSetName)+"' ";
sCondition += " and set_area='" +_mysqlConfig.escapeString(sSetArea)+"' ";
sCondition += " and set_group='" +_mysqlConfig.escapeString(sSetGroup)+"' ";
}
else
{
TLOGERROR("ConfigImp::ListAllConfigByInfo setdivision is invalid:" << configInfo.setdivision << endl);
return -1;
}
}
else//兼容没有set信息的业务
{
string sNULL;
sCondition += " and set_name='" + _mysqlConfig.escapeString(sNULL) +"' ";
sCondition += " and set_area='" + _mysqlConfig.escapeString(sNULL) +"' ";
sCondition += " and set_group='" + _mysqlConfig.escapeString(sNULL) +"' ";
}

sSql += sCondition;

TLOGDEBUG("ConfigImp::ListAllConfigByInfo sql:" << sSql << endl);

TC_Mysql::MysqlData res = _mysqlConfig.queryRecord(sSql);

TLOGDEBUG("ConfigImp::ListAllConfigByInfo sql:" << sSql << "|res:" << res.size() << endl);

for(unsigned i=0; i<res.size();i++)
{
vf.push_back(res[i]["filename"]);
}
}
}
catch(TC_Mysql_Exception & ex)
{
TLOGERROR("ConfigImp::ListAllConfigByInfo mysql exception:" << ex.what() << endl);
return -1;
}
catch(exception& ex)
{
TLOGERROR("ConfigImp::ListAllConfigByInfo exception:" << ex.what() << endl);
return -1;
}

return 0;
}
8 changes: 8 additions & 0 deletions cpp/framework/ConfigServer/ConfigImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ class ConfigImp : public Config
*/
virtual int checkConfigByInfo(const ConfigInfo & configInfo, string &result,tars::TarsCurrentPtr current);

/**
* 获取服务的所有配置文件列表,
* @param configInfo 支持拉取应用配置列表,服务配置列表,机器配置列表
* @param[out] vf 获取到的文件名称列表
* @return int 0: 成功, -1:失败
**/
virtual int ListAllConfigByInfo(const tars::GetConfigListInfo & configInfo, vector<std::string> &vf, tars::TarsCurrentPtr current);

protected:

/**
Expand Down
8 changes: 8 additions & 0 deletions cpp/servant/protocol/ConfigF.tars
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ module tars
* @return int 0: 合法, -1:非法
**/
int checkConfigByInfo(ConfigInfo configInfo, out string result);

/**
* 获取服务的所有配置文件列表,
* @param configInfo 支持拉取应用配置列表,服务配置列表,机器配置列表
* @param[out] vf 获取到的文件名称列表
* @return int 0: 成功, -1:失败
**/
int ListAllConfigByInfo(GetConfigListInfo configInfo, out vector<string> vf);

};
};
Expand Down

0 comments on commit 362965f

Please sign in to comment.