DescribeScalingRulesResult.cc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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/ess/model/DescribeScalingRulesResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Ess;
  19. using namespace AlibabaCloud::Ess::Model;
  20. DescribeScalingRulesResult::DescribeScalingRulesResult() :
  21. ServiceResult()
  22. {}
  23. DescribeScalingRulesResult::DescribeScalingRulesResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. DescribeScalingRulesResult::~DescribeScalingRulesResult()
  29. {}
  30. void DescribeScalingRulesResult::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 allScalingRules = value["ScalingRules"]["ScalingRule"];
  37. for (auto value : allScalingRules)
  38. {
  39. ScalingRule scalingRulesObject;
  40. if(!value["ScalingRuleId"].isNull())
  41. scalingRulesObject.scalingRuleId = value["ScalingRuleId"].asString();
  42. if(!value["ScalingGroupId"].isNull())
  43. scalingRulesObject.scalingGroupId = value["ScalingGroupId"].asString();
  44. if(!value["ScalingRuleName"].isNull())
  45. scalingRulesObject.scalingRuleName = value["ScalingRuleName"].asString();
  46. if(!value["Cooldown"].isNull())
  47. scalingRulesObject.cooldown = std::stoi(value["Cooldown"].asString());
  48. if(!value["MinAdjustmentMagnitude"].isNull())
  49. scalingRulesObject.minAdjustmentMagnitude = std::stoi(value["MinAdjustmentMagnitude"].asString());
  50. if(!value["AdjustmentType"].isNull())
  51. scalingRulesObject.adjustmentType = value["AdjustmentType"].asString();
  52. if(!value["AdjustmentValue"].isNull())
  53. scalingRulesObject.adjustmentValue = std::stoi(value["AdjustmentValue"].asString());
  54. if(!value["MinSize"].isNull())
  55. scalingRulesObject.minSize = std::stoi(value["MinSize"].asString());
  56. if(!value["MaxSize"].isNull())
  57. scalingRulesObject.maxSize = std::stoi(value["MaxSize"].asString());
  58. if(!value["ScalingRuleAri"].isNull())
  59. scalingRulesObject.scalingRuleAri = value["ScalingRuleAri"].asString();
  60. if(!value["ScalingRuleType"].isNull())
  61. scalingRulesObject.scalingRuleType = value["ScalingRuleType"].asString();
  62. if(!value["EstimatedInstanceWarmup"].isNull())
  63. scalingRulesObject.estimatedInstanceWarmup = std::stoi(value["EstimatedInstanceWarmup"].asString());
  64. if(!value["MetricName"].isNull())
  65. scalingRulesObject.metricName = value["MetricName"].asString();
  66. if(!value["TargetValue"].isNull())
  67. scalingRulesObject.targetValue = std::stof(value["TargetValue"].asString());
  68. if(!value["DisableScaleIn"].isNull())
  69. scalingRulesObject.disableScaleIn = value["DisableScaleIn"].asString() == "true";
  70. auto allAlarms = value["Alarms"]["Alarm"];
  71. for (auto value : allAlarms)
  72. {
  73. ScalingRule::Alarm alarmsObject;
  74. if(!value["AlarmTaskName"].isNull())
  75. alarmsObject.alarmTaskName = value["AlarmTaskName"].asString();
  76. if(!value["AlarmTaskId"].isNull())
  77. alarmsObject.alarmTaskId = value["AlarmTaskId"].asString();
  78. scalingRulesObject.alarms.push_back(alarmsObject);
  79. }
  80. auto allStepAdjustments = value["StepAdjustments"]["StepAdjustment"];
  81. for (auto value : allStepAdjustments)
  82. {
  83. ScalingRule::StepAdjustment stepAdjustmentsObject;
  84. if(!value["MetricIntervalLowerBound"].isNull())
  85. stepAdjustmentsObject.metricIntervalLowerBound = std::stof(value["MetricIntervalLowerBound"].asString());
  86. if(!value["MetricIntervalUpperBound"].isNull())
  87. stepAdjustmentsObject.metricIntervalUpperBound = std::stof(value["MetricIntervalUpperBound"].asString());
  88. if(!value["ScalingAdjustment"].isNull())
  89. stepAdjustmentsObject.scalingAdjustment = std::stoi(value["ScalingAdjustment"].asString());
  90. scalingRulesObject.stepAdjustments.push_back(stepAdjustmentsObject);
  91. }
  92. scalingRules_.push_back(scalingRulesObject);
  93. }
  94. if(!value["TotalCount"].isNull())
  95. totalCount_ = std::stoi(value["TotalCount"].asString());
  96. if(!value["PageNumber"].isNull())
  97. pageNumber_ = std::stoi(value["PageNumber"].asString());
  98. if(!value["PageSize"].isNull())
  99. pageSize_ = std::stoi(value["PageSize"].asString());
  100. }
  101. std::vector<DescribeScalingRulesResult::ScalingRule> DescribeScalingRulesResult::getScalingRules()const
  102. {
  103. return scalingRules_;
  104. }
  105. int DescribeScalingRulesResult::getTotalCount()const
  106. {
  107. return totalCount_;
  108. }
  109. int DescribeScalingRulesResult::getPageSize()const
  110. {
  111. return pageSize_;
  112. }
  113. int DescribeScalingRulesResult::getPageNumber()const
  114. {
  115. return pageNumber_;
  116. }