ConfigImp.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. 
  2. #ifndef _CONFIGIMP_H_
  3. #define _CONFIGIMP_H_
  4. #include "servant/ConfigF.h"
  5. #include "util/tc_file.h"
  6. using namespace tars;
  7. class ConfigImp : public Config
  8. {
  9. public:
  10. /**
  11. *
  12. */
  13. ConfigImp(){};
  14. /**
  15. *
  16. */
  17. virtual ~ConfigImp(){};
  18. /**
  19. * 初始化
  20. *
  21. * @return int
  22. */
  23. virtual void initialize()
  24. {
  25. files["test.conf"] = "test-content";
  26. };
  27. /**
  28. * 退出
  29. */
  30. virtual void destroy() {};
  31. virtual int ListConfig(const string &app,const string &server, vector<string> &vf,tars::CurrentPtr current)
  32. {
  33. LOG_CONSOLE_DEBUG << app << ", " << server << endl;
  34. return 0;
  35. }
  36. /**
  37. * 加载配置文件
  38. * param app :应用
  39. * param server: server名
  40. * param filename: 配置文件名
  41. *
  42. * return : 配置文件内容
  43. */
  44. virtual int loadConfig(const std::string & app, const std::string & server, const std::string & filename, string &config, tars::CurrentPtr current)
  45. {
  46. LOG_CONSOLE_DEBUG << app << ", " << server << ", " << filename << endl;
  47. map<string, string>::iterator it =files.find(filename);
  48. if(it!=files.end()){
  49. config = it->second;
  50. }
  51. return 0;
  52. }
  53. /**
  54. * 根据ip获取配置
  55. * @param appServerName
  56. * @param filename
  57. * @param host
  58. * @param config
  59. *
  60. * @return int
  61. */
  62. virtual int loadConfigByHost(const string &appServerName, const string &filename, const string &host, string &config, tars::CurrentPtr current)
  63. {
  64. LOG_CONSOLE_DEBUG << appServerName << ", " << filename << ", " << host << endl;
  65. return 0;
  66. }
  67. /**
  68. *
  69. * @param appServerName
  70. * @param filename
  71. * @param host
  72. * @param current
  73. *
  74. * @return int
  75. */
  76. virtual int checkConfig(const string &appServerName, const string &filename, const string &host, string &result, tars::CurrentPtr current)
  77. {
  78. LOG_CONSOLE_DEBUG << appServerName << ", " << filename << ", " << host << endl;
  79. return 0;
  80. }
  81. /**
  82. * 获取配置文件列表
  83. * param configInfo ConfigInfo
  84. * param vf: 配置文件名
  85. *
  86. * return : 配置文件内容
  87. */
  88. virtual int ListConfigByInfo(const ConfigInfo& configInfo, vector<string> &vf,tars::CurrentPtr current)
  89. {
  90. LOG_CONSOLE_DEBUG << configInfo.writeToJsonString() << endl;
  91. return 0;
  92. }
  93. /**
  94. * 加载配置文件
  95. * param configInfo ConfigInfo
  96. * param config: 配置文件内容
  97. *
  98. * return :
  99. */
  100. virtual int loadConfigByInfo(const ConfigInfo & configInfo, string &config,tars::CurrentPtr current)
  101. {
  102. LOG_CONSOLE_DEBUG << configInfo.writeToJsonString() << endl;
  103. return 0;
  104. }
  105. /**
  106. *
  107. * @param configInfo ConfigInfo
  108. *
  109. * @return int
  110. */
  111. virtual int checkConfigByInfo(const ConfigInfo & configInfo, string &result,tars::CurrentPtr current)
  112. {
  113. LOG_CONSOLE_DEBUG << configInfo.writeToJsonString() << endl;
  114. return 0;
  115. }
  116. /**
  117. * 获取服务的所有配置文件列表,
  118. * @param configInfo 支持拉取应用配置列表,服务配置列表,机器配置列表
  119. * @param[out] vf 获取到的文件名称列表
  120. * @return int 0: 成功, -1:失败
  121. **/
  122. virtual int ListAllConfigByInfo(const tars::GetConfigListInfo & configInfo, vector<std::string> &vf, tars::CurrentPtr current)
  123. {
  124. LOG_CONSOLE_DEBUG << configInfo.writeToJsonString() << endl;
  125. return 0;
  126. }
  127. private:
  128. map<string, string> files;
  129. };
  130. #endif /* TARS_TARS_TEST_TESTCODE_INCLUDE_STUB_CONFIGIMP_H_ */