From 86f01c44a804234356dedc38c9bb7b1fadd46793 Mon Sep 17 00:00:00 2001 From: sdk-team Date: Wed, 2 Sep 2020 21:43:23 +0800 Subject: [PATCH] Support sg for ml region. --- CHANGELOG | 3 + VERSION | 2 +- saf/CMakeLists.txt | 4 ++ saf/include/alibabacloud/saf/SafClient.h | 8 +++ .../saf/model/ExecuteRequestMLRequest.h | 51 +++++++++++++++ .../saf/model/ExecuteRequestMLResult.h | 55 ++++++++++++++++ saf/src/SafClient.cc | 42 +++++++++++- saf/src/model/ExecuteRequestMLRequest.cc | 51 +++++++++++++++ saf/src/model/ExecuteRequestMLResult.cc | 65 +++++++++++++++++++ 9 files changed, 277 insertions(+), 4 deletions(-) create mode 100644 saf/include/alibabacloud/saf/model/ExecuteRequestMLRequest.h create mode 100644 saf/include/alibabacloud/saf/model/ExecuteRequestMLResult.h create mode 100644 saf/src/model/ExecuteRequestMLRequest.cc create mode 100644 saf/src/model/ExecuteRequestMLResult.cc diff --git a/CHANGELOG b/CHANGELOG index f9bdac3d6..d98bc49cf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +2020-09-02 Version: 1.36.631 +- Support sg for ml region. + 2020-09-02 Version: 1.36.630 - ChatApp second version. - Support new message fomat. diff --git a/VERSION b/VERSION index 3b6a40468..23fa65ea0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.36.630 \ No newline at end of file +1.36.631 \ No newline at end of file diff --git a/saf/CMakeLists.txt b/saf/CMakeLists.txt index 3952fff52..e2d3a06cb 100755 --- a/saf/CMakeLists.txt +++ b/saf/CMakeLists.txt @@ -25,6 +25,8 @@ set(saf_public_header_model include/alibabacloud/saf/model/ExecuteExtendServiceResult.h include/alibabacloud/saf/model/ExecuteRequestRequest.h include/alibabacloud/saf/model/ExecuteRequestResult.h + include/alibabacloud/saf/model/ExecuteRequestMLRequest.h + include/alibabacloud/saf/model/ExecuteRequestMLResult.h include/alibabacloud/saf/model/ExecuteRequestSGRequest.h include/alibabacloud/saf/model/ExecuteRequestSGResult.h ) @@ -34,6 +36,8 @@ set(saf_src src/model/ExecuteExtendServiceResult.cc src/model/ExecuteRequestRequest.cc src/model/ExecuteRequestResult.cc + src/model/ExecuteRequestMLRequest.cc + src/model/ExecuteRequestMLResult.cc src/model/ExecuteRequestSGRequest.cc src/model/ExecuteRequestSGResult.cc ) diff --git a/saf/include/alibabacloud/saf/SafClient.h b/saf/include/alibabacloud/saf/SafClient.h index 657c6fe3f..552c9cc27 100755 --- a/saf/include/alibabacloud/saf/SafClient.h +++ b/saf/include/alibabacloud/saf/SafClient.h @@ -26,6 +26,8 @@ #include "model/ExecuteExtendServiceResult.h" #include "model/ExecuteRequestRequest.h" #include "model/ExecuteRequestResult.h" +#include "model/ExecuteRequestMLRequest.h" +#include "model/ExecuteRequestMLResult.h" #include "model/ExecuteRequestSGRequest.h" #include "model/ExecuteRequestSGResult.h" @@ -43,6 +45,9 @@ namespace AlibabaCloud typedef Outcome ExecuteRequestOutcome; typedef std::future ExecuteRequestOutcomeCallable; typedef std::function&)> ExecuteRequestAsyncHandler; + typedef Outcome ExecuteRequestMLOutcome; + typedef std::future ExecuteRequestMLOutcomeCallable; + typedef std::function&)> ExecuteRequestMLAsyncHandler; typedef Outcome ExecuteRequestSGOutcome; typedef std::future ExecuteRequestSGOutcomeCallable; typedef std::function&)> ExecuteRequestSGAsyncHandler; @@ -57,6 +62,9 @@ namespace AlibabaCloud ExecuteRequestOutcome executeRequest(const Model::ExecuteRequestRequest &request)const; void executeRequestAsync(const Model::ExecuteRequestRequest& request, const ExecuteRequestAsyncHandler& handler, const std::shared_ptr& context = nullptr) const; ExecuteRequestOutcomeCallable executeRequestCallable(const Model::ExecuteRequestRequest& request) const; + ExecuteRequestMLOutcome executeRequestML(const Model::ExecuteRequestMLRequest &request)const; + void executeRequestMLAsync(const Model::ExecuteRequestMLRequest& request, const ExecuteRequestMLAsyncHandler& handler, const std::shared_ptr& context = nullptr) const; + ExecuteRequestMLOutcomeCallable executeRequestMLCallable(const Model::ExecuteRequestMLRequest& request) const; ExecuteRequestSGOutcome executeRequestSG(const Model::ExecuteRequestSGRequest &request)const; void executeRequestSGAsync(const Model::ExecuteRequestSGRequest& request, const ExecuteRequestSGAsyncHandler& handler, const std::shared_ptr& context = nullptr) const; ExecuteRequestSGOutcomeCallable executeRequestSGCallable(const Model::ExecuteRequestSGRequest& request) const; diff --git a/saf/include/alibabacloud/saf/model/ExecuteRequestMLRequest.h b/saf/include/alibabacloud/saf/model/ExecuteRequestMLRequest.h new file mode 100644 index 000000000..da4e061c4 --- /dev/null +++ b/saf/include/alibabacloud/saf/model/ExecuteRequestMLRequest.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_SAF_MODEL_EXECUTEREQUESTMLREQUEST_H_ +#define ALIBABACLOUD_SAF_MODEL_EXECUTEREQUESTMLREQUEST_H_ + +#include +#include +#include +#include + +namespace AlibabaCloud +{ + namespace Saf + { + namespace Model + { + class ALIBABACLOUD_SAF_EXPORT ExecuteRequestMLRequest : public RpcServiceRequest + { + + public: + ExecuteRequestMLRequest(); + ~ExecuteRequestMLRequest(); + + std::string getServiceParameters()const; + void setServiceParameters(const std::string& serviceParameters); + std::string getService()const; + void setService(const std::string& service); + + private: + std::string serviceParameters_; + std::string service_; + + }; + } + } +} +#endif // !ALIBABACLOUD_SAF_MODEL_EXECUTEREQUESTMLREQUEST_H_ \ No newline at end of file diff --git a/saf/include/alibabacloud/saf/model/ExecuteRequestMLResult.h b/saf/include/alibabacloud/saf/model/ExecuteRequestMLResult.h new file mode 100644 index 000000000..c1c557e97 --- /dev/null +++ b/saf/include/alibabacloud/saf/model/ExecuteRequestMLResult.h @@ -0,0 +1,55 @@ +/* + * 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_SAF_MODEL_EXECUTEREQUESTMLRESULT_H_ +#define ALIBABACLOUD_SAF_MODEL_EXECUTEREQUESTMLRESULT_H_ + +#include +#include +#include +#include +#include + +namespace AlibabaCloud +{ + namespace Saf + { + namespace Model + { + class ALIBABACLOUD_SAF_EXPORT ExecuteRequestMLResult : public ServiceResult + { + public: + + + ExecuteRequestMLResult(); + explicit ExecuteRequestMLResult(const std::string &payload); + ~ExecuteRequestMLResult(); + std::string getMessage()const; + std::string getData()const; + int getCode()const; + + protected: + void parse(const std::string &payload); + private: + std::string message_; + std::string data_; + int code_; + + }; + } + } +} +#endif // !ALIBABACLOUD_SAF_MODEL_EXECUTEREQUESTMLRESULT_H_ \ No newline at end of file diff --git a/saf/src/SafClient.cc b/saf/src/SafClient.cc index 8a55002ee..d089d8093 100755 --- a/saf/src/SafClient.cc +++ b/saf/src/SafClient.cc @@ -31,21 +31,21 @@ SafClient::SafClient(const Credentials &credentials, const ClientConfiguration & RpcServiceClient(SERVICE_NAME, std::make_shared(credentials), configuration) { auto locationClient = std::make_shared(credentials, configuration); - endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, "SAF"); + endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, "saf"); } SafClient::SafClient(const std::shared_ptr& credentialsProvider, const ClientConfiguration & configuration) : RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration) { auto locationClient = std::make_shared(credentialsProvider, configuration); - endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, "SAF"); + endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, "saf"); } SafClient::SafClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) : RpcServiceClient(SERVICE_NAME, std::make_shared(accessKeyId, accessKeySecret), configuration) { auto locationClient = std::make_shared(accessKeyId, accessKeySecret, configuration); - endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, "SAF"); + endpointProvider_ = std::make_shared(locationClient, configuration.regionId(), SERVICE_NAME, "saf"); } SafClient::~SafClient() @@ -123,6 +123,42 @@ SafClient::ExecuteRequestOutcomeCallable SafClient::executeRequestCallable(const return task->get_future(); } +SafClient::ExecuteRequestMLOutcome SafClient::executeRequestML(const ExecuteRequestMLRequest &request) const +{ + auto endpointOutcome = endpointProvider_->getEndpoint(); + if (!endpointOutcome.isSuccess()) + return ExecuteRequestMLOutcome(endpointOutcome.error()); + + auto outcome = makeRequest(endpointOutcome.result(), request); + + if (outcome.isSuccess()) + return ExecuteRequestMLOutcome(ExecuteRequestMLResult(outcome.result())); + else + return ExecuteRequestMLOutcome(outcome.error()); +} + +void SafClient::executeRequestMLAsync(const ExecuteRequestMLRequest& request, const ExecuteRequestMLAsyncHandler& handler, const std::shared_ptr& context) const +{ + auto fn = [this, request, handler, context]() + { + handler(this, request, executeRequestML(request), context); + }; + + asyncExecute(new Runnable(fn)); +} + +SafClient::ExecuteRequestMLOutcomeCallable SafClient::executeRequestMLCallable(const ExecuteRequestMLRequest &request) const +{ + auto task = std::make_shared>( + [this, request]() + { + return this->executeRequestML(request); + }); + + asyncExecute(new Runnable([task]() { (*task)(); })); + return task->get_future(); +} + SafClient::ExecuteRequestSGOutcome SafClient::executeRequestSG(const ExecuteRequestSGRequest &request) const { auto endpointOutcome = endpointProvider_->getEndpoint(); diff --git a/saf/src/model/ExecuteRequestMLRequest.cc b/saf/src/model/ExecuteRequestMLRequest.cc new file mode 100644 index 000000000..b97f11ace --- /dev/null +++ b/saf/src/model/ExecuteRequestMLRequest.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 + +using AlibabaCloud::Saf::Model::ExecuteRequestMLRequest; + +ExecuteRequestMLRequest::ExecuteRequestMLRequest() : + RpcServiceRequest("saf", "2019-05-21", "ExecuteRequestML") +{ + setMethod(HttpRequest::Method::Post); +} + +ExecuteRequestMLRequest::~ExecuteRequestMLRequest() +{} + +std::string ExecuteRequestMLRequest::getServiceParameters()const +{ + return serviceParameters_; +} + +void ExecuteRequestMLRequest::setServiceParameters(const std::string& serviceParameters) +{ + serviceParameters_ = serviceParameters; + setParameter("ServiceParameters", serviceParameters); +} + +std::string ExecuteRequestMLRequest::getService()const +{ + return service_; +} + +void ExecuteRequestMLRequest::setService(const std::string& service) +{ + service_ = service; + setParameter("Service", service); +} + diff --git a/saf/src/model/ExecuteRequestMLResult.cc b/saf/src/model/ExecuteRequestMLResult.cc new file mode 100644 index 000000000..e4c314cbc --- /dev/null +++ b/saf/src/model/ExecuteRequestMLResult.cc @@ -0,0 +1,65 @@ +/* + * 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 +#include + +using namespace AlibabaCloud::Saf; +using namespace AlibabaCloud::Saf::Model; + +ExecuteRequestMLResult::ExecuteRequestMLResult() : + ServiceResult() +{} + +ExecuteRequestMLResult::ExecuteRequestMLResult(const std::string &payload) : + ServiceResult() +{ + parse(payload); +} + +ExecuteRequestMLResult::~ExecuteRequestMLResult() +{} + +void ExecuteRequestMLResult::parse(const std::string &payload) +{ + Json::Reader reader; + Json::Value value; + reader.parse(payload, value); + setRequestId(value["RequestId"].asString()); + if(!value["Code"].isNull()) + code_ = std::stoi(value["Code"].asString()); + if(!value["Message"].isNull()) + message_ = value["Message"].asString(); + if(!value["Data"].isNull()) + data_ = value["Data"].asString(); + +} + +std::string ExecuteRequestMLResult::getMessage()const +{ + return message_; +} + +std::string ExecuteRequestMLResult::getData()const +{ + return data_; +} + +int ExecuteRequestMLResult::getCode()const +{ + return code_; +} +