123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: lishengyin
- * @Date: 2022-04-12 15:40:03
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-06-27 15:26:26
- */
- #ifndef __PARSERJSON_HPP_
- #define __PARSERJSON_HPP_
- #include <iostream>
- #include "ParserBase.hpp"
- using namespace std;
- namespace ins
- {
- class ParserJson:public ParserBase
- {
- private:
-
- public:
- ParserJson():ParserBase(){}
- ~ParserJson(){}
- /**
- * @description: 解析配置
- * @param {shared_ptr<InsPacket>} packet
- * @return {*}
- */
- bool ParseConfig(std::shared_ptr<InsPacket> packet){
- ApolloServerResultMsg<ApolloAppConfig> msg;
- if(msg.jsonToObject(packet->getData()->data)){
- InsUniversalData::Ptr toData = std::make_shared<InsUniversalData>();
- msg.configurations.USERID = Disposition::getPtr()->getUserId();
- toData->format = InsDataFormat::INS_DATA_FORMAT_SQL;
- msg.ObjectToSql(toData->data);
- packet->setToData(toData);
- return true;
- }
- return false;
- }
- /**
- * @description: 解析 KsTemplate
- * @param {*}
- * @return {*}
- */
- bool ParseKsTemplate(std::shared_ptr<InsPacket> packet){
-
- return false;
- }
- /**
- * @description: 获取对应类型的解析器
- * @param {std::string} DescriptionId 描述的ID
- * @return {*}
- */
- MsgBase::Ptr getParserType(std::string DescriptionId){
- MsgBase::Ptr msg = nullptr;
- SqlStream stream("SELECT TYPE,PARSERTYPE FROM InsServerDB.`InsDataDescription` WHERE USERID = 2 AND DESCRIPTIONID = '?'");
- stream << DescriptionId;
- vector<vector<std::string>> res;
- std::string sql = (std::string)stream;
- res = GetCenter::getPtr()->ExecuteSql(sql);
- if(res.empty()) return msg;
- if(res.size() > 1) return msg;
- for(auto &line: res){
- if(line[1] == "ApolloAppConfig") msg = std::make_shared<ApolloServerResultMsg<ApolloAppConfig>>();
- else if(line[1] == "ApolloKsTemplate") msg = std::make_shared<ApolloServerResultMsg<ApolloKsTemplate>>();
- else if(line[1] == "KubeSphereNodes") msg = std::make_shared<KubeSphereResourcesMsg<KubeSphereNodes>>();
- else if(line[1] == "KubeSpherePods") msg = std::make_shared<KubeSphereResourcesMsg<KubeSpherePods>>();
- else if(line[1] == "KubeSphereServers") msg = std::make_shared<KubeSphereResourcesMsg<KubeSphereServers>>();
- else if(line[1] == "KubeSphereDeployments") msg = std::make_shared<KubeSphereResourcesMsg<KubeSphereDeployments>>();
- }
- return msg;
- }
- /**
- * @description: 解析数据
- * @param {*}
- * @return {*}
- */
- virtual bool ParserData(std::shared_ptr<InsPacket> packet) override{
- MsgBase::Ptr msg = nullptr;
- msg = getParserType(packet->getData()->attr1);
- if(msg == nullptr) return false;
- if(msg->jsonToObject(packet->getData()->data)){
- InsUniversalData::Ptr toData = std::make_shared<InsUniversalData>();
- msg->DATATIME = packet->getCreateTime();
- msg->USERID = Disposition::getPtr()->getUserId();
- msg->ID = std::atoi(packet->getData()->attr1.c_str());
- msg->DATATIME = packet->getCreateTime();
- if(packet->getBournType() == InsPacketTypes::INS_MYSQL_PACKET){
- if(!msg->ObjectToSql(toData->data)) return false;
- msg->ObjectToSqlBack(toData->attr2);
- toData->format = InsDataFormat::INS_DATA_FORMAT_SQL;
- }
- packet->setToData(toData);
- return true;
- }
- return false;
- }
- };
- } // namespace ins
- #endif
|