Add API OpenOnsService which can active ons service.

This commit is contained in:
sdk-team
2020-09-29 08:44:45 +00:00
parent 37c044aa31
commit e3b1009a94
10 changed files with 236 additions and 3 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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;

View File

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

View File

@@ -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_

View File

@@ -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_

View File

@@ -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();

View File

@@ -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();

View File

@@ -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()
{}

View File

@@ -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_;
}