GetInstanceResult.cc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/ots/model/GetInstanceResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Ots;
  19. using namespace AlibabaCloud::Ots::Model;
  20. GetInstanceResult::GetInstanceResult() :
  21. ServiceResult()
  22. {}
  23. GetInstanceResult::GetInstanceResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. GetInstanceResult::~GetInstanceResult()
  29. {}
  30. void GetInstanceResult::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 instanceInfoNode = value["InstanceInfo"];
  37. if(!instanceInfoNode["InstanceName"].isNull())
  38. instanceInfo_.instanceName = instanceInfoNode["InstanceName"].asString();
  39. if(!instanceInfoNode["UserId"].isNull())
  40. instanceInfo_.userId = instanceInfoNode["UserId"].asString();
  41. if(!instanceInfoNode["Network"].isNull())
  42. instanceInfo_.network = instanceInfoNode["Network"].asString();
  43. if(!instanceInfoNode["Status"].isNull())
  44. instanceInfo_.status = std::stoi(instanceInfoNode["Status"].asString());
  45. if(!instanceInfoNode["WriteCapacity"].isNull())
  46. instanceInfo_.writeCapacity = std::stoi(instanceInfoNode["WriteCapacity"].asString());
  47. if(!instanceInfoNode["ReadCapacity"].isNull())
  48. instanceInfo_.readCapacity = std::stoi(instanceInfoNode["ReadCapacity"].asString());
  49. if(!instanceInfoNode["Description"].isNull())
  50. instanceInfo_.description = instanceInfoNode["Description"].asString();
  51. if(!instanceInfoNode["CreateTime"].isNull())
  52. instanceInfo_.createTime = instanceInfoNode["CreateTime"].asString();
  53. if(!instanceInfoNode["ClusterType"].isNull())
  54. instanceInfo_.clusterType = instanceInfoNode["ClusterType"].asString();
  55. auto allTagInfos = value["TagInfos"]["TagInfo"];
  56. for (auto value : allTagInfos)
  57. {
  58. InstanceInfo::TagInfo tagInfoObject;
  59. if(!value["TagKey"].isNull())
  60. tagInfoObject.tagKey = value["TagKey"].asString();
  61. if(!value["TagValue"].isNull())
  62. tagInfoObject.tagValue = value["TagValue"].asString();
  63. instanceInfo_.tagInfos.push_back(tagInfoObject);
  64. }
  65. auto quotaNode = instanceInfoNode["Quota"];
  66. if(!quotaNode["EntityQuota"].isNull())
  67. instanceInfo_.quota.entityQuota = std::stoi(quotaNode["EntityQuota"].asString());
  68. }
  69. GetInstanceResult::InstanceInfo GetInstanceResult::getInstanceInfo()const
  70. {
  71. return instanceInfo_;
  72. }