/* * @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 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(){} }; /** * @description: 数据包类 */ class InsPacket:private NonCopyable { public: using Ptr = std::shared_ptr; using PackTaskPtr = std::shared_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 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} t * @return {*} */ static PackTaskPtr MakePackTaskPtr(std::function 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>} ret * @return {*} */ bool setSqlResult(vector> ret); /** * @description: 获取结果 * @param {*} * @return {*} */ vector> 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> result_; InsPacketTypes sourceType_; InsPacketTypes bournType_; PackTaskPtr insPackTask_ = nullptr; InsUniversalData::Ptr data_ = nullptr; InsUniversalData::Ptr toData_ = nullptr; InsDataType insDataType_; }; } // namespace ins #endif