Selaa lähdekoodia

Add API OpenOnsService which can active ons service.

sdk-team 6 vuotta sitten
vanhempi
sitoutus
e3b1009a94

+ 3 - 0
CHANGELOG

@@ -1,3 +1,6 @@
+2020-09-29 Version: patch
+- Add API OpenOnsService which can active ons service.
+
 2020-09-29 Version: patch
 - Supported regional API.
 

+ 4 - 0
ons/CMakeLists.txt

@@ -115,6 +115,8 @@ set(ons_public_header_model
 	include/alibabacloud/ons/model/OnsWarnCreateResult.h
 	include/alibabacloud/ons/model/OnsWarnDeleteRequest.h
 	include/alibabacloud/ons/model/OnsWarnDeleteResult.h
+	include/alibabacloud/ons/model/OpenOnsServiceRequest.h
+	include/alibabacloud/ons/model/OpenOnsServiceResult.h
 	include/alibabacloud/ons/model/TagResourcesRequest.h
 	include/alibabacloud/ons/model/TagResourcesResult.h
 	include/alibabacloud/ons/model/UntagResourcesRequest.h
@@ -216,6 +218,8 @@ set(ons_src
 	src/model/OnsWarnCreateResult.cc
 	src/model/OnsWarnDeleteRequest.cc
 	src/model/OnsWarnDeleteResult.cc
+	src/model/OpenOnsServiceRequest.cc
+	src/model/OpenOnsServiceResult.cc
 	src/model/TagResourcesRequest.cc
 	src/model/TagResourcesResult.cc
 	src/model/UntagResourcesRequest.cc

+ 8 - 0
ons/include/alibabacloud/ons/OnsClient.h

@@ -116,6 +116,8 @@
 #include "model/OnsWarnCreateResult.h"
 #include "model/OnsWarnDeleteRequest.h"
 #include "model/OnsWarnDeleteResult.h"
+#include "model/OpenOnsServiceRequest.h"
+#include "model/OpenOnsServiceResult.h"
 #include "model/TagResourcesRequest.h"
 #include "model/TagResourcesResult.h"
 #include "model/UntagResourcesRequest.h"
@@ -270,6 +272,9 @@ namespace AlibabaCloud
 			typedef Outcome<Error, Model::OnsWarnDeleteResult> OnsWarnDeleteOutcome;
 			typedef std::future<OnsWarnDeleteOutcome> OnsWarnDeleteOutcomeCallable;
 			typedef std::function<void(const OnsClient*, const Model::OnsWarnDeleteRequest&, const OnsWarnDeleteOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> OnsWarnDeleteAsyncHandler;
+			typedef Outcome<Error, Model::OpenOnsServiceResult> OpenOnsServiceOutcome;
+			typedef std::future<OpenOnsServiceOutcome> OpenOnsServiceOutcomeCallable;
+			typedef std::function<void(const OnsClient*, const Model::OpenOnsServiceRequest&, const OpenOnsServiceOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> OpenOnsServiceAsyncHandler;
 			typedef Outcome<Error, Model::TagResourcesResult> TagResourcesOutcome;
 			typedef std::future<TagResourcesOutcome> TagResourcesOutcomeCallable;
 			typedef std::function<void(const OnsClient*, const Model::TagResourcesRequest&, const TagResourcesOutcome&, const std::shared_ptr<const AsyncCallerContext>&)> TagResourcesAsyncHandler;
@@ -422,6 +427,9 @@ namespace AlibabaCloud
 			OnsWarnDeleteOutcome onsWarnDelete(const Model::OnsWarnDeleteRequest &request)const;
 			void onsWarnDeleteAsync(const Model::OnsWarnDeleteRequest& request, const OnsWarnDeleteAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
 			OnsWarnDeleteOutcomeCallable onsWarnDeleteCallable(const Model::OnsWarnDeleteRequest& request) const;
+			OpenOnsServiceOutcome openOnsService(const Model::OpenOnsServiceRequest &request)const;
+			void openOnsServiceAsync(const Model::OpenOnsServiceRequest& request, const OpenOnsServiceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
+			OpenOnsServiceOutcomeCallable openOnsServiceCallable(const Model::OpenOnsServiceRequest& request) const;
 			TagResourcesOutcome tagResources(const Model::TagResourcesRequest &request)const;
 			void tagResourcesAsync(const Model::TagResourcesRequest& request, const TagResourcesAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
 			TagResourcesOutcomeCallable tagResourcesCallable(const Model::TagResourcesRequest& request) const;

+ 2 - 0
ons/include/alibabacloud/ons/model/OnsInstanceBaseInfoResult.h

@@ -43,6 +43,8 @@ namespace AlibabaCloud
 					};
 					Endpoints endpoints;
 					std::string instanceName;
+					long maxTps;
+					int topicCapacity;
 					std::string instanceId;
 					long releaseTime;
 					int instanceStatus;

+ 45 - 0
ons/include/alibabacloud/ons/model/OpenOnsServiceRequest.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_ONS_MODEL_OPENONSSERVICEREQUEST_H_
+#define ALIBABACLOUD_ONS_MODEL_OPENONSSERVICEREQUEST_H_
+
+#include <string>
+#include <vector>
+#include <alibabacloud/core/RpcServiceRequest.h>
+#include <alibabacloud/ons/OnsExport.h>
+
+namespace AlibabaCloud
+{
+	namespace Ons
+	{
+		namespace Model
+		{
+			class ALIBABACLOUD_ONS_EXPORT OpenOnsServiceRequest : public RpcServiceRequest
+			{
+
+			public:
+				OpenOnsServiceRequest();
+				~OpenOnsServiceRequest();
+
+
+            private:
+
+			};
+		}
+	}
+}
+#endif // !ALIBABACLOUD_ONS_MODEL_OPENONSSERVICEREQUEST_H_

+ 51 - 0
ons/include/alibabacloud/ons/model/OpenOnsServiceResult.h

@@ -0,0 +1,51 @@
+/*
+ * 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_ONS_MODEL_OPENONSSERVICERESULT_H_
+#define ALIBABACLOUD_ONS_MODEL_OPENONSSERVICERESULT_H_
+
+#include <string>
+#include <vector>
+#include <utility>
+#include <alibabacloud/core/ServiceResult.h>
+#include <alibabacloud/ons/OnsExport.h>
+
+namespace AlibabaCloud
+{
+	namespace Ons
+	{
+		namespace Model
+		{
+			class ALIBABACLOUD_ONS_EXPORT OpenOnsServiceResult : public ServiceResult
+			{
+			public:
+
+
+				OpenOnsServiceResult();
+				explicit OpenOnsServiceResult(const std::string &payload);
+				~OpenOnsServiceResult();
+				std::string getOrderId()const;
+
+			protected:
+				void parse(const std::string &payload);
+			private:
+				std::string orderId_;
+
+			};
+		}
+	}
+}
+#endif // !ALIBABACLOUD_ONS_MODEL_OPENONSSERVICERESULT_H_

+ 39 - 3
ons/src/OnsClient.cc

@@ -31,21 +31,21 @@ OnsClient::OnsClient(const Credentials &credentials, const ClientConfiguration &
 	RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
 {
 	auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
-	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "ons");
+	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
 }
 
 OnsClient::OnsClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
 	RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
 {
 	auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
-	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "ons");
+	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
 }
 
 OnsClient::OnsClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
 	RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
 {
 	auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
-	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "ons");
+	endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
 }
 
 OnsClient::~OnsClient()
@@ -1743,6 +1743,42 @@ OnsClient::OnsWarnDeleteOutcomeCallable OnsClient::onsWarnDeleteCallable(const O
 	return task->get_future();
 }
 
+OnsClient::OpenOnsServiceOutcome OnsClient::openOnsService(const OpenOnsServiceRequest &request) const
+{
+	auto endpointOutcome = endpointProvider_->getEndpoint();
+	if (!endpointOutcome.isSuccess())
+		return OpenOnsServiceOutcome(endpointOutcome.error());
+
+	auto outcome = makeRequest(endpointOutcome.result(), request);
+
+	if (outcome.isSuccess())
+		return OpenOnsServiceOutcome(OpenOnsServiceResult(outcome.result()));
+	else
+		return OpenOnsServiceOutcome(outcome.error());
+}
+
+void OnsClient::openOnsServiceAsync(const OpenOnsServiceRequest& request, const OpenOnsServiceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
+{
+	auto fn = [this, request, handler, context]()
+	{
+		handler(this, request, openOnsService(request), context);
+	};
+
+	asyncExecute(new Runnable(fn));
+}
+
+OnsClient::OpenOnsServiceOutcomeCallable OnsClient::openOnsServiceCallable(const OpenOnsServiceRequest &request) const
+{
+	auto task = std::make_shared<std::packaged_task<OpenOnsServiceOutcome()>>(
+			[this, request]()
+			{
+			return this->openOnsService(request);
+			});
+
+	asyncExecute(new Runnable([task]() { (*task)(); }));
+	return task->get_future();
+}
+
 OnsClient::TagResourcesOutcome OnsClient::tagResources(const TagResourcesRequest &request) const
 {
 	auto endpointOutcome = endpointProvider_->getEndpoint();

+ 4 - 0
ons/src/model/OnsInstanceBaseInfoResult.cc

@@ -54,6 +54,10 @@ void OnsInstanceBaseInfoResult::parse(const std::string &payload)
 		instanceBaseInfo_.independentNaming = instanceBaseInfoNode["IndependentNaming"].asString() == "true";
 	if(!instanceBaseInfoNode["Remark"].isNull())
 		instanceBaseInfo_.remark = instanceBaseInfoNode["Remark"].asString();
+	if(!instanceBaseInfoNode["TopicCapacity"].isNull())
+		instanceBaseInfo_.topicCapacity = std::stoi(instanceBaseInfoNode["TopicCapacity"].asString());
+	if(!instanceBaseInfoNode["MaxTps"].isNull())
+		instanceBaseInfo_.maxTps = std::stol(instanceBaseInfoNode["MaxTps"].asString());
 	auto endpointsNode = instanceBaseInfoNode["Endpoints"];
 	if(!endpointsNode["TcpEndpoint"].isNull())
 		instanceBaseInfo_.endpoints.tcpEndpoint = endpointsNode["TcpEndpoint"].asString();

+ 29 - 0
ons/src/model/OpenOnsServiceRequest.cc

@@ -0,0 +1,29 @@
+/*
+ * 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/ons/model/OpenOnsServiceRequest.h>
+
+using AlibabaCloud::Ons::Model::OpenOnsServiceRequest;
+
+OpenOnsServiceRequest::OpenOnsServiceRequest() :
+	RpcServiceRequest("ons", "2019-02-14", "OpenOnsService")
+{
+	setMethod(HttpRequest::Method::Post);
+}
+
+OpenOnsServiceRequest::~OpenOnsServiceRequest()
+{}
+

+ 51 - 0
ons/src/model/OpenOnsServiceResult.cc

@@ -0,0 +1,51 @@
+/*
+ * 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/ons/model/OpenOnsServiceResult.h>
+#include <json/json.h>
+
+using namespace AlibabaCloud::Ons;
+using namespace AlibabaCloud::Ons::Model;
+
+OpenOnsServiceResult::OpenOnsServiceResult() :
+	ServiceResult()
+{}
+
+OpenOnsServiceResult::OpenOnsServiceResult(const std::string &payload) :
+	ServiceResult()
+{
+	parse(payload);
+}
+
+OpenOnsServiceResult::~OpenOnsServiceResult()
+{}
+
+void OpenOnsServiceResult::parse(const std::string &payload)
+{
+	Json::Reader reader;
+	Json::Value value;
+	reader.parse(payload, value);
+	setRequestId(value["RequestId"].asString());
+	if(!value["OrderId"].isNull())
+		orderId_ = value["OrderId"].asString();
+
+}
+
+std::string OpenOnsServiceResult::getOrderId()const
+{
+	return orderId_;
+}
+