ins_Packet.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-04-06 11:07:53
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-04-24 16:15:45
  8. */
  9. #ifndef __INS_INSPACK_HPP_
  10. #define __INS_INSPACK_HPP_
  11. #include "private/ins_module_private.hpp"
  12. #include "ins_Task.hpp"
  13. #include <vector>
  14. namespace ins
  15. {
  16. /**
  17. * @description: 数据包类型
  18. */
  19. enum class InsPacketTypes{
  20. INS_ROUTINE_PACKET = 1 << 0,
  21. INS_IN_PACKET = 1 << 1,
  22. INS_NETTY_PACKET = 1 << 2,
  23. INS_K8SSERVER_PACKET = 1 << 3,
  24. INS_APOLLO_PACKET = 1 << 4,
  25. INS_MYSQL_PACKET = 1 << 5,
  26. };
  27. /**
  28. * @description: 数据格式
  29. */
  30. enum class InsDataFormat{
  31. INS_DATA_FORMAT_JSON = 1 << 0,
  32. INS_DATA_FORMAT_XML = 1 << 1,
  33. INS_DATA_FORMAT_PROTOBUF = 1 << 2,
  34. INS_DATA_FORMAT_SQL = 1 << 3,
  35. };
  36. /**
  37. * @description: ins的数据类型
  38. * @param {*}
  39. * @return {*}
  40. */
  41. enum class InsDataType{
  42. INS_DATA_TYPE_NULL = 1 << 0,
  43. INS_DATA_TYPE_APPCONFIG = 1 << 1,
  44. INS_DATA_TYPE_KSWORKLOADTEMPLATE = 1 << 2,
  45. INS_DATA_TYPE_KSSERVERSTEMPLATE = 1 << 3,
  46. };
  47. class InsUniversalData
  48. {
  49. public:
  50. int Id;
  51. InsDataFormat format;
  52. std::string data;
  53. InsDataType type = InsDataType::INS_DATA_TYPE_NULL;
  54. // 附属信息
  55. std::string attr1;
  56. std::string attr2;
  57. std::string attr3;
  58. public:
  59. using Ptr = std::shared_ptr<InsUniversalData>;
  60. InsUniversalData(){}
  61. ~InsUniversalData(){}
  62. };
  63. /**
  64. * @description: 数据包类
  65. */
  66. class InsPacket:private NonCopyable
  67. {
  68. public:
  69. using Ptr = std::shared_ptr<InsPacket>;
  70. using PackTaskPtr = std::shared_ptr<std::function<void(InsPacket::Ptr)>>;
  71. private:
  72. InsPacket(InsPacketTypes sourceType, InsPacketTypes bournType, InsUniversalData::Ptr data, InsPacket::PackTaskPtr packtask): sourceType_(sourceType), \
  73. bournType_(bournType), insPackTask_(packtask){
  74. this->CreateTime = getDataTime();
  75. data_ = data;
  76. }
  77. public:
  78. ~InsPacket(){}
  79. /**
  80. * @description: 创建实例
  81. * @param {InsPacketTypes} sourceType 数据来源
  82. * @param {InsPacketTypes} bournType 数据去向
  83. * @param {InsUniversalData} data 起始数据
  84. * @param {PackTaskPtr} packtask 包的任务,工作流中解析成功时调用,默认为nullptr, 如需使用MakePackTaskPtr生成
  85. * @return {*}
  86. */
  87. static std::shared_ptr<InsPacket> CreateNew(InsPacketTypes sourceType, InsPacketTypes bournType, InsUniversalData::Ptr data, InsPacket::PackTaskPtr packtask = nullptr);
  88. /**
  89. * @description: 获取sourceType
  90. * @param {*}
  91. * @return {*}
  92. */
  93. InsPacketTypes& getSourceType(){
  94. return sourceType_;
  95. }
  96. /**
  97. * @description: 获取bournType
  98. * @param {*}
  99. * @return {*}
  100. */
  101. InsPacketTypes& getBournType(){
  102. return bournType_;
  103. }
  104. /**
  105. * @description:
  106. * @param {function<void(InsPacket::Ptr)>} t
  107. * @return {*}
  108. */
  109. static PackTaskPtr MakePackTaskPtr(std::function<void(InsPacket::Ptr)> t);
  110. /**
  111. * @description: 获取原始数据
  112. * @param {*}
  113. * @return {*}
  114. */
  115. InsUniversalData::Ptr getData();
  116. /**
  117. * @description: 获得最终数据
  118. * @param {*}
  119. * @return {*}
  120. */
  121. InsUniversalData::Ptr getToData();
  122. /**
  123. * @description: 设置最终的数据
  124. * @param {InsUniversalData} Data
  125. * @return {*}
  126. */
  127. bool setToData(InsUniversalData::Ptr Data);
  128. /**
  129. * @description: 获取创建时间
  130. * @param {*}
  131. * @return {*}
  132. */
  133. std::string getCreateTime(){
  134. return this->CreateTime;
  135. }
  136. /**
  137. * @description: 获取更新时间
  138. * @param {*}
  139. * @return {*}
  140. */
  141. std::string getUpdateTime(){
  142. return this->UpdateTime;
  143. }
  144. /**
  145. * @description: 设置sql结果
  146. * @param {vector<vector<std::string>>} ret
  147. * @return {*}
  148. */
  149. bool setSqlResult(vector<vector<std::string>> ret);
  150. /**
  151. * @description: 获取结果
  152. * @param {*}
  153. * @return {*}
  154. */
  155. vector<vector<std::string>> getSqlResult();
  156. /**
  157. * @description: 获取任务
  158. * @param {*}
  159. * @return {*}
  160. */
  161. PackTaskPtr getInsPackTask();
  162. /**
  163. * @description: 判断是否有任务
  164. * @param {*}
  165. * @return {*}
  166. */
  167. bool IsInsPackTask();
  168. /**
  169. * @description: 设置数据类型
  170. * @param {*}
  171. * @return {*}
  172. */
  173. bool setInsDataType(InsDataType dataType);
  174. /**
  175. * @description: 获取数据类型
  176. * @param {*}
  177. * @return {*}
  178. */
  179. InsDataType getInsDataType();
  180. private:
  181. std::string CreateTime;
  182. std::string UpdateTime;
  183. vector<vector<std::string>> result_;
  184. InsPacketTypes sourceType_;
  185. InsPacketTypes bournType_;
  186. PackTaskPtr insPackTask_ = nullptr;
  187. InsUniversalData::Ptr data_ = nullptr;
  188. InsUniversalData::Ptr toData_ = nullptr;
  189. InsDataType insDataType_;
  190. };
  191. } // namespace ins
  192. #endif