123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: lishengyin
- * @Date: 2022-04-06 11:07:53
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-04-24 16:15:45
- */
- #ifndef __INS_INSPACK_HPP_
- #define __INS_INSPACK_HPP_
- #include "private/ins_module_private.hpp"
- #include "ins_Task.hpp"
- #include <vector>
- namespace ins
- {
- /**
- * @description: 数据包类型
- */
- enum class InsPacketTypes{
- INS_ROUTINE_PACKET = 1 << 0,
- INS_IN_PACKET = 1 << 1,
- INS_NETTY_PACKET = 1 << 2,
- INS_K8SSERVER_PACKET = 1 << 3,
- INS_APOLLO_PACKET = 1 << 4,
- INS_MYSQL_PACKET = 1 << 5,
- };
-
- /**
- * @description: 数据格式
- */
- enum class InsDataFormat{
- INS_DATA_FORMAT_JSON = 1 << 0,
- INS_DATA_FORMAT_XML = 1 << 1,
- INS_DATA_FORMAT_PROTOBUF = 1 << 2,
- INS_DATA_FORMAT_SQL = 1 << 3,
- };
-
- /**
- * @description: ins的数据类型
- * @param {*}
- * @return {*}
- */
- enum class InsDataType{
- INS_DATA_TYPE_NULL = 1 << 0,
- INS_DATA_TYPE_APPCONFIG = 1 << 1,
- INS_DATA_TYPE_KSWORKLOADTEMPLATE = 1 << 2,
- INS_DATA_TYPE_KSSERVERSTEMPLATE = 1 << 3,
- };
- class InsUniversalData
- {
- public:
- int Id;
- InsDataFormat format;
- std::string data;
- InsDataType type = InsDataType::INS_DATA_TYPE_NULL;
- // 附属信息
- std::string attr1;
- std::string attr2;
- std::string attr3;
- public:
- using Ptr = std::shared_ptr<InsUniversalData>;
- InsUniversalData(){}
- ~InsUniversalData(){}
- };
-
- /**
- * @description: 数据包类
- */
- class InsPacket:private NonCopyable
- {
- public:
- using Ptr = std::shared_ptr<InsPacket>;
- using PackTaskPtr = std::shared_ptr<std::function<void(InsPacket::Ptr)>>;
- private:
- InsPacket(InsPacketTypes sourceType, InsPacketTypes bournType, InsUniversalData::Ptr data, InsPacket::PackTaskPtr packtask): sourceType_(sourceType), \
- bournType_(bournType), insPackTask_(packtask){
- this->CreateTime = getDataTime();
- data_ = data;
- }
- public:
- ~InsPacket(){}
- /**
- * @description: 创建实例
- * @param {InsPacketTypes} sourceType 数据来源
- * @param {InsPacketTypes} bournType 数据去向
- * @param {InsUniversalData} data 起始数据
- * @param {PackTaskPtr} packtask 包的任务,工作流中解析成功时调用,默认为nullptr, 如需使用MakePackTaskPtr生成
- * @return {*}
- */
- static std::shared_ptr<InsPacket> CreateNew(InsPacketTypes sourceType, InsPacketTypes bournType, InsUniversalData::Ptr data, InsPacket::PackTaskPtr packtask = nullptr);
- /**
- * @description: 获取sourceType
- * @param {*}
- * @return {*}
- */
- InsPacketTypes& getSourceType(){
- return sourceType_;
- }
-
- /**
- * @description: 获取bournType
- * @param {*}
- * @return {*}
- */
- InsPacketTypes& getBournType(){
- return bournType_;
- }
- /**
- * @description:
- * @param {function<void(InsPacket::Ptr)>} t
- * @return {*}
- */
- static PackTaskPtr MakePackTaskPtr(std::function<void(InsPacket::Ptr)> t);
- /**
- * @description: 获取原始数据
- * @param {*}
- * @return {*}
- */
- InsUniversalData::Ptr getData();
- /**
- * @description: 获得最终数据
- * @param {*}
- * @return {*}
- */
- InsUniversalData::Ptr getToData();
- /**
- * @description: 设置最终的数据
- * @param {InsUniversalData} Data
- * @return {*}
- */
- bool setToData(InsUniversalData::Ptr Data);
- /**
- * @description: 获取创建时间
- * @param {*}
- * @return {*}
- */
- std::string getCreateTime(){
- return this->CreateTime;
- }
- /**
- * @description: 获取更新时间
- * @param {*}
- * @return {*}
- */
- std::string getUpdateTime(){
- return this->UpdateTime;
- }
- /**
- * @description: 设置sql结果
- * @param {vector<vector<std::string>>} ret
- * @return {*}
- */
- bool setSqlResult(vector<vector<std::string>> ret);
- /**
- * @description: 获取结果
- * @param {*}
- * @return {*}
- */
- vector<vector<std::string>> getSqlResult();
-
- /**
- * @description: 获取任务
- * @param {*}
- * @return {*}
- */
- PackTaskPtr getInsPackTask();
- /**
- * @description: 判断是否有任务
- * @param {*}
- * @return {*}
- */
- bool IsInsPackTask();
- /**
- * @description: 设置数据类型
- * @param {*}
- * @return {*}
- */
- bool setInsDataType(InsDataType dataType);
- /**
- * @description: 获取数据类型
- * @param {*}
- * @return {*}
- */
- InsDataType getInsDataType();
- private:
- std::string CreateTime;
- std::string UpdateTime;
- vector<vector<std::string>> result_;
- InsPacketTypes sourceType_;
- InsPacketTypes bournType_;
- PackTaskPtr insPackTask_ = nullptr;
- InsUniversalData::Ptr data_ = nullptr;
- InsUniversalData::Ptr toData_ = nullptr;
- InsDataType insDataType_;
- };
- } // namespace ins
- #endif
|