DescribeClusterDetailResult.cc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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/retailcloud/model/DescribeClusterDetailResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Retailcloud;
  19. using namespace AlibabaCloud::Retailcloud::Model;
  20. DescribeClusterDetailResult::DescribeClusterDetailResult() :
  21. ServiceResult()
  22. {}
  23. DescribeClusterDetailResult::DescribeClusterDetailResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. DescribeClusterDetailResult::~DescribeClusterDetailResult()
  29. {}
  30. void DescribeClusterDetailResult::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 resultNode = value["Result"];
  37. auto allNodeWorkLoadListNode = resultNode["NodeWorkLoadList"]["ClusterNodeWorkLoad"];
  38. for (auto resultNodeNodeWorkLoadListClusterNodeWorkLoad : allNodeWorkLoadListNode)
  39. {
  40. Result::ClusterNodeWorkLoad clusterNodeWorkLoadObject;
  41. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["AppPodCount"].isNull())
  42. clusterNodeWorkLoadObject.appPodCount = std::stoi(resultNodeNodeWorkLoadListClusterNodeWorkLoad["AppPodCount"].asString());
  43. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["CpuRequest"].isNull())
  44. clusterNodeWorkLoadObject.cpuRequest = resultNodeNodeWorkLoadListClusterNodeWorkLoad["CpuRequest"].asString();
  45. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["CpuTotal"].isNull())
  46. clusterNodeWorkLoadObject.cpuTotal = resultNodeNodeWorkLoadListClusterNodeWorkLoad["CpuTotal"].asString();
  47. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["CpuUse"].isNull())
  48. clusterNodeWorkLoadObject.cpuUse = resultNodeNodeWorkLoadListClusterNodeWorkLoad["CpuUse"].asString();
  49. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["InstanceId"].isNull())
  50. clusterNodeWorkLoadObject.instanceId = resultNodeNodeWorkLoadListClusterNodeWorkLoad["InstanceId"].asString();
  51. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["MemRequest"].isNull())
  52. clusterNodeWorkLoadObject.memRequest = resultNodeNodeWorkLoadListClusterNodeWorkLoad["MemRequest"].asString();
  53. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["MemTotal"].isNull())
  54. clusterNodeWorkLoadObject.memTotal = resultNodeNodeWorkLoadListClusterNodeWorkLoad["MemTotal"].asString();
  55. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["MemUse"].isNull())
  56. clusterNodeWorkLoadObject.memUse = resultNodeNodeWorkLoadListClusterNodeWorkLoad["MemUse"].asString();
  57. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["NodeName"].isNull())
  58. clusterNodeWorkLoadObject.nodeName = resultNodeNodeWorkLoadListClusterNodeWorkLoad["NodeName"].asString();
  59. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["PodCount"].isNull())
  60. clusterNodeWorkLoadObject.podCount = std::stoi(resultNodeNodeWorkLoadListClusterNodeWorkLoad["PodCount"].asString());
  61. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["Ready"].isNull())
  62. clusterNodeWorkLoadObject.ready = resultNodeNodeWorkLoadListClusterNodeWorkLoad["Ready"].asString() == "true";
  63. if(!resultNodeNodeWorkLoadListClusterNodeWorkLoad["Unschedulable"].isNull())
  64. clusterNodeWorkLoadObject.unschedulable = resultNodeNodeWorkLoadListClusterNodeWorkLoad["Unschedulable"].asString() == "true";
  65. result_.nodeWorkLoadList.push_back(clusterNodeWorkLoadObject);
  66. }
  67. auto basicInfoNode = resultNode["BasicInfo"];
  68. if(!basicInfoNode["BusinessCode"].isNull())
  69. result_.basicInfo.businessCode = basicInfoNode["BusinessCode"].asString();
  70. if(!basicInfoNode["ClusterId"].isNull())
  71. result_.basicInfo.clusterId = std::stol(basicInfoNode["ClusterId"].asString());
  72. if(!basicInfoNode["ClusterInstanceId"].isNull())
  73. result_.basicInfo.clusterInstanceId = basicInfoNode["ClusterInstanceId"].asString();
  74. if(!basicInfoNode["ClusterName"].isNull())
  75. result_.basicInfo.clusterName = basicInfoNode["ClusterName"].asString();
  76. if(!basicInfoNode["EnvType"].isNull())
  77. result_.basicInfo.envType = basicInfoNode["EnvType"].asString();
  78. if(!basicInfoNode["HasInstallArmsPilot"].isNull())
  79. result_.basicInfo.hasInstallArmsPilot = basicInfoNode["HasInstallArmsPilot"].asString() == "true";
  80. if(!basicInfoNode["HasInstallLogController"].isNull())
  81. result_.basicInfo.hasInstallLogController = basicInfoNode["HasInstallLogController"].asString() == "true";
  82. if(!basicInfoNode["InstallArmsInProcess"].isNull())
  83. result_.basicInfo.installArmsInProcess = basicInfoNode["InstallArmsInProcess"].asString() == "true";
  84. if(!basicInfoNode["InstallLogInProcess"].isNull())
  85. result_.basicInfo.installLogInProcess = basicInfoNode["InstallLogInProcess"].asString() == "true";
  86. if(!basicInfoNode["MainUserId"].isNull())
  87. result_.basicInfo.mainUserId = basicInfoNode["MainUserId"].asString();
  88. if(!basicInfoNode["RegionId"].isNull())
  89. result_.basicInfo.regionId = basicInfoNode["RegionId"].asString();
  90. if(!basicInfoNode["RegionName"].isNull())
  91. result_.basicInfo.regionName = basicInfoNode["RegionName"].asString();
  92. if(!basicInfoNode["UserNick"].isNull())
  93. result_.basicInfo.userNick = basicInfoNode["UserNick"].asString();
  94. if(!basicInfoNode["VpcId"].isNull())
  95. result_.basicInfo.vpcId = basicInfoNode["VpcId"].asString();
  96. auto allEcsIds = basicInfoNode["EcsIds"]["String"];
  97. for (auto value : allEcsIds)
  98. result_.basicInfo.ecsIds.push_back(value.asString());
  99. auto allVswitchs = basicInfoNode["Vswitchs"]["String"];
  100. for (auto value : allVswitchs)
  101. result_.basicInfo.vswitchs.push_back(value.asString());
  102. auto instanceInfoNode = resultNode["InstanceInfo"];
  103. if(!instanceInfoNode["AllocatePodCount"].isNull())
  104. result_.instanceInfo.allocatePodCount = std::stoi(instanceInfoNode["AllocatePodCount"].asString());
  105. if(!instanceInfoNode["AppCount"].isNull())
  106. result_.instanceInfo.appCount = std::stoi(instanceInfoNode["AppCount"].asString());
  107. auto allAllocatedPodInfoListNode = instanceInfoNode["AllocatedPodInfoList"]["AllocatedPodInstanceInfo"];
  108. for (auto instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo : allAllocatedPodInfoListNode)
  109. {
  110. Result::InstanceInfo::AllocatedPodInstanceInfo allocatedPodInstanceInfoObject;
  111. if(!instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["AppId"].isNull())
  112. allocatedPodInstanceInfoObject.appId = std::stol(instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["AppId"].asString());
  113. if(!instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["AppName"].isNull())
  114. allocatedPodInstanceInfoObject.appName = instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["AppName"].asString();
  115. if(!instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["CupRequest"].isNull())
  116. allocatedPodInstanceInfoObject.cupRequest = instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["CupRequest"].asString();
  117. if(!instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["EnvId"].isNull())
  118. allocatedPodInstanceInfoObject.envId = std::stol(instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["EnvId"].asString());
  119. if(!instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["EnvName"].isNull())
  120. allocatedPodInstanceInfoObject.envName = instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["EnvName"].asString();
  121. if(!instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["MemRequest"].isNull())
  122. allocatedPodInstanceInfoObject.memRequest = instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["MemRequest"].asString();
  123. if(!instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["PodCount"].isNull())
  124. allocatedPodInstanceInfoObject.podCount = std::stoi(instanceInfoNodeAllocatedPodInfoListAllocatedPodInstanceInfo["PodCount"].asString());
  125. result_.instanceInfo.allocatedPodInfoList.push_back(allocatedPodInstanceInfoObject);
  126. }
  127. auto allAvailablePodInfoListNode = instanceInfoNode["AvailablePodInfoList"]["AvailablePodInstanceInfo"];
  128. for (auto instanceInfoNodeAvailablePodInfoListAvailablePodInstanceInfo : allAvailablePodInfoListNode)
  129. {
  130. Result::InstanceInfo::AvailablePodInstanceInfo availablePodInstanceInfoObject;
  131. if(!instanceInfoNodeAvailablePodInfoListAvailablePodInstanceInfo["AvailablePodCount"].isNull())
  132. availablePodInstanceInfoObject.availablePodCount = std::stoi(instanceInfoNodeAvailablePodInfoListAvailablePodInstanceInfo["AvailablePodCount"].asString());
  133. if(!instanceInfoNodeAvailablePodInfoListAvailablePodInstanceInfo["CupRequest"].isNull())
  134. availablePodInstanceInfoObject.cupRequest = instanceInfoNodeAvailablePodInfoListAvailablePodInstanceInfo["CupRequest"].asString();
  135. if(!instanceInfoNodeAvailablePodInfoListAvailablePodInstanceInfo["MemRequest"].isNull())
  136. availablePodInstanceInfoObject.memRequest = instanceInfoNodeAvailablePodInfoListAvailablePodInstanceInfo["MemRequest"].asString();
  137. result_.instanceInfo.availablePodInfoList.push_back(availablePodInstanceInfoObject);
  138. }
  139. auto netInfoNode = resultNode["NetInfo"];
  140. if(!netInfoNode["NetPlugType"].isNull())
  141. result_.netInfo.netPlugType = netInfoNode["NetPlugType"].asString();
  142. if(!netInfoNode["ProdCIDR"].isNull())
  143. result_.netInfo.prodCIDR = netInfoNode["ProdCIDR"].asString();
  144. if(!netInfoNode["ServiceCIDR"].isNull())
  145. result_.netInfo.serviceCIDR = netInfoNode["ServiceCIDR"].asString();
  146. auto workLoadNode = resultNode["WorkLoad"];
  147. if(!workLoadNode["AllNodeCount"].isNull())
  148. result_.workLoad.allNodeCount = std::stoi(workLoadNode["AllNodeCount"].asString());
  149. if(!workLoadNode["AllocateAllPodCount"].isNull())
  150. result_.workLoad.allocateAllPodCount = std::stoi(workLoadNode["AllocateAllPodCount"].asString());
  151. if(!workLoadNode["AllocateAppPodCount"].isNull())
  152. result_.workLoad.allocateAppPodCount = std::stoi(workLoadNode["AllocateAppPodCount"].asString());
  153. if(!workLoadNode["CpuCapacityTotal"].isNull())
  154. result_.workLoad.cpuCapacityTotal = workLoadNode["CpuCapacityTotal"].asString();
  155. if(!workLoadNode["CpuLevel"].isNull())
  156. result_.workLoad.cpuLevel = workLoadNode["CpuLevel"].asString();
  157. if(!workLoadNode["CpuRequest"].isNull())
  158. result_.workLoad.cpuRequest = workLoadNode["CpuRequest"].asString();
  159. if(!workLoadNode["CpuRequestPercent"].isNull())
  160. result_.workLoad.cpuRequestPercent = workLoadNode["CpuRequestPercent"].asString();
  161. if(!workLoadNode["CpuTotal"].isNull())
  162. result_.workLoad.cpuTotal = workLoadNode["CpuTotal"].asString();
  163. if(!workLoadNode["CpuUse"].isNull())
  164. result_.workLoad.cpuUse = workLoadNode["CpuUse"].asString();
  165. if(!workLoadNode["CpuUsePercent"].isNull())
  166. result_.workLoad.cpuUsePercent = workLoadNode["CpuUsePercent"].asString();
  167. if(!workLoadNode["MemCapacityTotal"].isNull())
  168. result_.workLoad.memCapacityTotal = workLoadNode["MemCapacityTotal"].asString();
  169. if(!workLoadNode["MemLevel"].isNull())
  170. result_.workLoad.memLevel = workLoadNode["MemLevel"].asString();
  171. if(!workLoadNode["MemRequest"].isNull())
  172. result_.workLoad.memRequest = workLoadNode["MemRequest"].asString();
  173. if(!workLoadNode["MemRequestPercent"].isNull())
  174. result_.workLoad.memRequestPercent = workLoadNode["MemRequestPercent"].asString();
  175. if(!workLoadNode["MemTotal"].isNull())
  176. result_.workLoad.memTotal = workLoadNode["MemTotal"].asString();
  177. if(!workLoadNode["MemUse"].isNull())
  178. result_.workLoad.memUse = workLoadNode["MemUse"].asString();
  179. if(!workLoadNode["MemUsePercent"].isNull())
  180. result_.workLoad.memUsePercent = workLoadNode["MemUsePercent"].asString();
  181. if(!value["Code"].isNull())
  182. code_ = std::stoi(value["Code"].asString());
  183. if(!value["ErrMsg"].isNull())
  184. errMsg_ = value["ErrMsg"].asString();
  185. if(!value["Success"].isNull())
  186. success_ = value["Success"].asString() == "true";
  187. }
  188. std::string DescribeClusterDetailResult::getErrMsg()const
  189. {
  190. return errMsg_;
  191. }
  192. int DescribeClusterDetailResult::getCode()const
  193. {
  194. return code_;
  195. }
  196. bool DescribeClusterDetailResult::getSuccess()const
  197. {
  198. return success_;
  199. }
  200. DescribeClusterDetailResult::Result DescribeClusterDetailResult::getResult()const
  201. {
  202. return result_;
  203. }