ListNodesResult.cc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/ListNodesResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::EHPC;
  19. using namespace AlibabaCloud::EHPC::Model;
  20. ListNodesResult::ListNodesResult() :
  21. ServiceResult()
  22. {}
  23. ListNodesResult::ListNodesResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. ListNodesResult::~ListNodesResult()
  29. {}
  30. void ListNodesResult::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 allNodesNode = value["Nodes"]["NodeInfo"];
  37. for (auto valueNodesNodeInfo : allNodesNode)
  38. {
  39. NodeInfo nodesObject;
  40. if(!valueNodesNodeInfo["Id"].isNull())
  41. nodesObject.id = valueNodesNodeInfo["Id"].asString();
  42. if(!valueNodesNodeInfo["RegionId"].isNull())
  43. nodesObject.regionId = valueNodesNodeInfo["RegionId"].asString();
  44. if(!valueNodesNodeInfo["HostName"].isNull())
  45. nodesObject.hostName = valueNodesNodeInfo["HostName"].asString();
  46. if(!valueNodesNodeInfo["IpAddress"].isNull())
  47. nodesObject.ipAddress = valueNodesNodeInfo["IpAddress"].asString();
  48. if(!valueNodesNodeInfo["Status"].isNull())
  49. nodesObject.status = valueNodesNodeInfo["Status"].asString();
  50. if(!valueNodesNodeInfo["Version"].isNull())
  51. nodesObject.version = valueNodesNodeInfo["Version"].asString();
  52. if(!valueNodesNodeInfo["CreatedByEhpc"].isNull())
  53. nodesObject.createdByEhpc = valueNodesNodeInfo["CreatedByEhpc"].asString() == "true";
  54. if(!valueNodesNodeInfo["AddTime"].isNull())
  55. nodesObject.addTime = valueNodesNodeInfo["AddTime"].asString();
  56. if(!valueNodesNodeInfo["Expired"].isNull())
  57. nodesObject.expired = valueNodesNodeInfo["Expired"].asString() == "true";
  58. if(!valueNodesNodeInfo["ExpiredTime"].isNull())
  59. nodesObject.expiredTime = valueNodesNodeInfo["ExpiredTime"].asString();
  60. if(!valueNodesNodeInfo["SpotStrategy"].isNull())
  61. nodesObject.spotStrategy = valueNodesNodeInfo["SpotStrategy"].asString();
  62. if(!valueNodesNodeInfo["LockReason"].isNull())
  63. nodesObject.lockReason = valueNodesNodeInfo["LockReason"].asString();
  64. if(!valueNodesNodeInfo["ImageOwnerAlias"].isNull())
  65. nodesObject.imageOwnerAlias = valueNodesNodeInfo["ImageOwnerAlias"].asString();
  66. if(!valueNodesNodeInfo["ImageId"].isNull())
  67. nodesObject.imageId = valueNodesNodeInfo["ImageId"].asString();
  68. if(!valueNodesNodeInfo["Location"].isNull())
  69. nodesObject.location = valueNodesNodeInfo["Location"].asString();
  70. if(!valueNodesNodeInfo["CreateMode"].isNull())
  71. nodesObject.createMode = valueNodesNodeInfo["CreateMode"].asString();
  72. if(!valueNodesNodeInfo["VpcId"].isNull())
  73. nodesObject.vpcId = valueNodesNodeInfo["VpcId"].asString();
  74. if(!valueNodesNodeInfo["ZoneId"].isNull())
  75. nodesObject.zoneId = valueNodesNodeInfo["ZoneId"].asString();
  76. if(!valueNodesNodeInfo["VSwitchId"].isNull())
  77. nodesObject.vSwitchId = valueNodesNodeInfo["VSwitchId"].asString();
  78. if(!valueNodesNodeInfo["HtEnabled"].isNull())
  79. nodesObject.htEnabled = valueNodesNodeInfo["HtEnabled"].asString() == "true";
  80. if(!valueNodesNodeInfo["PublicIpAddress"].isNull())
  81. nodesObject.publicIpAddress = valueNodesNodeInfo["PublicIpAddress"].asString();
  82. auto totalResourcesNode = value["TotalResources"];
  83. if(!totalResourcesNode["Cpu"].isNull())
  84. nodesObject.totalResources.cpu = std::stoi(totalResourcesNode["Cpu"].asString());
  85. if(!totalResourcesNode["Memory"].isNull())
  86. nodesObject.totalResources.memory = std::stoi(totalResourcesNode["Memory"].asString());
  87. if(!totalResourcesNode["Gpu"].isNull())
  88. nodesObject.totalResources.gpu = std::stoi(totalResourcesNode["Gpu"].asString());
  89. auto usedResourcesNode = value["UsedResources"];
  90. if(!usedResourcesNode["Cpu"].isNull())
  91. nodesObject.usedResources.cpu = std::stoi(usedResourcesNode["Cpu"].asString());
  92. if(!usedResourcesNode["Memory"].isNull())
  93. nodesObject.usedResources.memory = std::stoi(usedResourcesNode["Memory"].asString());
  94. if(!usedResourcesNode["Gpu"].isNull())
  95. nodesObject.usedResources.gpu = std::stoi(usedResourcesNode["Gpu"].asString());
  96. auto allRoles = value["Roles"]["Role"];
  97. for (auto value : allRoles)
  98. nodesObject.roles.push_back(value.asString());
  99. nodes_.push_back(nodesObject);
  100. }
  101. if(!value["TotalCount"].isNull())
  102. totalCount_ = std::stoi(value["TotalCount"].asString());
  103. if(!value["PageNumber"].isNull())
  104. pageNumber_ = std::stoi(value["PageNumber"].asString());
  105. if(!value["PageSize"].isNull())
  106. pageSize_ = std::stoi(value["PageSize"].asString());
  107. }
  108. int ListNodesResult::getTotalCount()const
  109. {
  110. return totalCount_;
  111. }
  112. int ListNodesResult::getPageSize()const
  113. {
  114. return pageSize_;
  115. }
  116. int ListNodesResult::getPageNumber()const
  117. {
  118. return pageNumber_;
  119. }
  120. std::vector<ListNodesResult::NodeInfo> ListNodesResult::getNodes()const
  121. {
  122. return nodes_;
  123. }