Skip to content

Commit 168b9ed

Browse files
committed
fix tarsnotify eType default value
1 parent 27327af commit 168b9ed

File tree

5 files changed

+85
-133
lines changed

5 files changed

+85
-133
lines changed

CMakeLists.txt

-44
Original file line numberDiff line numberDiff line change
@@ -63,52 +63,9 @@ macro(complice_module MODULE)
6363
endif()
6464
endmacro()
6565

66-
# #调用tars2cpp, 生成tars对应的文件
67-
# macro(complice_tars_framework OUT_DEPENDS_LIST)
68-
# set(DEPENDS_LIST)
69-
70-
# set(SERVANT_PROTOCOL "${servant_SOURCE_DIR}/protocol/servant")
71-
72-
# set(CLEAN_LIST)
73-
74-
# set(CURRENT_PROTOCOL_DIR ${CMAKE_CURRENT_SOURCE_DIR})
75-
76-
# FILE(GLOB SRC_LIST "${CURRENT_PROTOCOL_DIR}/*.tars")
77-
78-
# foreach (FILE ${SRC_LIST})
79-
80-
# #设置tars文件搜索路径
81-
# set(INCLUDE_STRING "--include=\"${SERVANT_PROTOCOL}\"")
82-
83-
# get_filename_component(NAME_WE ${FILE} NAME_WE)
84-
85-
# # 生成tars文件
86-
# set(TARS_IN ${FILE})
87-
# set(TARS_H ${NAME_WE}.h)
88-
89-
# add_custom_command(
90-
# OUTPUT ${CURRENT_PROTOCOL_DIR}/${TARS_H}
91-
# WORKING_DIRECTORY ${CURRENT_PROTOCOL_DIR}
92-
# DEPENDS tars2cpp ${TARS_IN}
93-
# COMMAND ${TARS2CPP} --with-tars ${INCLUDE_STRING} ${TARS_IN}
94-
# COMMENT "${TARS2CPP} --with-tars ${INCLUDE_STRING} ${TARS_IN}")
95-
96-
# list(APPEND DEPENDS_LIST ${CURRENT_PROTOCOL_DIR}/${TARS_H})
97-
98-
# #设置需要清除的文件
99-
# list(APPEND CLEAN_LIST ${CURRENT_PROTOCOL_DIR}/${TARS_H})
100-
101-
# endforeach ()
102-
103-
# set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN_LIST}")
104-
105-
# set(OUT_DEPENDS_LIST ${DEPENDS_LIST})
106-
# endmacro()
107-
10866
add_subdirectory(mysql-tool)
10967
#add_subdirectory(tars-client)
11068

111-
# add_subdirectory(tarscpp/servant/protocol/framework)
11269
add_subdirectory(ConfigServer)
11370
add_subdirectory(NodeServer)
11471
add_subdirectory(NotifyServer)
@@ -132,7 +89,6 @@ list(APPEND DEPENDS_LIST tarsAdminRegistry)
13289
list(APPEND DEPENDS_LIST tarspatch)
13390
list(APPEND DEPENDS_LIST tarsconfig)
13491

135-
#set(FRAMEWORK-TGZ "${CMAKE_BINARY_DIR}/framework-tmp.tgz")
13692
set(FRAMEWORK-TGZ "${CMAKE_BINARY_DIR}/framework.tgz")
13793

13894
#执行命令

NodeServer/NodeRollLogger.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ RollLoggerManager::RollLoggerManager()
2626

2727
RollLoggerManager::~RollLoggerManager()
2828
{
29-
3029
map<string, RollLogger*>::iterator it = _loggers.begin();
3130
while(it != _loggers.end())
3231
{
@@ -37,7 +36,6 @@ RollLoggerManager::~RollLoggerManager()
3736
}
3837

3938
void RollLoggerManager::setLogInfo(const string &sApp, const string &sServer, const string &sLogpath, int iMaxSize, int iMaxNum, const CommunicatorPtr &comm, const string &sLogObj)
40-
//void RollLoggerManager::setLogInfo(const string &sApp, const string &sServer, const string &sLogpath, int iMaxSize, int iMaxNum, const string &sLogObj)
4139
{
4240
_app = sApp;
4341
_server = sServer;
@@ -80,7 +78,6 @@ RollLoggerManager::RollLogger* RollLoggerManager::logger(const string &sFile)
8078
if( it == _loggers.end())
8179
{
8280
RollLogger *p = new RollLogger();
83-
//p->modFlag(RollLogger::HAS_MTIME);
8481
initRollLogger(p, sFile, "%Y%m%d");
8582
_loggers[sFile] = p;
8683
return p;
@@ -91,17 +88,14 @@ RollLoggerManager::RollLogger* RollLoggerManager::logger(const string &sFile)
9188

9289
void RollLoggerManager::initRollLogger(RollLogger *pRollLogger, const string &sFile, const string &sFormat)
9390
{
94-
9591
//初始化本地循环日志
96-
pRollLogger->init(_logpath + "/" + _app + "/" + _server + "/" + _app + "." + _server + "_" + sFile, _maxSize, _maxNum);
92+
pRollLogger->init(_logpath + FILE_SEP + _app + FILE_SEP + _server + FILE_SEP + _app + "." + _server + "_" + sFile, _maxSize, _maxNum);
9793
pRollLogger->modFlag(TC_DayLogger::HAS_TIME, false);
9894
pRollLogger->modFlag(TC_DayLogger::HAS_TIME|TC_DayLogger::HAS_LEVEL|TC_DayLogger::HAS_PID, true);
9995

10096
//设置为异步
10197
sync(pRollLogger, false);
10298

103-
10499
//设置染色日志信息
105100
pRollLogger->getWriteT().setDyeingLogInfo(_app, _server, _logpath, _maxSize, _maxNum, _comm, _logObj);
106-
// pRollLogger->getWriteT().setDyeingLogInfo(_app, _server, _logpath, _maxSize, _maxNum, _logObj);
107101
}

NodeServer/NodeRollLogger.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* 循环日志单件是永生不死的, 保证任何地方都可以使用
3232
* 当该对象析构以后, 则直接cout出来
3333
*/
34-
class RollLoggerManager : public TC_ThreadLock, public TC_Singleton<RollLoggerManager, CreateUsingNew, DefaultLifetime>
34+
class RollLoggerManager : public TC_ThreadLock, public TC_Singleton<RollLoggerManager, CreateUsingNew, NoDestroyLifetime>
3535
{
3636
public:
3737
enum
@@ -40,7 +40,7 @@ class RollLoggerManager : public TC_ThreadLock, public TC_Singleton<RollLoggerMa
4040
ERROR_LOG = 2, /**写错误log*/
4141
WARN_LOG = 3, /**写错误,警告log*/
4242
DEBUG_LOG = 4, /**写错误,警告,调试log*/
43-
INFO_LOG = 5 /**写错误,警告,调试,Info log*/
43+
INFO_LOG = 5 /**写错误,警告,调试,Info log*/
4444
};
4545
public:
4646

@@ -94,10 +94,10 @@ class RollLoggerManager : public TC_ThreadLock, public TC_Singleton<RollLoggerMa
9494
*/
9595
string _logpath;
9696

97-
int _maxSize;
98-
int _maxNum;
97+
int _maxSize;
98+
int _maxNum;
9999
CommunicatorPtr _comm;
100-
string _logObj;
100+
string _logObj;
101101

102102
/**
103103
* 本地线程组

NotifyServer/NotifyImp.cpp

+79-76
Original file line numberDiff line numberDiff line change
@@ -217,82 +217,8 @@ void NotifyImp::reportNotifyInfo(const tars::ReportInfo & info, tars::TarsCurren
217217
{
218218
nodeId = current->getIp();
219219
}
220-
221220
switch (info.eType)
222221
{
223-
case (REPORT):
224-
{
225-
TLOGDEBUG("NotifyImp::reportNotifyInfo reportServer:" << info.sApp + "." + info.sServer << "|sSet:" << info.sSet << "|sContainer:" << info.sContainer << "|ip:" << current->getHostName()
226-
<< "|nodeName:" << info.sNodeName << "|sThreadId:" << info.sThreadId << "|sMessage:" << info.sMessage << endl);
227-
228-
if (IsNeedFilte(info.sApp + info.sServer, info.sMessage))
229-
{
230-
TLOGWARN("NotifyImp::reportNotifyInfo reportServer filter:" << info.sApp + "." + info.sServer << "|sSet:" << info.sSet << "|sContainer:" << info.sContainer << "|ip:" << current->getHostName()
231-
<< "|nodeName:" << info.sNodeName << "|sThreadId:" << info.sThreadId << "|sMessage:" << info.sMessage << "|filted" << endl);
232-
233-
return;
234-
}
235-
236-
string sql;
237-
TC_Mysql::RECORD_DATA rd;
238-
239-
rd["application"] = make_pair(TC_Mysql::DB_STR, info.sApp);
240-
rd["server_name"] = make_pair(TC_Mysql::DB_STR, info.sServer);
241-
rd["container_name"] = make_pair(TC_Mysql::DB_STR, info.sContainer);
242-
rd["server_id"] = make_pair(TC_Mysql::DB_STR, info.sApp +"."+ info.sServer + "_" + nodeId);
243-
rd["node_name"] = make_pair(TC_Mysql::DB_STR, nodeId);
244-
rd["thread_id"] = make_pair(TC_Mysql::DB_STR, info.sThreadId);
245-
246-
if (!info.sSet.empty())
247-
{
248-
vector<string> v = TC_Common::sepstr<string>(info.sSet, ".");
249-
if (v.size() != 3 || (v.size() == 3 && (v[0] == "*" || v[1] == "*")))
250-
{
251-
TLOGERROR("NotifyImp::reportNotifyInfo bad set name:" << info.sSet << endl);
252-
}
253-
else
254-
{
255-
rd["set_name"] = make_pair(TC_Mysql::DB_STR, v[0]);
256-
rd["set_area"] = make_pair(TC_Mysql::DB_STR, v[1]);
257-
rd["set_group"] = make_pair(TC_Mysql::DB_STR, v[2]);
258-
}
259-
260-
}
261-
else
262-
{
263-
rd["set_name"] = make_pair(TC_Mysql::DB_STR, "");
264-
rd["set_area"] = make_pair(TC_Mysql::DB_STR, "");
265-
rd["set_group"] = make_pair(TC_Mysql::DB_STR, "");
266-
}
267-
268-
rd["result"] = make_pair(TC_Mysql::DB_STR, info.sMessage);
269-
rd["notifytime"] = make_pair(TC_Mysql::DB_INT, "now()");
270-
string sTable = "t_server_notifys";
271-
try
272-
{
273-
_mysqlConfig.insertRecord(sTable, rd);
274-
}
275-
catch (TC_Mysql_Exception& ex)
276-
{
277-
string err = string(ex.what());
278-
if (std::string::npos != err.find("doesn't exist"))
279-
{
280-
creatTb(sTable);
281-
}
282-
else
283-
{
284-
string sInfo = string("insert2Db exception") + "|" + ServerConfig::LocalIp + "|" + ServerConfig::Application + "." + ServerConfig::ServerName;
285-
TARS_NOTIFY_ERROR(sInfo);
286-
}
287-
TLOGERROR("NotifyImp::reportNotifyInfo insert2Db exception:" << ex.what() << endl);
288-
}
289-
catch (exception& ex)
290-
{
291-
TLOGERROR("NotifyImp::reportNotifyInfo insert2Db exception:" << ex.what() << endl);
292-
string sInfo = string("insert2Db exception") + "|" + ServerConfig::LocalIp + "|" + ServerConfig::Application + "." + ServerConfig::ServerName;
293-
//TARS_NOTIFY_ERROR(sInfo);
294-
}
295-
}
296222
case (NOTIFY):
297223
{
298224
TLOGDEBUG("NotifyImp::reportNotifyInfo notifyServer:" << info.sApp + "." + info.sServer << "|sSet:" << info.sSet << "|sContainer:" << info.sContainer << "|nodeId:" << nodeId
@@ -344,8 +270,85 @@ void NotifyImp::reportNotifyInfo(const tars::ReportInfo & info, tars::TarsCurren
344270
stInfo0.notifyItems.push_back(stItem);
345271
iRet = g_notifyHash->set(stKey0, stInfo0);
346272
}
347-
default:
348-
break;
273+
case (REPORT):
274+
default: {
275+
TLOGDEBUG(
276+
"NotifyImp::reportNotifyInfo reportServer:" << info.sApp + "." + info.sServer << "|sSet:" << info.sSet
277+
<< "|sContainer:" << info.sContainer << "|ip:"
278+
<< current->getHostName()
279+
<< "|nodeName:" << info.sNodeName << "|sThreadId:"
280+
<< info.sThreadId << "|sMessage:" << info.sMessage << endl);
281+
282+
if (IsNeedFilte(info.sApp + info.sServer, info.sMessage)) {
283+
TLOGWARN(
284+
"NotifyImp::reportNotifyInfo reportServer filter:" << info.sApp + "." + info.sServer << "|sSet:"
285+
<< info.sSet << "|sContainer:" << info.sContainer
286+
<< "|ip:" << current->getHostName()
287+
<< "|nodeName:" << info.sNodeName
288+
<< "|sThreadId:" << info.sThreadId
289+
<< "|sMessage:" << info.sMessage << "|filted"
290+
<< endl);
291+
292+
return;
293+
}
294+
295+
string sql;
296+
TC_Mysql::RECORD_DATA rd;
297+
298+
rd["application"] = make_pair(TC_Mysql::DB_STR, info.sApp);
299+
rd["server_name"] = make_pair(TC_Mysql::DB_STR, info.sServer);
300+
rd["container_name"] = make_pair(TC_Mysql::DB_STR, info.sContainer);
301+
rd["server_id"] = make_pair(TC_Mysql::DB_STR, info.sApp + "." + info.sServer + "_" + nodeId);
302+
rd["node_name"] = make_pair(TC_Mysql::DB_STR, nodeId);
303+
rd["thread_id"] = make_pair(TC_Mysql::DB_STR, info.sThreadId);
304+
305+
if (!info.sSet.empty()) {
306+
vector<string> v = TC_Common::sepstr<string>(info.sSet, ".");
307+
if (v.size() != 3 || (v.size() == 3 && (v[0] == "*" || v[1] == "*"))) {
308+
TLOGERROR("NotifyImp::reportNotifyInfo bad set name:" << info.sSet << endl);
309+
}
310+
else {
311+
rd["set_name"] = make_pair(TC_Mysql::DB_STR, v[0]);
312+
rd["set_area"] = make_pair(TC_Mysql::DB_STR, v[1]);
313+
rd["set_group"] = make_pair(TC_Mysql::DB_STR, v[2]);
314+
}
315+
316+
}
317+
else {
318+
rd["set_name"] = make_pair(TC_Mysql::DB_STR, "");
319+
rd["set_area"] = make_pair(TC_Mysql::DB_STR, "");
320+
rd["set_group"] = make_pair(TC_Mysql::DB_STR, "");
321+
}
322+
323+
rd["result"] = make_pair(TC_Mysql::DB_STR, info.sMessage);
324+
rd["notifytime"] = make_pair(TC_Mysql::DB_INT, "now()");
325+
string sTable = "t_server_notifys";
326+
try {
327+
_mysqlConfig.insertRecord(sTable, rd);
328+
}
329+
catch (TC_Mysql_Exception & ex) {
330+
string err = string(ex.what());
331+
if (std::string::npos != err.find("doesn't exist")) {
332+
creatTb(sTable);
333+
}
334+
else {
335+
string sInfo =
336+
string("insert2Db exception") + "|" + ServerConfig::LocalIp + "|" + ServerConfig::Application
337+
+ "." + ServerConfig::ServerName;
338+
TARS_NOTIFY_ERROR(sInfo);
339+
}
340+
TLOGERROR("NotifyImp::reportNotifyInfo insert2Db exception:" << ex.what() << endl);
341+
}
342+
catch (exception & ex) {
343+
TLOGERROR("NotifyImp::reportNotifyInfo insert2Db exception:" << ex.what() << endl);
344+
string sInfo =
345+
string("insert2Db exception") + "|" + ServerConfig::LocalIp + "|" + ServerConfig::Application + "."
346+
+ ServerConfig::ServerName;
347+
}
348+
349+
TLOGERROR("reportNotifyInfo unknown type:" << info.writeToJsonString() << endl);
350+
break;
351+
}
349352
}
350353

351354
return;

tars-client/command/ping.h

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ void ping(TarsClient* tarsClient, TC_Option& option)
1616
{
1717
ServantPrx prx = tarsClient->getCommunicator()->stringToProxy<ServantPrx>(obj);
1818
prx->tars_ping();
19-
cout << "ping succ" << endl;
2019
}
2120
catch(exception &ex)
2221
{

0 commit comments

Comments
 (0)