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

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