OnsConsumerStatusResult.cc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/ons/model/OnsConsumerStatusResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Ons;
  19. using namespace AlibabaCloud::Ons::Model;
  20. OnsConsumerStatusResult::OnsConsumerStatusResult() :
  21. ServiceResult()
  22. {}
  23. OnsConsumerStatusResult::OnsConsumerStatusResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. OnsConsumerStatusResult::~OnsConsumerStatusResult()
  29. {}
  30. void OnsConsumerStatusResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto dataNode = value["Data"];
  37. if(!dataNode["Online"].isNull())
  38. data_.online = dataNode["Online"].asString() == "true";
  39. if(!dataNode["TotalDiff"].isNull())
  40. data_.totalDiff = std::stol(dataNode["TotalDiff"].asString());
  41. if(!dataNode["ConsumeTps"].isNull())
  42. data_.consumeTps = std::stof(dataNode["ConsumeTps"].asString());
  43. if(!dataNode["LastTimestamp"].isNull())
  44. data_.lastTimestamp = std::stol(dataNode["LastTimestamp"].asString());
  45. if(!dataNode["DelayTime"].isNull())
  46. data_.delayTime = std::stol(dataNode["DelayTime"].asString());
  47. if(!dataNode["ConsumeModel"].isNull())
  48. data_.consumeModel = dataNode["ConsumeModel"].asString();
  49. if(!dataNode["SubscriptionSame"].isNull())
  50. data_.subscriptionSame = dataNode["SubscriptionSame"].asString() == "true";
  51. if(!dataNode["RebalanceOK"].isNull())
  52. data_.rebalanceOK = dataNode["RebalanceOK"].asString() == "true";
  53. if(!dataNode["InstanceId"].isNull())
  54. data_.instanceId = dataNode["InstanceId"].asString();
  55. auto allConnectionSetNode = dataNode["ConnectionSet"]["ConnectionDo"];
  56. for (auto dataNodeConnectionSetConnectionDo : allConnectionSetNode)
  57. {
  58. Data::ConnectionDo connectionDoObject;
  59. if(!dataNodeConnectionSetConnectionDo["ClientId"].isNull())
  60. connectionDoObject.clientId = dataNodeConnectionSetConnectionDo["ClientId"].asString();
  61. if(!dataNodeConnectionSetConnectionDo["ClientAddr"].isNull())
  62. connectionDoObject.clientAddr = dataNodeConnectionSetConnectionDo["ClientAddr"].asString();
  63. if(!dataNodeConnectionSetConnectionDo["Language"].isNull())
  64. connectionDoObject.language = dataNodeConnectionSetConnectionDo["Language"].asString();
  65. if(!dataNodeConnectionSetConnectionDo["Version"].isNull())
  66. connectionDoObject.version = dataNodeConnectionSetConnectionDo["Version"].asString();
  67. if(!dataNodeConnectionSetConnectionDo["RemoteIP"].isNull())
  68. connectionDoObject.remoteIP = dataNodeConnectionSetConnectionDo["RemoteIP"].asString();
  69. data_.connectionSet.push_back(connectionDoObject);
  70. }
  71. auto allDetailInTopicListNode = dataNode["DetailInTopicList"]["DetailInTopicDo"];
  72. for (auto dataNodeDetailInTopicListDetailInTopicDo : allDetailInTopicListNode)
  73. {
  74. Data::DetailInTopicDo detailInTopicDoObject;
  75. if(!dataNodeDetailInTopicListDetailInTopicDo["Topic"].isNull())
  76. detailInTopicDoObject.topic = dataNodeDetailInTopicListDetailInTopicDo["Topic"].asString();
  77. if(!dataNodeDetailInTopicListDetailInTopicDo["TotalDiff"].isNull())
  78. detailInTopicDoObject.totalDiff = std::stol(dataNodeDetailInTopicListDetailInTopicDo["TotalDiff"].asString());
  79. if(!dataNodeDetailInTopicListDetailInTopicDo["LastTimestamp"].isNull())
  80. detailInTopicDoObject.lastTimestamp = std::stol(dataNodeDetailInTopicListDetailInTopicDo["LastTimestamp"].asString());
  81. if(!dataNodeDetailInTopicListDetailInTopicDo["DelayTime"].isNull())
  82. detailInTopicDoObject.delayTime = std::stol(dataNodeDetailInTopicListDetailInTopicDo["DelayTime"].asString());
  83. data_.detailInTopicList.push_back(detailInTopicDoObject);
  84. }
  85. auto allConsumerConnectionInfoListNode = dataNode["ConsumerConnectionInfoList"]["ConsumerConnectionInfoDo"];
  86. for (auto dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo : allConsumerConnectionInfoListNode)
  87. {
  88. Data::ConsumerConnectionInfoDo consumerConnectionInfoDoObject;
  89. if(!dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["ClientId"].isNull())
  90. consumerConnectionInfoDoObject.clientId = dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["ClientId"].asString();
  91. if(!dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["Connection"].isNull())
  92. consumerConnectionInfoDoObject.connection = dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["Connection"].asString();
  93. if(!dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["Language"].isNull())
  94. consumerConnectionInfoDoObject.language = dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["Language"].asString();
  95. if(!dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["Version"].isNull())
  96. consumerConnectionInfoDoObject.version = dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["Version"].asString();
  97. if(!dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["ConsumeModel"].isNull())
  98. consumerConnectionInfoDoObject.consumeModel = dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["ConsumeModel"].asString();
  99. if(!dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["ConsumeType"].isNull())
  100. consumerConnectionInfoDoObject.consumeType = dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["ConsumeType"].asString();
  101. if(!dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["ThreadCount"].isNull())
  102. consumerConnectionInfoDoObject.threadCount = std::stoi(dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["ThreadCount"].asString());
  103. if(!dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["StartTimeStamp"].isNull())
  104. consumerConnectionInfoDoObject.startTimeStamp = std::stol(dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["StartTimeStamp"].asString());
  105. if(!dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["LastTimeStamp"].isNull())
  106. consumerConnectionInfoDoObject.lastTimeStamp = std::stol(dataNodeConsumerConnectionInfoListConsumerConnectionInfoDo["LastTimeStamp"].asString());
  107. auto allSubscriptionSetNode = allConsumerConnectionInfoListNode["SubscriptionSet"]["SubscriptionData"];
  108. for (auto allConsumerConnectionInfoListNodeSubscriptionSetSubscriptionData : allSubscriptionSetNode)
  109. {
  110. Data::ConsumerConnectionInfoDo::SubscriptionData subscriptionSetObject;
  111. if(!allConsumerConnectionInfoListNodeSubscriptionSetSubscriptionData["Topic"].isNull())
  112. subscriptionSetObject.topic = allConsumerConnectionInfoListNodeSubscriptionSetSubscriptionData["Topic"].asString();
  113. if(!allConsumerConnectionInfoListNodeSubscriptionSetSubscriptionData["SubString"].isNull())
  114. subscriptionSetObject.subString = allConsumerConnectionInfoListNodeSubscriptionSetSubscriptionData["SubString"].asString();
  115. if(!allConsumerConnectionInfoListNodeSubscriptionSetSubscriptionData["SubVersion"].isNull())
  116. subscriptionSetObject.subVersion = std::stol(allConsumerConnectionInfoListNodeSubscriptionSetSubscriptionData["SubVersion"].asString());
  117. auto allTagsSet = value["TagsSet"]["Tag"];
  118. for (auto value : allTagsSet)
  119. subscriptionSetObject.tagsSet.push_back(value.asString());
  120. consumerConnectionInfoDoObject.subscriptionSet.push_back(subscriptionSetObject);
  121. }
  122. auto allRunningDataListNode = allConsumerConnectionInfoListNode["RunningDataList"]["ConsumerRunningDataDo"];
  123. for (auto allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo : allRunningDataListNode)
  124. {
  125. Data::ConsumerConnectionInfoDo::ConsumerRunningDataDo runningDataListObject;
  126. if(!allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["GroupId"].isNull())
  127. runningDataListObject.groupId = allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["GroupId"].asString();
  128. if(!allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["Topic"].isNull())
  129. runningDataListObject.topic = allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["Topic"].asString();
  130. if(!allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["Rt"].isNull())
  131. runningDataListObject.rt = std::stof(allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["Rt"].asString());
  132. if(!allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["OkTps"].isNull())
  133. runningDataListObject.okTps = std::stof(allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["OkTps"].asString());
  134. if(!allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["FailedTps"].isNull())
  135. runningDataListObject.failedTps = std::stof(allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["FailedTps"].asString());
  136. if(!allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["FailedCountPerHour"].isNull())
  137. runningDataListObject.failedCountPerHour = std::stol(allConsumerConnectionInfoListNodeRunningDataListConsumerRunningDataDo["FailedCountPerHour"].asString());
  138. consumerConnectionInfoDoObject.runningDataList.push_back(runningDataListObject);
  139. }
  140. auto allJstackNode = allConsumerConnectionInfoListNode["Jstack"]["ThreadTrackDo"];
  141. for (auto allConsumerConnectionInfoListNodeJstackThreadTrackDo : allJstackNode)
  142. {
  143. Data::ConsumerConnectionInfoDo::ThreadTrackDo jstackObject;
  144. if(!allConsumerConnectionInfoListNodeJstackThreadTrackDo["Thread"].isNull())
  145. jstackObject.thread = allConsumerConnectionInfoListNodeJstackThreadTrackDo["Thread"].asString();
  146. auto allTrackList = value["TrackList"]["Track"];
  147. for (auto value : allTrackList)
  148. jstackObject.trackList.push_back(value.asString());
  149. consumerConnectionInfoDoObject.jstack.push_back(jstackObject);
  150. }
  151. data_.consumerConnectionInfoList.push_back(consumerConnectionInfoDoObject);
  152. }
  153. if(!value["HelpUrl"].isNull())
  154. helpUrl_ = value["HelpUrl"].asString();
  155. }
  156. OnsConsumerStatusResult::Data OnsConsumerStatusResult::getData()const
  157. {
  158. return data_;
  159. }
  160. std::string OnsConsumerStatusResult::getHelpUrl()const
  161. {
  162. return helpUrl_;
  163. }