ListClustersResult.cc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/ehpc/model/ListClustersResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::EHPC;
  19. using namespace AlibabaCloud::EHPC::Model;
  20. ListClustersResult::ListClustersResult() :
  21. ServiceResult()
  22. {}
  23. ListClustersResult::ListClustersResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. ListClustersResult::~ListClustersResult()
  29. {}
  30. void ListClustersResult::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 allClustersNode = value["Clusters"]["ClusterInfoSimple"];
  37. for (auto valueClustersClusterInfoSimple : allClustersNode)
  38. {
  39. ClusterInfoSimple clustersObject;
  40. if(!valueClustersClusterInfoSimple["Id"].isNull())
  41. clustersObject.id = valueClustersClusterInfoSimple["Id"].asString();
  42. if(!valueClustersClusterInfoSimple["RegionId"].isNull())
  43. clustersObject.regionId = valueClustersClusterInfoSimple["RegionId"].asString();
  44. if(!valueClustersClusterInfoSimple["ZoneId"].isNull())
  45. clustersObject.zoneId = valueClustersClusterInfoSimple["ZoneId"].asString();
  46. if(!valueClustersClusterInfoSimple["VSwitchId"].isNull())
  47. clustersObject.vSwitchId = valueClustersClusterInfoSimple["VSwitchId"].asString();
  48. if(!valueClustersClusterInfoSimple["VpcId"].isNull())
  49. clustersObject.vpcId = valueClustersClusterInfoSimple["VpcId"].asString();
  50. if(!valueClustersClusterInfoSimple["Name"].isNull())
  51. clustersObject.name = valueClustersClusterInfoSimple["Name"].asString();
  52. if(!valueClustersClusterInfoSimple["Description"].isNull())
  53. clustersObject.description = valueClustersClusterInfoSimple["Description"].asString();
  54. if(!valueClustersClusterInfoSimple["Status"].isNull())
  55. clustersObject.status = valueClustersClusterInfoSimple["Status"].asString();
  56. if(!valueClustersClusterInfoSimple["OsTag"].isNull())
  57. clustersObject.osTag = valueClustersClusterInfoSimple["OsTag"].asString();
  58. if(!valueClustersClusterInfoSimple["AccountType"].isNull())
  59. clustersObject.accountType = valueClustersClusterInfoSimple["AccountType"].asString();
  60. if(!valueClustersClusterInfoSimple["SchedulerType"].isNull())
  61. clustersObject.schedulerType = valueClustersClusterInfoSimple["SchedulerType"].asString();
  62. if(!valueClustersClusterInfoSimple["DeployMode"].isNull())
  63. clustersObject.deployMode = valueClustersClusterInfoSimple["DeployMode"].asString();
  64. if(!valueClustersClusterInfoSimple["Count"].isNull())
  65. clustersObject.count = std::stoi(valueClustersClusterInfoSimple["Count"].asString());
  66. if(!valueClustersClusterInfoSimple["InstanceType"].isNull())
  67. clustersObject.instanceType = valueClustersClusterInfoSimple["InstanceType"].asString();
  68. if(!valueClustersClusterInfoSimple["LoginNodes"].isNull())
  69. clustersObject.loginNodes = valueClustersClusterInfoSimple["LoginNodes"].asString();
  70. if(!valueClustersClusterInfoSimple["CreateTime"].isNull())
  71. clustersObject.createTime = valueClustersClusterInfoSimple["CreateTime"].asString();
  72. if(!valueClustersClusterInfoSimple["ImageOwnerAlias"].isNull())
  73. clustersObject.imageOwnerAlias = valueClustersClusterInfoSimple["ImageOwnerAlias"].asString();
  74. if(!valueClustersClusterInfoSimple["ImageId"].isNull())
  75. clustersObject.imageId = valueClustersClusterInfoSimple["ImageId"].asString();
  76. if(!valueClustersClusterInfoSimple["Location"].isNull())
  77. clustersObject.location = valueClustersClusterInfoSimple["Location"].asString();
  78. if(!valueClustersClusterInfoSimple["EhpcVersion"].isNull())
  79. clustersObject.ehpcVersion = valueClustersClusterInfoSimple["EhpcVersion"].asString();
  80. if(!valueClustersClusterInfoSimple["NodePrefix"].isNull())
  81. clustersObject.nodePrefix = valueClustersClusterInfoSimple["NodePrefix"].asString();
  82. if(!valueClustersClusterInfoSimple["NodeSuffix"].isNull())
  83. clustersObject.nodeSuffix = valueClustersClusterInfoSimple["NodeSuffix"].asString();
  84. if(!valueClustersClusterInfoSimple["BaseOsTag"].isNull())
  85. clustersObject.baseOsTag = valueClustersClusterInfoSimple["BaseOsTag"].asString();
  86. if(!valueClustersClusterInfoSimple["InstanceChargeType"].isNull())
  87. clustersObject.instanceChargeType = valueClustersClusterInfoSimple["InstanceChargeType"].asString();
  88. if(!valueClustersClusterInfoSimple["ComputeSpotStrategy"].isNull())
  89. clustersObject.computeSpotStrategy = valueClustersClusterInfoSimple["ComputeSpotStrategy"].asString();
  90. if(!valueClustersClusterInfoSimple["ComputeSpotPriceLimit"].isNull())
  91. clustersObject.computeSpotPriceLimit = std::stof(valueClustersClusterInfoSimple["ComputeSpotPriceLimit"].asString());
  92. auto managersNode = value["Managers"];
  93. if(!managersNode["Total"].isNull())
  94. clustersObject.managers.total = std::stoi(managersNode["Total"].asString());
  95. if(!managersNode["NormalCount"].isNull())
  96. clustersObject.managers.normalCount = std::stoi(managersNode["NormalCount"].asString());
  97. if(!managersNode["OperatingCount"].isNull())
  98. clustersObject.managers.operatingCount = std::stoi(managersNode["OperatingCount"].asString());
  99. if(!managersNode["StoppedCount"].isNull())
  100. clustersObject.managers.stoppedCount = std::stoi(managersNode["StoppedCount"].asString());
  101. if(!managersNode["ExceptionCount"].isNull())
  102. clustersObject.managers.exceptionCount = std::stoi(managersNode["ExceptionCount"].asString());
  103. auto computesNode = value["Computes"];
  104. if(!computesNode["Total"].isNull())
  105. clustersObject.computes.total = std::stoi(computesNode["Total"].asString());
  106. if(!computesNode["NormalCount"].isNull())
  107. clustersObject.computes.normalCount = std::stoi(computesNode["NormalCount"].asString());
  108. if(!computesNode["OperatingCount"].isNull())
  109. clustersObject.computes.operatingCount = std::stoi(computesNode["OperatingCount"].asString());
  110. if(!computesNode["StoppedCount"].isNull())
  111. clustersObject.computes.stoppedCount = std::stoi(computesNode["StoppedCount"].asString());
  112. if(!computesNode["ExceptionCount"].isNull())
  113. clustersObject.computes.exceptionCount = std::stoi(computesNode["ExceptionCount"].asString());
  114. auto totalResourcesNode = value["TotalResources"];
  115. if(!totalResourcesNode["Cpu"].isNull())
  116. clustersObject.totalResources.cpu = std::stoi(totalResourcesNode["Cpu"].asString());
  117. if(!totalResourcesNode["Memory"].isNull())
  118. clustersObject.totalResources.memory = std::stoi(totalResourcesNode["Memory"].asString());
  119. if(!totalResourcesNode["Gpu"].isNull())
  120. clustersObject.totalResources.gpu = std::stoi(totalResourcesNode["Gpu"].asString());
  121. auto usedResourcesNode = value["UsedResources"];
  122. if(!usedResourcesNode["Cpu"].isNull())
  123. clustersObject.usedResources.cpu = std::stoi(usedResourcesNode["Cpu"].asString());
  124. if(!usedResourcesNode["Memory"].isNull())
  125. clustersObject.usedResources.memory = std::stoi(usedResourcesNode["Memory"].asString());
  126. if(!usedResourcesNode["Gpu"].isNull())
  127. clustersObject.usedResources.gpu = std::stoi(usedResourcesNode["Gpu"].asString());
  128. clusters_.push_back(clustersObject);
  129. }
  130. if(!value["TotalCount"].isNull())
  131. totalCount_ = std::stoi(value["TotalCount"].asString());
  132. if(!value["PageNumber"].isNull())
  133. pageNumber_ = std::stoi(value["PageNumber"].asString());
  134. if(!value["PageSize"].isNull())
  135. pageSize_ = std::stoi(value["PageSize"].asString());
  136. }
  137. int ListClustersResult::getTotalCount()const
  138. {
  139. return totalCount_;
  140. }
  141. int ListClustersResult::getPageSize()const
  142. {
  143. return pageSize_;
  144. }
  145. int ListClustersResult::getPageNumber()const
  146. {
  147. return pageNumber_;
  148. }
  149. std::vector<ListClustersResult::ClusterInfoSimple> ListClustersResult::getClusters()const
  150. {
  151. return clusters_;
  152. }