DescribeFleetsResult.cc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/ecs/model/DescribeFleetsResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Ecs;
  19. using namespace AlibabaCloud::Ecs::Model;
  20. DescribeFleetsResult::DescribeFleetsResult() :
  21. ServiceResult()
  22. {}
  23. DescribeFleetsResult::DescribeFleetsResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. DescribeFleetsResult::~DescribeFleetsResult()
  29. {}
  30. void DescribeFleetsResult::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 allFleetsNode = value["Fleets"]["Fleet"];
  37. for (auto valueFleetsFleet : allFleetsNode)
  38. {
  39. Fleet fleetsObject;
  40. if(!valueFleetsFleet["FleetId"].isNull())
  41. fleetsObject.fleetId = valueFleetsFleet["FleetId"].asString();
  42. if(!valueFleetsFleet["FleetName"].isNull())
  43. fleetsObject.fleetName = valueFleetsFleet["FleetName"].asString();
  44. if(!valueFleetsFleet["FleetType"].isNull())
  45. fleetsObject.fleetType = valueFleetsFleet["FleetType"].asString();
  46. if(!valueFleetsFleet["Status"].isNull())
  47. fleetsObject.status = valueFleetsFleet["Status"].asString();
  48. if(!valueFleetsFleet["State"].isNull())
  49. fleetsObject.state = valueFleetsFleet["State"].asString();
  50. if(!valueFleetsFleet["RegionId"].isNull())
  51. fleetsObject.regionId = valueFleetsFleet["RegionId"].asString();
  52. if(!valueFleetsFleet["ValidFrom"].isNull())
  53. fleetsObject.validFrom = valueFleetsFleet["ValidFrom"].asString();
  54. if(!valueFleetsFleet["ValidUntil"].isNull())
  55. fleetsObject.validUntil = valueFleetsFleet["ValidUntil"].asString();
  56. if(!valueFleetsFleet["ExcessCapacityTerminationPolicy"].isNull())
  57. fleetsObject.excessCapacityTerminationPolicy = valueFleetsFleet["ExcessCapacityTerminationPolicy"].asString();
  58. if(!valueFleetsFleet["MaxSpotPrice"].isNull())
  59. fleetsObject.maxSpotPrice = std::stof(valueFleetsFleet["MaxSpotPrice"].asString());
  60. if(!valueFleetsFleet["LaunchTemplateId"].isNull())
  61. fleetsObject.launchTemplateId = valueFleetsFleet["LaunchTemplateId"].asString();
  62. if(!valueFleetsFleet["LaunchTemplateVersion"].isNull())
  63. fleetsObject.launchTemplateVersion = valueFleetsFleet["LaunchTemplateVersion"].asString();
  64. if(!valueFleetsFleet["TerminateInstances"].isNull())
  65. fleetsObject.terminateInstances = valueFleetsFleet["TerminateInstances"].asString() == "true";
  66. if(!valueFleetsFleet["TerminateInstancesWithExpiration"].isNull())
  67. fleetsObject.terminateInstancesWithExpiration = valueFleetsFleet["TerminateInstancesWithExpiration"].asString() == "true";
  68. if(!valueFleetsFleet["CreationTime"].isNull())
  69. fleetsObject.creationTime = valueFleetsFleet["CreationTime"].asString();
  70. auto alllaunchTemplateConfigsNode = allFleetsNode["launchTemplateConfigs"]["LaunchTemplateConfig"];
  71. for (auto allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig : alllaunchTemplateConfigsNode)
  72. {
  73. Fleet::LaunchTemplateConfig launchTemplateConfigsObject;
  74. if(!allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig["InstanceType"].isNull())
  75. launchTemplateConfigsObject.instanceType = allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig["InstanceType"].asString();
  76. if(!allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig["MaxPrice"].isNull())
  77. launchTemplateConfigsObject.maxPrice = std::stof(allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig["MaxPrice"].asString());
  78. if(!allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig["VSWitchId"].isNull())
  79. launchTemplateConfigsObject.vSWitchId = allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig["VSWitchId"].asString();
  80. if(!allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig["WeightedCapacity"].isNull())
  81. launchTemplateConfigsObject.weightedCapacity = std::stof(allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig["WeightedCapacity"].asString());
  82. if(!allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig["Priority"].isNull())
  83. launchTemplateConfigsObject.priority = std::stof(allFleetsNodelaunchTemplateConfigsLaunchTemplateConfig["Priority"].asString());
  84. fleetsObject.launchTemplateConfigs.push_back(launchTemplateConfigsObject);
  85. }
  86. auto spotOptionsNode = value["SpotOptions"];
  87. if(!spotOptionsNode["AllocationStrategy"].isNull())
  88. fleetsObject.spotOptions.allocationStrategy = spotOptionsNode["AllocationStrategy"].asString();
  89. if(!spotOptionsNode["InstanceInterruptionBehavior"].isNull())
  90. fleetsObject.spotOptions.instanceInterruptionBehavior = spotOptionsNode["InstanceInterruptionBehavior"].asString();
  91. if(!spotOptionsNode["InstancePoolsToUseCount"].isNull())
  92. fleetsObject.spotOptions.instancePoolsToUseCount = std::stoi(spotOptionsNode["InstancePoolsToUseCount"].asString());
  93. auto onDemandOptionsNode = value["OnDemandOptions"];
  94. if(!onDemandOptionsNode["AllocationStrategy"].isNull())
  95. fleetsObject.onDemandOptions.allocationStrategy = onDemandOptionsNode["AllocationStrategy"].asString();
  96. auto targetCapacitySpecificationNode = value["TargetCapacitySpecification"];
  97. if(!targetCapacitySpecificationNode["TotalTargetCapacity"].isNull())
  98. fleetsObject.targetCapacitySpecification.totalTargetCapacity = std::stof(targetCapacitySpecificationNode["TotalTargetCapacity"].asString());
  99. if(!targetCapacitySpecificationNode["OnDemandTargetCapacity"].isNull())
  100. fleetsObject.targetCapacitySpecification.onDemandTargetCapacity = std::stof(targetCapacitySpecificationNode["OnDemandTargetCapacity"].asString());
  101. if(!targetCapacitySpecificationNode["SpotTargetCapacity"].isNull())
  102. fleetsObject.targetCapacitySpecification.spotTargetCapacity = std::stof(targetCapacitySpecificationNode["SpotTargetCapacity"].asString());
  103. if(!targetCapacitySpecificationNode["DefaultTargetCapacityType"].isNull())
  104. fleetsObject.targetCapacitySpecification.defaultTargetCapacityType = targetCapacitySpecificationNode["DefaultTargetCapacityType"].asString();
  105. if(!targetCapacitySpecificationNode["FillGapWithOnDemand"].isNull())
  106. fleetsObject.targetCapacitySpecification.fillGapWithOnDemand = targetCapacitySpecificationNode["FillGapWithOnDemand"].asString() == "true";
  107. fleets_.push_back(fleetsObject);
  108. }
  109. if(!value["TotalCount"].isNull())
  110. totalCount_ = std::stoi(value["TotalCount"].asString());
  111. if(!value["PageNumber"].isNull())
  112. pageNumber_ = std::stoi(value["PageNumber"].asString());
  113. if(!value["PageSize"].isNull())
  114. pageSize_ = std::stoi(value["PageSize"].asString());
  115. }
  116. std::vector<DescribeFleetsResult::Fleet> DescribeFleetsResult::getFleets()const
  117. {
  118. return fleets_;
  119. }
  120. int DescribeFleetsResult::getTotalCount()const
  121. {
  122. return totalCount_;
  123. }
  124. int DescribeFleetsResult::getPageSize()const
  125. {
  126. return pageSize_;
  127. }
  128. int DescribeFleetsResult::getPageNumber()const
  129. {
  130. return pageNumber_;
  131. }