ParserJson.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-04-12 15:40:03
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-04-24 17:49:52
  8. */
  9. #ifndef __PARSERJSON_HPP_
  10. #define __PARSERJSON_HPP_
  11. #include <iostream>
  12. #include "ParserBase.hpp"
  13. using namespace std;
  14. namespace ins
  15. {
  16. class ParserJson:public ParserBase
  17. {
  18. private:
  19. public:
  20. ParserJson():ParserBase(){}
  21. ~ParserJson(){}
  22. /**
  23. * @description: 解析配置
  24. * @param {shared_ptr<InsPacket>} packet
  25. * @return {*}
  26. */
  27. bool ParseConfig(std::shared_ptr<InsPacket> packet){
  28. ApolloServerResultMsg<ApolloAppConfig> msg;
  29. if(msg.jsonToObject(packet->getData()->data)){
  30. InsUniversalData::Ptr toData = std::make_shared<InsUniversalData>();
  31. msg.configurations.USERID = Disposition::getPtr()->getUserId();
  32. toData->format = InsDataFormat::INS_DATA_FORMAT_SQL;
  33. msg.ObjectToSql(toData->data);
  34. packet->setToData(toData);
  35. return true;
  36. }
  37. return false;
  38. }
  39. /**
  40. * @description: 解析 KsWorkload的
  41. * @param {*}
  42. * @return {*}
  43. */
  44. bool ParseKsWorkloadTemplate(std::shared_ptr<InsPacket> packet){
  45. ApolloServerResultMsg<ApolloKsWorkloadTemplate> msg;
  46. if(msg.jsonToObject(packet->getData()->data)){
  47. InsUniversalData::Ptr toData = std::make_shared<InsUniversalData>();
  48. msg.configurations.WORKLOADTEMPLATEID = packet->getData()->Id;
  49. msg.configurations.APOLLONAMESPACEID = atoi(packet->getData()->attr2.c_str());
  50. msg.configurations.AIID = atoi(packet->getData()->attr1.c_str());
  51. msg.configurations.USERID = Disposition::getPtr()->getUserId();
  52. toData->format = InsDataFormat::INS_DATA_FORMAT_SQL;
  53. msg.ObjectToSql(toData->data);
  54. packet->setToData(toData);
  55. return true;
  56. }
  57. return false;
  58. }
  59. /**
  60. * @description:
  61. * @param {*}
  62. * @return {*}
  63. */
  64. bool ParseKsServersTemplate(std::shared_ptr<InsPacket> packet){
  65. ApolloServerResultMsg<ApolloKsServersTemplate> msg;
  66. if(msg.jsonToObject(packet->getData()->data)){
  67. InsUniversalData::Ptr toData = std::make_shared<InsUniversalData>();
  68. msg.configurations.SERVERID = packet->getData()->Id;
  69. msg.configurations.USERID = Disposition::getPtr()->getUserId();
  70. msg.configurations.APOLLONAMESPACEID = atoi(packet->getData()->attr2.c_str());
  71. toData->format = InsDataFormat::INS_DATA_FORMAT_SQL;
  72. msg.ObjectToSql(toData->data);
  73. packet->setToData(toData);
  74. return true;
  75. }
  76. return false;
  77. }
  78. /**
  79. * @description: 解析数据
  80. * @param {*}
  81. * @return {*}
  82. */
  83. virtual bool ParserData(std::shared_ptr<InsPacket> packet) override{
  84. bool result = false;
  85. switch ((int)packet->getData()->type)
  86. {
  87. //* 应用配置
  88. case (int)InsDataType::INS_DATA_TYPE_APPCONFIG:
  89. result = ParseConfig(packet);
  90. break;
  91. //* Ks workload template 工作负载模板
  92. case (int)(InsDataType::INS_DATA_TYPE_KSWORKLOADTEMPLATE):
  93. result = ParseKsWorkloadTemplate(packet);
  94. break;
  95. //* Ks servers template servers模板
  96. case (int)InsDataType::INS_DATA_TYPE_KSSERVERSTEMPLATE:
  97. result = ParseKsServersTemplate(packet);
  98. break;
  99. default:
  100. break;
  101. }
  102. return result;
  103. }
  104. };
  105. } // namespace ins
  106. #endif