Просмотр исходного кода

由荣旸发起的TESLAMAXCOMPUTE SDK自动发布, BUILD_ID=314, 版本号:1.2.4

Signed-off-by: haowei.yao <haowei.yao@alibaba-inc.com>
haowei.yao 8 лет назад
Родитель
Сommit
78ee1b30bd

+ 4 - 0
CHANGELOG

@@ -1,3 +1,7 @@
+2018-02-28 Version: 1.2.4
+1, Add query resource inventory API.
+2, Add query topology API.
+
 2018-02-27 Version: 1.2.3
 1, Add query topology API.
 

+ 1 - 1
VERSION

@@ -1 +1 @@
-1.2.3
+1.2.4

+ 4 - 0
teslamaxcompute/CMakeLists.txt

@@ -25,6 +25,8 @@ set(teslamaxcompute_public_header_model
 	include/alibabacloud/teslamaxcompute/model/GetUserInstanceResult.h
 	include/alibabacloud/teslamaxcompute/model/GetProjectInstanceRequest.h
 	include/alibabacloud/teslamaxcompute/model/GetProjectInstanceResult.h
+	include/alibabacloud/teslamaxcompute/model/QueryResourceInventoryRequest.h
+	include/alibabacloud/teslamaxcompute/model/QueryResourceInventoryResult.h
 	include/alibabacloud/teslamaxcompute/model/QueryTopologyRequest.h
 	include/alibabacloud/teslamaxcompute/model/QueryTopologyResult.h
 	include/alibabacloud/teslamaxcompute/model/GetInstancesStatusCountRequest.h
@@ -42,6 +44,8 @@ set(teslamaxcompute_src
 	src/model/GetUserInstanceResult.cc
 	src/model/GetProjectInstanceRequest.cc
 	src/model/GetProjectInstanceResult.cc
+	src/model/QueryResourceInventoryRequest.cc
+	src/model/QueryResourceInventoryResult.cc
 	src/model/QueryTopologyRequest.cc
 	src/model/QueryTopologyResult.cc
 	src/model/GetInstancesStatusCountRequest.cc

+ 8 - 0
teslamaxcompute/include/alibabacloud/teslamaxcompute/TeslaMaxComputeClient.h

@@ -26,6 +26,8 @@
 #include "model/GetUserInstanceResult.h"
 #include "model/GetProjectInstanceRequest.h"
 #include "model/GetProjectInstanceResult.h"
+#include "model/QueryResourceInventoryRequest.h"
+#include "model/QueryResourceInventoryResult.h"
 #include "model/QueryTopologyRequest.h"
 #include "model/QueryTopologyResult.h"
 #include "model/GetInstancesStatusCountRequest.h"
@@ -51,6 +53,9 @@ namespace AlibabaCloud
 			typedef Outcome<Error, Model::GetProjectInstanceResult> GetProjectInstanceOutcome;			
 			typedef std::future<GetProjectInstanceOutcome> GetProjectInstanceOutcomeCallable;			
 			typedef std::function<void(const TeslaMaxComputeClient*, const Model::GetProjectInstanceRequest&, const GetProjectInstanceOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> GetProjectInstanceAsyncHandler;
+			typedef Outcome<Error, Model::QueryResourceInventoryResult> QueryResourceInventoryOutcome;			
+			typedef std::future<QueryResourceInventoryOutcome> QueryResourceInventoryOutcomeCallable;			
+			typedef std::function<void(const TeslaMaxComputeClient*, const Model::QueryResourceInventoryRequest&, const QueryResourceInventoryOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> QueryResourceInventoryAsyncHandler;
 			typedef Outcome<Error, Model::QueryTopologyResult> QueryTopologyOutcome;			
 			typedef std::future<QueryTopologyOutcome> QueryTopologyOutcomeCallable;			
 			typedef std::function<void(const TeslaMaxComputeClient*, const Model::QueryTopologyRequest&, const QueryTopologyOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> QueryTopologyAsyncHandler;
@@ -77,6 +82,9 @@ namespace AlibabaCloud
             GetProjectInstanceOutcome getProjectInstance(const Model::GetProjectInstanceRequest &request)const;
             void getProjectInstanceAsync(const Model::GetProjectInstanceRequest& request, const GetProjectInstanceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
             GetProjectInstanceOutcomeCallable getProjectInstanceCallable(const Model::GetProjectInstanceRequest& request) const;
+            QueryResourceInventoryOutcome queryResourceInventory(const Model::QueryResourceInventoryRequest &request)const;
+            void queryResourceInventoryAsync(const Model::QueryResourceInventoryRequest& request, const QueryResourceInventoryAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
+            QueryResourceInventoryOutcomeCallable queryResourceInventoryCallable(const Model::QueryResourceInventoryRequest& request) const;
             QueryTopologyOutcome queryTopology(const Model::QueryTopologyRequest &request)const;
             void queryTopologyAsync(const Model::QueryTopologyRequest& request, const QueryTopologyAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
             QueryTopologyOutcomeCallable queryTopologyCallable(const Model::QueryTopologyRequest& request) const;

+ 45 - 0
teslamaxcompute/include/alibabacloud/teslamaxcompute/model/QueryResourceInventoryRequest.h

@@ -0,0 +1,45 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ALIBABACLOUD_TESLAMAXCOMPUTE_MODEL_QUERYRESOURCEINVENTORYREQUEST_H_
+#define ALIBABACLOUD_TESLAMAXCOMPUTE_MODEL_QUERYRESOURCEINVENTORYREQUEST_H_
+
+#include <string>
+#include <vector>
+#include <alibabacloud/core/RpcServiceRequest.h>
+#include <alibabacloud/teslamaxcompute/TeslaMaxComputeExport.h>
+
+namespace AlibabaCloud
+{
+	namespace TeslaMaxCompute
+	{
+		namespace Model
+		{
+			class ALIBABACLOUD_TESLAMAXCOMPUTE_EXPORT QueryResourceInventoryRequest : public RpcServiceRequest
+			{
+
+			public:
+				QueryResourceInventoryRequest();
+				~QueryResourceInventoryRequest();
+
+
+            private:
+
+			};
+		}
+	}
+}
+#endif // !ALIBABACLOUD_TESLAMAXCOMPUTE_MODEL_QUERYRESOURCEINVENTORYREQUEST_H_

+ 81 - 0
teslamaxcompute/include/alibabacloud/teslamaxcompute/model/QueryResourceInventoryResult.h

@@ -0,0 +1,81 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ALIBABACLOUD_TESLAMAXCOMPUTE_MODEL_QUERYRESOURCEINVENTORYRESULT_H_
+#define ALIBABACLOUD_TESLAMAXCOMPUTE_MODEL_QUERYRESOURCEINVENTORYRESULT_H_
+
+#include <string>
+#include <vector>
+#include <utility>
+#include <alibabacloud/core/ServiceResult.h>
+#include <alibabacloud/teslamaxcompute/TeslaMaxComputeExport.h>
+
+namespace AlibabaCloud
+{
+	namespace TeslaMaxCompute
+	{
+		namespace Model
+		{
+			class ALIBABACLOUD_TESLAMAXCOMPUTE_EXPORT QueryResourceInventoryResult : public ServiceResult
+			{
+			public:
+				struct Data
+				{
+					struct Cluster
+					{
+						struct ResourceParameter
+						{
+							std::string paraName;
+							std::string paraValue;
+						};
+						struct ResourceInventory
+						{
+							long used;
+							long total;
+							long available;
+							std::string resourceType;
+						};
+						std::string status;
+						std::vector<Cluster::ResourceInventory> resourceInventories;
+						std::string cluster;
+						std::string region;
+						std::string machineRoom;
+						std::vector<Cluster::ResourceParameter> resourceParameters;
+					};
+					std::string lastUpdate;
+					std::vector<Cluster> clusters;
+				};
+
+
+				QueryResourceInventoryResult();
+				explicit QueryResourceInventoryResult(const std::string &payload);
+				~QueryResourceInventoryResult();
+				std::string getMessage()const;
+				std::vector<Data> getData()const;
+				int getCode()const;
+
+			protected:
+				void parse(const std::string &payload);
+			private:
+				std::string message_;
+				std::vector<Data> data_;
+				int code_;
+
+			};
+		}
+	}
+}
+#endif // !ALIBABACLOUD_TESLAMAXCOMPUTE_MODEL_QUERYRESOURCEINVENTORYRESULT_H_

+ 7 - 7
teslamaxcompute/include/alibabacloud/teslamaxcompute/model/QueryTopologyResult.h

@@ -32,11 +32,11 @@ namespace AlibabaCloud
 			class ALIBABACLOUD_TESLAMAXCOMPUTE_EXPORT QueryTopologyResult : public ServiceResult
 			{
 			public:
-				struct Result
+				struct ResultItem
 				{
-					struct Regions
+					struct RegionItem
 					{
-						struct Clusters
+						struct ClusterItem
 						{
 							std::string netArch;
 							std::string netCode;
@@ -46,13 +46,13 @@ namespace AlibabaCloud
 							std::string productLine;
 							std::string business;
 						};
-						std::vector<Clusters> clusters;
+						std::vector<RegionItem::ClusterItem> clusters;
 						std::string regionEnName;
 						std::string region;
 						std::string regionCnName;
 					};
 					std::string lastUpdate;
-					std::vector<Regions> regions;
+					std::vector<ResultItem::RegionItem> regions;
 				};
 
 
@@ -61,14 +61,14 @@ namespace AlibabaCloud
 				~QueryTopologyResult();
 				std::string getMessage()const;
 				int getCode()const;
-				std::vector<Result> getResult()const;
+				std::vector<ResultItem> getResult()const;
 
 			protected:
 				void parse(const std::string &payload);
 			private:
 				std::string message_;
 				int code_;
-				std::vector<Result> result_;
+				std::vector<ResultItem> result_;
 
 			};
 		}

+ 36 - 0
teslamaxcompute/src/TeslaMaxComputeClient.cc

@@ -131,6 +131,42 @@ TeslaMaxComputeClient::GetProjectInstanceOutcomeCallable TeslaMaxComputeClient::
 	return task->get_future();
 }
 
+TeslaMaxComputeClient::QueryResourceInventoryOutcome TeslaMaxComputeClient::queryResourceInventory(const QueryResourceInventoryRequest &request) const
+{
+	auto endpointOutcome = endpoint();
+	if (!endpointOutcome.isSuccess())
+		return QueryResourceInventoryOutcome(endpointOutcome.error());
+
+	auto outcome = makeRequest(endpointOutcome.result(), request);
+
+	if (outcome.isSuccess())
+		return QueryResourceInventoryOutcome(QueryResourceInventoryResult(outcome.result()));
+	else
+		return QueryResourceInventoryOutcome(outcome.error());
+}
+
+void TeslaMaxComputeClient::queryResourceInventoryAsync(const QueryResourceInventoryRequest& request, const QueryResourceInventoryAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
+{
+	auto fn = [this, request, handler, context]()
+	{
+		handler(this, request, queryResourceInventory(request), context);
+	};
+
+	asyncExecute(new Runnable(fn));
+}
+
+TeslaMaxComputeClient::QueryResourceInventoryOutcomeCallable TeslaMaxComputeClient::queryResourceInventoryCallable(const QueryResourceInventoryRequest &request) const
+{
+	auto task = std::make_shared<std::packaged_task<QueryResourceInventoryOutcome()>>(
+			[this, request]()
+			{
+			return this->queryResourceInventory(request);
+			});
+
+	asyncExecute(new Runnable([task]() { (*task)(); }));
+	return task->get_future();
+}
+
 TeslaMaxComputeClient::QueryTopologyOutcome TeslaMaxComputeClient::queryTopology(const QueryTopologyRequest &request) const
 {
 	auto endpointOutcome = endpoint();

+ 27 - 0
teslamaxcompute/src/model/QueryResourceInventoryRequest.cc

@@ -0,0 +1,27 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <alibabacloud/teslamaxcompute/model/QueryResourceInventoryRequest.h>
+
+using AlibabaCloud::TeslaMaxCompute::Model::QueryResourceInventoryRequest;
+
+QueryResourceInventoryRequest::QueryResourceInventoryRequest() :
+	RpcServiceRequest("teslamaxcompute", "2018-01-04", "QueryResourceInventory")
+{}
+
+QueryResourceInventoryRequest::~QueryResourceInventoryRequest()
+{}
+

+ 110 - 0
teslamaxcompute/src/model/QueryResourceInventoryResult.cc

@@ -0,0 +1,110 @@
+/*
+ * Copyright 2009-2017 Alibaba Cloud All rights reserved.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <alibabacloud/teslamaxcompute/model/QueryResourceInventoryResult.h>
+#include <json/json.h>
+
+using namespace AlibabaCloud::TeslaMaxCompute;
+using namespace AlibabaCloud::TeslaMaxCompute::Model;
+
+QueryResourceInventoryResult::QueryResourceInventoryResult() :
+	ServiceResult()
+{}
+
+QueryResourceInventoryResult::QueryResourceInventoryResult(const std::string &payload) :
+	ServiceResult()
+{
+	parse(payload);
+}
+
+QueryResourceInventoryResult::~QueryResourceInventoryResult()
+{}
+
+void QueryResourceInventoryResult::parse(const std::string &payload)
+{
+	Json::Reader reader;
+	Json::Value value;
+	reader.parse(payload, value);
+
+	setRequestId(value["RequestId"].asString());
+	auto allData = value["Data"];
+	for (auto value : allData)
+	{
+		Data dataObject;
+		if(!value["LastUpdate"].isNull())
+			dataObject.lastUpdate = value["LastUpdate"].asString();
+		auto allClusters = value["Clusters"]["cluster"];
+		for (auto value : allClusters)
+		{
+			Data::Cluster clusterObject;
+			if(!value["Status"].isNull())
+				clusterObject.status = value["Status"].asString();
+			if(!value["Cluster"].isNull())
+				clusterObject.cluster = value["Cluster"].asString();
+			if(!value["MachineRoom"].isNull())
+				clusterObject.machineRoom = value["MachineRoom"].asString();
+			if(!value["Region"].isNull())
+				clusterObject.region = value["Region"].asString();
+			auto allResourceParameters = value["ResourceParameters"]["resourceParameter"];
+			for (auto value : allResourceParameters)
+			{
+				Data::Cluster::ResourceParameter resourceParametersObject;
+				if(!value["ParaName"].isNull())
+					resourceParametersObject.paraName = value["ParaName"].asString();
+				if(!value["ParaValue"].isNull())
+					resourceParametersObject.paraValue = value["ParaValue"].asString();
+				clusterObject.resourceParameters.push_back(resourceParametersObject);
+			}
+			auto allResourceInventories = value["ResourceInventories"]["resourceInventory"];
+			for (auto value : allResourceInventories)
+			{
+				Data::Cluster::ResourceInventory resourceInventoriesObject;
+				if(!value["Total"].isNull())
+					resourceInventoriesObject.total = std::stol(value["Total"].asString());
+				if(!value["Available"].isNull())
+					resourceInventoriesObject.available = std::stol(value["Available"].asString());
+				if(!value["Used"].isNull())
+					resourceInventoriesObject.used = std::stol(value["Used"].asString());
+				if(!value["ResourceType"].isNull())
+					resourceInventoriesObject.resourceType = value["ResourceType"].asString();
+				clusterObject.resourceInventories.push_back(resourceInventoriesObject);
+			}
+			dataObject.clusters.push_back(clusterObject);
+		}
+		data_.push_back(dataObject);
+	}
+	if(!value["Code"].isNull())
+		code_ = std::stoi(value["Code"].asString());
+	if(!value["Message"].isNull())
+		message_ = value["Message"].asString();
+
+}
+
+std::string QueryResourceInventoryResult::getMessage()const
+{
+	return message_;
+}
+
+std::vector<QueryResourceInventoryResult::Data> QueryResourceInventoryResult::getData()const
+{
+	return data_;
+}
+
+int QueryResourceInventoryResult::getCode()const
+{
+	return code_;
+}
+

+ 7 - 7
teslamaxcompute/src/model/QueryTopologyResult.cc

@@ -40,26 +40,26 @@ void QueryTopologyResult::parse(const std::string &payload)
 	reader.parse(payload, value);
 
 	setRequestId(value["RequestId"].asString());
-	auto allResult = value["Result"];
+	auto allResult = value["Result"]["resultItem"];
 	for (auto value : allResult)
 	{
-		Result resultObject;
+		ResultItem resultObject;
 		if(!value["LastUpdate"].isNull())
 			resultObject.lastUpdate = value["LastUpdate"].asString();
-		auto allRegions = value["Regions"];
+		auto allRegions = value["Regions"]["regionItem"];
 		for (auto value : allRegions)
 		{
-			Result::Regions regionsObject;
+			ResultItem::RegionItem regionsObject;
 			if(!value["Region"].isNull())
 				regionsObject.region = value["Region"].asString();
 			if(!value["RegionEnName"].isNull())
 				regionsObject.regionEnName = value["RegionEnName"].asString();
 			if(!value["RegionCnName"].isNull())
 				regionsObject.regionCnName = value["RegionCnName"].asString();
-			auto allClusters = value["Clusters"];
+			auto allClusters = value["Clusters"]["clusterItem"];
 			for (auto value : allClusters)
 			{
-				Result::Regions::Clusters clustersObject;
+				ResultItem::RegionItem::ClusterItem clustersObject;
 				if(!value["Cluster"].isNull())
 					clustersObject.cluster = value["Cluster"].asString();
 				if(!value["ProductLine"].isNull())
@@ -97,7 +97,7 @@ int QueryTopologyResult::getCode()const
 	return code_;
 }
 
-std::vector<QueryTopologyResult::Result> QueryTopologyResult::getResult()const
+std::vector<QueryTopologyResult::ResultItem> QueryTopologyResult::getResult()const
 {
 	return result_;
 }