DescribeClusterResult.cc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/DescribeClusterResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::EHPC;
  19. using namespace AlibabaCloud::EHPC::Model;
  20. DescribeClusterResult::DescribeClusterResult() :
  21. ServiceResult()
  22. {}
  23. DescribeClusterResult::DescribeClusterResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. DescribeClusterResult::~DescribeClusterResult()
  29. {}
  30. void DescribeClusterResult::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 clusterInfoNode = value["ClusterInfo"];
  37. if(!clusterInfoNode["Id"].isNull())
  38. clusterInfo_.id = clusterInfoNode["Id"].asString();
  39. if(!clusterInfoNode["RegionId"].isNull())
  40. clusterInfo_.regionId = clusterInfoNode["RegionId"].asString();
  41. if(!clusterInfoNode["Name"].isNull())
  42. clusterInfo_.name = clusterInfoNode["Name"].asString();
  43. if(!clusterInfoNode["Description"].isNull())
  44. clusterInfo_.description = clusterInfoNode["Description"].asString();
  45. if(!clusterInfoNode["Status"].isNull())
  46. clusterInfo_.status = clusterInfoNode["Status"].asString();
  47. if(!clusterInfoNode["OsTag"].isNull())
  48. clusterInfo_.osTag = clusterInfoNode["OsTag"].asString();
  49. if(!clusterInfoNode["AccountType"].isNull())
  50. clusterInfo_.accountType = clusterInfoNode["AccountType"].asString();
  51. if(!clusterInfoNode["SchedulerType"].isNull())
  52. clusterInfo_.schedulerType = clusterInfoNode["SchedulerType"].asString();
  53. if(!clusterInfoNode["CreateTime"].isNull())
  54. clusterInfo_.createTime = clusterInfoNode["CreateTime"].asString();
  55. if(!clusterInfoNode["SecurityGroupId"].isNull())
  56. clusterInfo_.securityGroupId = clusterInfoNode["SecurityGroupId"].asString();
  57. if(!clusterInfoNode["VpcId"].isNull())
  58. clusterInfo_.vpcId = clusterInfoNode["VpcId"].asString();
  59. if(!clusterInfoNode["VSwitchId"].isNull())
  60. clusterInfo_.vSwitchId = clusterInfoNode["VSwitchId"].asString();
  61. if(!clusterInfoNode["VolumeType"].isNull())
  62. clusterInfo_.volumeType = clusterInfoNode["VolumeType"].asString();
  63. if(!clusterInfoNode["VolumeId"].isNull())
  64. clusterInfo_.volumeId = clusterInfoNode["VolumeId"].asString();
  65. if(!clusterInfoNode["VolumeProtocol"].isNull())
  66. clusterInfo_.volumeProtocol = clusterInfoNode["VolumeProtocol"].asString();
  67. if(!clusterInfoNode["VolumeMountpoint"].isNull())
  68. clusterInfo_.volumeMountpoint = clusterInfoNode["VolumeMountpoint"].asString();
  69. if(!clusterInfoNode["RemoteDirectory"].isNull())
  70. clusterInfo_.remoteDirectory = clusterInfoNode["RemoteDirectory"].asString();
  71. if(!clusterInfoNode["DeployMode"].isNull())
  72. clusterInfo_.deployMode = clusterInfoNode["DeployMode"].asString();
  73. if(!clusterInfoNode["HaEnable"].isNull())
  74. clusterInfo_.haEnable = clusterInfoNode["HaEnable"].asString() == "true";
  75. if(!clusterInfoNode["EcsChargeType"].isNull())
  76. clusterInfo_.ecsChargeType = clusterInfoNode["EcsChargeType"].asString();
  77. if(!clusterInfoNode["KeyPairName"].isNull())
  78. clusterInfo_.keyPairName = clusterInfoNode["KeyPairName"].asString();
  79. if(!clusterInfoNode["SccClusterId"].isNull())
  80. clusterInfo_.sccClusterId = clusterInfoNode["SccClusterId"].asString();
  81. if(!clusterInfoNode["ClientVersion"].isNull())
  82. clusterInfo_.clientVersion = clusterInfoNode["ClientVersion"].asString();
  83. if(!clusterInfoNode["ImageOwnerAlias"].isNull())
  84. clusterInfo_.imageOwnerAlias = clusterInfoNode["ImageOwnerAlias"].asString();
  85. if(!clusterInfoNode["ImageId"].isNull())
  86. clusterInfo_.imageId = clusterInfoNode["ImageId"].asString();
  87. if(!clusterInfoNode["Location"].isNull())
  88. clusterInfo_.location = clusterInfoNode["Location"].asString();
  89. if(!clusterInfoNode["BaseOsTag"].isNull())
  90. clusterInfo_.baseOsTag = clusterInfoNode["BaseOsTag"].asString();
  91. if(!clusterInfoNode["ImageName"].isNull())
  92. clusterInfo_.imageName = clusterInfoNode["ImageName"].asString();
  93. auto allApplicationsNode = clusterInfoNode["Applications"]["ApplicationInfo"];
  94. for (auto clusterInfoNodeApplicationsApplicationInfo : allApplicationsNode)
  95. {
  96. ClusterInfo::ApplicationInfo applicationInfoObject;
  97. if(!clusterInfoNodeApplicationsApplicationInfo["Tag"].isNull())
  98. applicationInfoObject.tag = clusterInfoNodeApplicationsApplicationInfo["Tag"].asString();
  99. if(!clusterInfoNodeApplicationsApplicationInfo["Name"].isNull())
  100. applicationInfoObject.name = clusterInfoNodeApplicationsApplicationInfo["Name"].asString();
  101. if(!clusterInfoNodeApplicationsApplicationInfo["Version"].isNull())
  102. applicationInfoObject.version = clusterInfoNodeApplicationsApplicationInfo["Version"].asString();
  103. clusterInfo_.applications.push_back(applicationInfoObject);
  104. }
  105. auto allPostInstallScriptsNode = clusterInfoNode["PostInstallScripts"]["PostInstallScriptInfo"];
  106. for (auto clusterInfoNodePostInstallScriptsPostInstallScriptInfo : allPostInstallScriptsNode)
  107. {
  108. ClusterInfo::PostInstallScriptInfo postInstallScriptInfoObject;
  109. if(!clusterInfoNodePostInstallScriptsPostInstallScriptInfo["Url"].isNull())
  110. postInstallScriptInfoObject.url = clusterInfoNodePostInstallScriptsPostInstallScriptInfo["Url"].asString();
  111. if(!clusterInfoNodePostInstallScriptsPostInstallScriptInfo["Args"].isNull())
  112. postInstallScriptInfoObject.args = clusterInfoNodePostInstallScriptsPostInstallScriptInfo["Args"].asString();
  113. clusterInfo_.postInstallScripts.push_back(postInstallScriptInfoObject);
  114. }
  115. auto ecsInfoNode = clusterInfoNode["EcsInfo"];
  116. auto managerNode = ecsInfoNode["Manager"];
  117. if(!managerNode["Count"].isNull())
  118. clusterInfo_.ecsInfo.manager.count = std::stoi(managerNode["Count"].asString());
  119. if(!managerNode["InstanceType"].isNull())
  120. clusterInfo_.ecsInfo.manager.instanceType = managerNode["InstanceType"].asString();
  121. auto computeNode = ecsInfoNode["Compute"];
  122. if(!computeNode["Count"].isNull())
  123. clusterInfo_.ecsInfo.compute.count = std::stoi(computeNode["Count"].asString());
  124. if(!computeNode["InstanceType"].isNull())
  125. clusterInfo_.ecsInfo.compute.instanceType = computeNode["InstanceType"].asString();
  126. auto loginNode = ecsInfoNode["Login"];
  127. if(!loginNode["Count"].isNull())
  128. clusterInfo_.ecsInfo.login.count = std::stoi(loginNode["Count"].asString());
  129. if(!loginNode["InstanceType"].isNull())
  130. clusterInfo_.ecsInfo.login.instanceType = loginNode["InstanceType"].asString();
  131. }
  132. DescribeClusterResult::ClusterInfo DescribeClusterResult::getClusterInfo()const
  133. {
  134. return clusterInfo_;
  135. }