loggingagentbase.hpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2014 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #pragma warning (disable : 4786)
  14. #ifndef _LOGGINGAGENT_HPP__
  15. #define _LOGGINGAGENT_HPP__
  16. #include "jiface.hpp"
  17. #include "esp.hpp"
  18. #include "datafieldmap.hpp"
  19. #include "ws_loggingservice_esp.ipp"
  20. #include "loggingcommon.hpp"
  21. #define UPDATELOGTHREADWAITINGTIME 3000
  22. //The 'TransactionXYZ' is expected for the following key strings
  23. //used in CTransIDBuilder::getTransID() -> add().
  24. static const char* sTransactionDateTime = "TransactionDateTime";
  25. static const char* sTransactionMethod = "TransactionMethod";
  26. static const char* sTransactionESPIP = "TransactionESPIP";
  27. interface IEspUpdateLogRequestWrap : extends IInterface
  28. {
  29. virtual const char* getGUID()=0;
  30. virtual const char* getOption()=0;
  31. virtual const char* getUpdateLogRequest()=0;
  32. virtual IPropertyTree* getESPContext()=0;
  33. virtual IPropertyTree* getUserContext()=0;
  34. virtual IPropertyTree* getUserRequest()=0;
  35. virtual const char* getBackEndResponse()=0;
  36. virtual const char* getUserResponse()=0;
  37. virtual void setGUID(const char* val)=0;
  38. virtual void setOption(const char* val)=0;
  39. virtual void setUpdateLogRequest(const char* val)=0;
  40. virtual void setESPContext(IPropertyTree* val)=0;
  41. virtual void setUserContext(IPropertyTree* val)=0;
  42. virtual void setUserRequest(IPropertyTree* val)=0;
  43. virtual void setBackEndResponse(const char* val)=0;
  44. virtual void setUserResponse(const char* val)=0;
  45. virtual unsigned incrementRetryCount() = 0;
  46. virtual void clearOriginalContent() = 0;
  47. };
  48. class CUpdateLogRequestWrap : implements IEspUpdateLogRequestWrap, public CInterface
  49. {
  50. StringAttr GUID;
  51. StringAttr option;
  52. StringAttr updateLogRequest;
  53. Owned<IPropertyTree> espContext;
  54. Owned<IPropertyTree> userContext;
  55. Owned<IPropertyTree> userRequest;
  56. StringAttr backEndResponse;
  57. StringAttr userResponse;
  58. unsigned retryCount;
  59. public:
  60. IMPLEMENT_IINTERFACE;
  61. CUpdateLogRequestWrap(const char* _GUID, const char* _option, const char* _updateLogRequest)
  62. : GUID(_GUID), option(_option), updateLogRequest(_updateLogRequest), retryCount(0) {};
  63. CUpdateLogRequestWrap(const char* _GUID, const char* _option, IPropertyTree* _espContext,
  64. IPropertyTree*_userContext, IPropertyTree*_userRequest, const char *_backEndResponse, const char *_userResponse)
  65. : GUID(_GUID), option(_option), backEndResponse(_backEndResponse), userResponse(_userResponse), retryCount(0)
  66. {
  67. userContext.setown(_userContext);
  68. espContext.setown(_espContext);
  69. userRequest.setown(_userRequest);
  70. };
  71. ~CUpdateLogRequestWrap()
  72. {
  73. espContext.clear();
  74. userRequest.clear();
  75. userContext.clear();
  76. };
  77. void clearOriginalContent()
  78. {
  79. espContext.clear();
  80. userRequest.clear();
  81. userContext.clear();
  82. userResponse.clear();
  83. backEndResponse.clear();
  84. updateLogRequest.clear();
  85. };
  86. const char* getGUID() {return GUID.get();};
  87. const char* getOption() {return option.get();};
  88. const char* getUpdateLogRequest() {return updateLogRequest.get();};
  89. IPropertyTree* getESPContext() {return espContext.getLink();};
  90. IPropertyTree* getUserContext() {return userContext.getLink();};
  91. IPropertyTree* getUserRequest() {return userRequest.getLink();};
  92. const char* getBackEndResponse() {return backEndResponse.get();};
  93. const char* getUserResponse() {return userResponse.get();};
  94. void setGUID(const char* val) {GUID.set(val);};
  95. void setOption(const char* val) {option.set(val);};
  96. void setUpdateLogRequest(const char* val) {updateLogRequest.set(val);};
  97. void setESPContext(IPropertyTree* val) {espContext.setown(val);};
  98. void setUserContext(IPropertyTree* val) {userContext.setown(val);};
  99. void setUserRequest(IPropertyTree* val) {userRequest.setown(val);};
  100. void setBackEndResponse(const char* val) {backEndResponse.set(val);};
  101. void setUserResponse(const char* val) {userResponse.set(val);};
  102. unsigned incrementRetryCount() { retryCount++; return retryCount;};
  103. };
  104. interface IEspLogAgent : extends IInterface
  105. {
  106. virtual bool init(const char * name, const char * type, IPropertyTree * cfg, const char * process) = 0;
  107. virtual bool getTransactionSeed(IEspGetTransactionSeedRequest& req, IEspGetTransactionSeedResponse& resp) = 0;
  108. virtual void getTransactionID(StringAttrMapping* transFields, StringBuffer& transactionID) = 0;
  109. virtual bool updateLog(IEspUpdateLogRequestWrap& req, IEspUpdateLogResponse& resp) = 0;
  110. virtual void filterLogContent(IEspUpdateLogRequestWrap* req) = 0;
  111. };
  112. class LOGGINGCOMMON_API CDBLogAgentBase : public CInterface, implements IEspLogAgent
  113. {
  114. protected:
  115. StringBuffer defaultDB, transactionTable, loggingTransactionSeed;
  116. StringAttr defaultLogGroup, defaultTransactionApp, loggingTransactionApp, logSourcePath;
  117. unsigned logSourceCount, loggingTransactionCount, maxTriesGTS;
  118. MapStringToMyClass<CLogGroup> logGroups;
  119. MapStringToMyClass<CLogSource> logSources;
  120. void readDBCfg(IPropertyTree* cfg, StringBuffer& server, StringBuffer& dbUser, StringBuffer& dbPassword);
  121. void readTransactionCfg(IPropertyTree* cfg);
  122. bool buildUpdateLogStatement(IPropertyTree* logRequest, const char* logDB, CLogTable& table, StringBuffer& logID, StringBuffer& cqlStatement);
  123. void appendFieldInfo(const char* field, StringBuffer& value, StringBuffer& fields, StringBuffer& values, bool quoted);
  124. void addMissingFields(CIArrayOf<CLogField>& logFields, BoolHash& HandledFields, StringBuffer& fields, StringBuffer& values);
  125. CLogGroup* checkLogSource(IPropertyTree* logRequest, StringBuffer& source, StringBuffer& logDB);
  126. void getLoggingTransactionID(StringBuffer& id);
  127. virtual void addField(CLogField& logField, const char* name, StringBuffer& value, StringBuffer& fields, StringBuffer& values) = 0;
  128. virtual void queryTransactionSeed(const char* appName, StringBuffer& seed) = 0;
  129. virtual void executeUpdateLogStatement(StringBuffer& statement) = 0;
  130. virtual void setUpdateLogStatement(const char* dbName, const char* tableName,
  131. const char* fields, const char* values, StringBuffer& statement) = 0;
  132. public:
  133. IMPLEMENT_IINTERFACE;
  134. CDBLogAgentBase() {};
  135. virtual ~CDBLogAgentBase() {};
  136. virtual bool getTransactionSeed(IEspGetTransactionSeedRequest& req, IEspGetTransactionSeedResponse& resp);
  137. virtual void getTransactionID(StringAttrMapping* transFields, StringBuffer& transactionID);
  138. virtual bool updateLog(IEspUpdateLogRequestWrap& req, IEspUpdateLogResponse& resp);
  139. virtual void filterLogContent(IEspUpdateLogRequestWrap* req);
  140. };
  141. #endif //_LOGGINGAGENT_HPP__