suport tarsnode deploy in domain

This commit is contained in:
ruanshudong 2020-03-24 21:41:56 +08:00
parent 2395491d78
commit addb77b5d5
11 changed files with 48 additions and 28 deletions

View File

@ -97,6 +97,7 @@ std::string ServerConfig::Key;
bool ServerConfig::VerifyClient = false;
#endif
map<string, string> ServerConfig::Context;
///////////////////////////////////////////////////////////////////////////////////////////
TC_Config Application::_conf;
@ -475,7 +476,7 @@ bool Application::cmdLoadProperty(const string& command, const string& params, s
ServerConfig::Config = _conf.get("/tars/application/server<config>");
TarsRemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision());
TarsRemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision(), 5);
ServerConfig::Notify = _conf.get("/tars/application/server<notify>");
@ -1049,6 +1050,7 @@ void Application::initializeServer()
ServerConfig::BackPacketLimit = TC_Common::strto<int>(_conf.get("/tars/application/server<backpacketlimit>", "100*1024*1024"));
ServerConfig::BackPacketMin = TC_Common::strto<int>(_conf.get("/tars/application/server<backpacketmin>", "1024"));
ServerConfig::Context["node_name"] = ServerConfig::LocalIp;
#if TARS_SSL
ServerConfig::CA = _conf.get("/tars/application/server<ca>");
ServerConfig::Cert = _conf.get("/tars/application/server<cert>");
@ -1149,7 +1151,7 @@ void Application::initializeServer()
///////////////////////////////////////////////////////////////////////////////////////////////////
//初始化到信息中心代理
cout << OUT_LINE << "\n" << TC_Common::outfill("[set remote notify] ") << "OK" << endl;
TarsRemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision());
TarsRemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision(), ServerConfig::LocalIp);
///////////////////////////////////////////////////////////////////////////////////////////////////
//初始化到Node的代理

View File

@ -389,16 +389,16 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName)
{
case E_ALL:
{
iRet = _queryFPrx->findObjectById4Any(_objName,activeEp,inactiveEp);
iRet = _queryFPrx->findObjectById4Any(_objName,activeEp,inactiveEp, ServerConfig::Context);
break;
}
case E_STATION:
{
iRet = _queryFPrx->findObjectByIdInSameStation(_objName,sName,activeEp,inactiveEp);
iRet = _queryFPrx->findObjectByIdInSameStation(_objName,sName,activeEp,inactiveEp, ServerConfig::Context);
}
case E_SET:
{
iRet = _queryFPrx->findObjectByIdInSameSet(_objName,sName,activeEp,inactiveEp);
iRet = _queryFPrx->findObjectByIdInSameSet(_objName,sName,activeEp,inactiveEp, ServerConfig::Context);
break;
}
case E_DEFAULT:
@ -408,11 +408,11 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName)
{
//指定set调用时指定set的优先级最高
string setId = _invokeSetId.empty()?ClientConfig::SetDivision:_invokeSetId;
iRet = _queryFPrx->findObjectByIdInSameSet(_objName,setId,activeEp,inactiveEp);
iRet = _queryFPrx->findObjectByIdInSameSet(_objName,setId,activeEp,inactiveEp, ServerConfig::Context);
}
else
{
iRet = _queryFPrx->findObjectByIdInSameGroup(_objName,activeEp,inactiveEp);
iRet = _queryFPrx->findObjectByIdInSameGroup(_objName,activeEp,inactiveEp, ServerConfig::Context);
}
break;
}
@ -425,17 +425,17 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName)
{
case E_ALL:
{
_queryFPrx->async_findObjectById4Any(this,_objName);
_queryFPrx->async_findObjectById4Any(this,_objName, ServerConfig::Context);
break;
}
case E_STATION:
{
_queryFPrx->async_findObjectByIdInSameStation(this,_objName,sName);
_queryFPrx->async_findObjectByIdInSameStation(this,_objName,sName, ServerConfig::Context);
break;
}
case E_SET:
{
_queryFPrx->async_findObjectByIdInSameSet(this,_objName,sName);
_queryFPrx->async_findObjectByIdInSameSet(this,_objName,sName, ServerConfig::Context);
break;
}
case E_DEFAULT:
@ -445,11 +445,11 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName)
{
//指定set调用时指定set的优先级最高
string setId = _invokeSetId.empty()?ClientConfig::SetDivision:_invokeSetId;
_queryFPrx->async_findObjectByIdInSameSet(this,_objName,setId);
_queryFPrx->async_findObjectByIdInSameSet(this,_objName,setId, ServerConfig::Context);
}
else
{
_queryFPrx->async_findObjectByIdInSameGroup(this,_objName);
_queryFPrx->async_findObjectByIdInSameGroup(this,_objName, ServerConfig::Context);
}
break;
}

View File

@ -19,6 +19,7 @@
#include "util/tc_timeprovider.h"
#include "servant/TarsLogger.h"
#include "servant/Communicator.h"
#include "servant/Application.h"
#include <iostream>
namespace tars
@ -477,7 +478,7 @@ int StatReport::reportMicMsg(MapStatMicMsg& msg,bool bFromClient)
if(_statPrx)
{
TLOGTARS("[TARS][StatReport::reportMicMsg send size:" << mTemp.size()<<"]"<< endl);
_statPrx->tars_set_timeout(_reportTimeout)->async_reportMicMsg(NULL,mTemp,bFromClient);
_statPrx->tars_set_timeout(_reportTimeout)->async_reportMicMsg(NULL,mTemp,bFromClient, ServerConfig::Context);
}
iLen = iTemLen;
mTemp.clear();
@ -499,7 +500,7 @@ int StatReport::reportMicMsg(MapStatMicMsg& msg,bool bFromClient)
if(_statPrx)
{
TLOGTARS("[TARS][StatReport::reportMicMsg send size:" << mTemp.size()<<"]"<< endl);
_statPrx->tars_set_timeout(_reportTimeout)->async_reportMicMsg(NULL,mTemp,bFromClient);
_statPrx->tars_set_timeout(_reportTimeout)->async_reportMicMsg(NULL,mTemp,bFromClient, ServerConfig::Context);
}
}
return 0;
@ -690,7 +691,7 @@ int StatReport::reportSampleMsg()
if(_statPrx)
{
TLOGTARS("[TARS][StatReport::reportSampleMsg send size:" << vTemp.size()<< "]"<< endl);
_statPrx->tars_set_timeout(_reportTimeout)->async_reportSampleMsg(NULL,vTemp);
_statPrx->tars_set_timeout(_reportTimeout)->async_reportSampleMsg(NULL,vTemp, ServerConfig::Context);
}
iLen = iTemLen;
vTemp.clear();
@ -702,7 +703,7 @@ int StatReport::reportSampleMsg()
if(_statPrx)
{
TLOGTARS("[TARS][StatReport::reportSampleMsg send size:" << vTemp.size()<< "]"<< endl);
_statPrx->tars_set_timeout(_reportTimeout)->async_reportSampleMsg(NULL,vTemp);
_statPrx->tars_set_timeout(_reportTimeout)->async_reportSampleMsg(NULL,vTemp, ServerConfig::Context);
}
}

View File

@ -18,6 +18,7 @@
#include "util/tc_file.h"
#include "servant/Communicator.h"
#include "servant/TarsNotify.h"
#include "servant/Application.h"
#include <fstream>
namespace tars
@ -108,7 +109,7 @@ string TarsRemoteConfig::getRemoteFile(const string &sFileName, bool bAppConfigO
{
if(_setdivision.empty())
{
ret = _configPrx->loadConfig(_app, (bAppConfigOnly ? "" : _serverName), sFileName, stream);
ret = _configPrx->loadConfig(_app, (bAppConfigOnly ? "" : _serverName), sFileName, stream, ServerConfig::Context);
}
else
{
@ -118,7 +119,7 @@ string TarsRemoteConfig::getRemoteFile(const string &sFileName, bool bAppConfigO
confInfo.filename = sFileName;
confInfo.bAppOnly = bAppConfigOnly;
confInfo.setdivision = _setdivision;
ret = _configPrx->loadConfigByInfo(confInfo,stream);
ret = _configPrx->loadConfigByInfo(confInfo,stream, ServerConfig::Context);
}
break;

View File

@ -60,10 +60,20 @@ TarsCurrent::~TarsCurrent()
}
}
const string &TarsCurrent::getHostName() const
{
auto it = _request.context.find("node_name");
if(it != _request.context.end())
{
return it->second;
}
return _data->ip();
}
const string &TarsCurrent::getIp() const
{
return _data->ip();
// return _ip;
return _data->ip();
}
int TarsCurrent::getPort() const

View File

@ -84,7 +84,7 @@ void RollWriteT::operator()(ostream &of, const deque<pair<size_t, string> > &ds)
{
try
{
_logPrx->logger(DYEING_DIR, DYEING_FILE, "roll", "%Y%m%d", vRemoteDyeing);
_logPrx->logger(DYEING_DIR, DYEING_FILE, "roll", "%Y%m%d", vRemoteDyeing, ServerConfig::Context);
}
catch(exception &ex)
{
@ -254,7 +254,7 @@ void RemoteTimeWriteT::sync2remote(const vector<string> &v)
stInfo.sSepar = _timeWrite->_separ;
stInfo.sLogType = _timeWrite->_logType;
_timeWrite->_logPrx->loggerbyInfo(stInfo,v);
_timeWrite->_logPrx->loggerbyInfo(stInfo,v, ServerConfig::Context);
if (_timeWrite->_reportSuccPtr)
{
@ -276,7 +276,7 @@ void RemoteTimeWriteT::sync2remoteDyeing(const vector<string> &v)
{
try
{
_timeWrite->_logPrx->logger(DYEING_DIR, DYEING_FILE, "", _timeWrite->_format, v);
_timeWrite->_logPrx->logger(DYEING_DIR, DYEING_FILE, "", _timeWrite->_format, v, ServerConfig::Context);
}
catch(exception &ex)
{
@ -418,7 +418,7 @@ void TimeWriteT::operator()(ostream &of, const deque<pair<size_t, string> > &buf
{
try
{
_logPrx->logger(DYEING_DIR, DYEING_FILE, "day", "%Y%m%d", vDyeingLog);
_logPrx->logger(DYEING_DIR, DYEING_FILE, "day", "%Y%m%d", vDyeingLog, ServerConfig::Context);
}
catch(exception &ex)
{

View File

@ -140,6 +140,7 @@ struct ServerConfig
static std::string Key;
static bool VerifyClient;
#endif
static map<string, string> Context; //框架内部用, 传递节点名称(以域名形式部署时)
};
class PropertyReport;

View File

@ -246,7 +246,6 @@ protected:
*/
set<EndpointInfo> _inactiveEndpoints;
private:
/////////以下是请求主控的策略信息/////////////////

View File

@ -57,7 +57,7 @@ public:
*
* @return int
*/
int setConfigInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string& basePath,const string& setdivision="",int maxBakNum=5);
int setConfigInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string& basePath,const string& setdivision="",int maxBakNum = 5);
/**
* ConfigServer上配置文件到本地

View File

@ -56,6 +56,12 @@ public:
const string &getIp() const;
/**
* get host name
* @return
*/
const string &getHostName() const;
/**
*
* @return int
*/

View File

@ -529,7 +529,7 @@ public:
* @param server,
* @param logpath,
*/
void setLogInfo(const CommunicatorPtr &comm, const string &obj, const string &sApp, const string &sServer, const string &sLogpath,const string& setdivision="", const bool &bLogStatReport = false);
void setLogInfo(const CommunicatorPtr &comm, const string &obj, const string &sApp, const string &sServer, const string &sLogpath,const string& setdivision="", const bool &bLogStatReport=false);
/**
* ("%Y%m%d")