ListNodesResult.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 allNodes = value["Nodes"]["NodeInfo"];
  37. for (auto value : allNodes)
  38. {
  39. NodeInfo nodesObject;
  40. if(!value["Id"].isNull())
  41. nodesObject.id = value["Id"].asString();
  42. if(!value["RegionId"].isNull())
  43. nodesObject.regionId = value["RegionId"].asString();
  44. if(!value["Status"].isNull())
  45. nodesObject.status = value["Status"].asString();
  46. if(!value["CreatedByEhpc"].isNull())
  47. nodesObject.createdByEhpc = value["CreatedByEhpc"].asString() == "true";
  48. if(!value["AddTime"].isNull())
  49. nodesObject.addTime = value["AddTime"].asString();
  50. if(!value["Expired"].isNull())
  51. nodesObject.expired = value["Expired"].asString() == "true";
  52. if(!value["ExpiredTime"].isNull())
  53. nodesObject.expiredTime = value["ExpiredTime"].asString();
  54. if(!value["SpotStrategy"].isNull())
  55. nodesObject.spotStrategy = value["SpotStrategy"].asString();
  56. if(!value["LockReason"].isNull())
  57. nodesObject.lockReason = value["LockReason"].asString();
  58. if(!value["ImageOwnerAlias"].isNull())
  59. nodesObject.imageOwnerAlias = value["ImageOwnerAlias"].asString();
  60. if(!value["ImageId"].isNull())
  61. nodesObject.imageId = value["ImageId"].asString();
  62. auto totalResourcesNode = value["TotalResources"];
  63. if(!totalResourcesNode["Cpu"].isNull())
  64. nodesObject.totalResources.cpu = std::stoi(totalResourcesNode["Cpu"].asString());
  65. if(!totalResourcesNode["Memory"].isNull())
  66. nodesObject.totalResources.memory = std::stoi(totalResourcesNode["Memory"].asString());
  67. if(!totalResourcesNode["Gpu"].isNull())
  68. nodesObject.totalResources.gpu = std::stoi(totalResourcesNode["Gpu"].asString());
  69. auto usedResourcesNode = value["UsedResources"];
  70. if(!usedResourcesNode["Cpu"].isNull())
  71. nodesObject.usedResources.cpu = std::stoi(usedResourcesNode["Cpu"].asString());
  72. if(!usedResourcesNode["Memory"].isNull())
  73. nodesObject.usedResources.memory = std::stoi(usedResourcesNode["Memory"].asString());
  74. if(!usedResourcesNode["Gpu"].isNull())
  75. nodesObject.usedResources.gpu = std::stoi(usedResourcesNode["Gpu"].asString());
  76. auto allRoles = value["Roles"]["Role"];
  77. for (auto value : allRoles)
  78. nodesObject.roles.push_back(value.asString());
  79. nodes_.push_back(nodesObject);
  80. }
  81. if(!value["TotalCount"].isNull())
  82. totalCount_ = std::stoi(value["TotalCount"].asString());
  83. if(!value["PageNumber"].isNull())
  84. pageNumber_ = std::stoi(value["PageNumber"].asString());
  85. if(!value["PageSize"].isNull())
  86. pageSize_ = std::stoi(value["PageSize"].asString());
  87. }
  88. int ListNodesResult::getTotalCount()const
  89. {
  90. return totalCount_;
  91. }
  92. int ListNodesResult::getPageSize()const
  93. {
  94. return pageSize_;
  95. }
  96. int ListNodesResult::getPageNumber()const
  97. {
  98. return pageNumber_;
  99. }
  100. std::vector<ListNodesResult::NodeInfo> ListNodesResult::getNodes()const
  101. {
  102. return nodes_;
  103. }