OtsClient.cc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/ots/OtsClient.h>
  17. #include <alibabacloud/core/SimpleCredentialsProvider.h>
  18. using namespace AlibabaCloud;
  19. using namespace AlibabaCloud::Location;
  20. using namespace AlibabaCloud::Ots;
  21. using namespace AlibabaCloud::Ots::Model;
  22. namespace
  23. {
  24. const std::string SERVICE_NAME = "Ots";
  25. }
  26. OtsClient::OtsClient(const Credentials &credentials, const ClientConfiguration &configuration) :
  27. RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
  28. {
  29. auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
  30. endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "ots");
  31. }
  32. OtsClient::OtsClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
  33. RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
  34. {
  35. auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
  36. endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "ots");
  37. }
  38. OtsClient::OtsClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
  39. RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
  40. {
  41. auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
  42. endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "ots");
  43. }
  44. OtsClient::~OtsClient()
  45. {}
  46. OtsClient::BindInstance2VpcOutcome OtsClient::bindInstance2Vpc(const BindInstance2VpcRequest &request) const
  47. {
  48. auto endpointOutcome = endpointProvider_->getEndpoint();
  49. if (!endpointOutcome.isSuccess())
  50. return BindInstance2VpcOutcome(endpointOutcome.error());
  51. auto outcome = makeRequest(endpointOutcome.result(), request);
  52. if (outcome.isSuccess())
  53. return BindInstance2VpcOutcome(BindInstance2VpcResult(outcome.result()));
  54. else
  55. return BindInstance2VpcOutcome(outcome.error());
  56. }
  57. void OtsClient::bindInstance2VpcAsync(const BindInstance2VpcRequest& request, const BindInstance2VpcAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  58. {
  59. auto fn = [this, request, handler, context]()
  60. {
  61. handler(this, request, bindInstance2Vpc(request), context);
  62. };
  63. asyncExecute(new Runnable(fn));
  64. }
  65. OtsClient::BindInstance2VpcOutcomeCallable OtsClient::bindInstance2VpcCallable(const BindInstance2VpcRequest &request) const
  66. {
  67. auto task = std::make_shared<std::packaged_task<BindInstance2VpcOutcome()>>(
  68. [this, request]()
  69. {
  70. return this->bindInstance2Vpc(request);
  71. });
  72. asyncExecute(new Runnable([task]() { (*task)(); }));
  73. return task->get_future();
  74. }
  75. OtsClient::DeleteInstanceOutcome OtsClient::deleteInstance(const DeleteInstanceRequest &request) const
  76. {
  77. auto endpointOutcome = endpointProvider_->getEndpoint();
  78. if (!endpointOutcome.isSuccess())
  79. return DeleteInstanceOutcome(endpointOutcome.error());
  80. auto outcome = makeRequest(endpointOutcome.result(), request);
  81. if (outcome.isSuccess())
  82. return DeleteInstanceOutcome(DeleteInstanceResult(outcome.result()));
  83. else
  84. return DeleteInstanceOutcome(outcome.error());
  85. }
  86. void OtsClient::deleteInstanceAsync(const DeleteInstanceRequest& request, const DeleteInstanceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  87. {
  88. auto fn = [this, request, handler, context]()
  89. {
  90. handler(this, request, deleteInstance(request), context);
  91. };
  92. asyncExecute(new Runnable(fn));
  93. }
  94. OtsClient::DeleteInstanceOutcomeCallable OtsClient::deleteInstanceCallable(const DeleteInstanceRequest &request) const
  95. {
  96. auto task = std::make_shared<std::packaged_task<DeleteInstanceOutcome()>>(
  97. [this, request]()
  98. {
  99. return this->deleteInstance(request);
  100. });
  101. asyncExecute(new Runnable([task]() { (*task)(); }));
  102. return task->get_future();
  103. }
  104. OtsClient::DeleteTagsOutcome OtsClient::deleteTags(const DeleteTagsRequest &request) const
  105. {
  106. auto endpointOutcome = endpointProvider_->getEndpoint();
  107. if (!endpointOutcome.isSuccess())
  108. return DeleteTagsOutcome(endpointOutcome.error());
  109. auto outcome = makeRequest(endpointOutcome.result(), request);
  110. if (outcome.isSuccess())
  111. return DeleteTagsOutcome(DeleteTagsResult(outcome.result()));
  112. else
  113. return DeleteTagsOutcome(outcome.error());
  114. }
  115. void OtsClient::deleteTagsAsync(const DeleteTagsRequest& request, const DeleteTagsAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  116. {
  117. auto fn = [this, request, handler, context]()
  118. {
  119. handler(this, request, deleteTags(request), context);
  120. };
  121. asyncExecute(new Runnable(fn));
  122. }
  123. OtsClient::DeleteTagsOutcomeCallable OtsClient::deleteTagsCallable(const DeleteTagsRequest &request) const
  124. {
  125. auto task = std::make_shared<std::packaged_task<DeleteTagsOutcome()>>(
  126. [this, request]()
  127. {
  128. return this->deleteTags(request);
  129. });
  130. asyncExecute(new Runnable([task]() { (*task)(); }));
  131. return task->get_future();
  132. }
  133. OtsClient::GetInstanceOutcome OtsClient::getInstance(const GetInstanceRequest &request) const
  134. {
  135. auto endpointOutcome = endpointProvider_->getEndpoint();
  136. if (!endpointOutcome.isSuccess())
  137. return GetInstanceOutcome(endpointOutcome.error());
  138. auto outcome = makeRequest(endpointOutcome.result(), request);
  139. if (outcome.isSuccess())
  140. return GetInstanceOutcome(GetInstanceResult(outcome.result()));
  141. else
  142. return GetInstanceOutcome(outcome.error());
  143. }
  144. void OtsClient::getInstanceAsync(const GetInstanceRequest& request, const GetInstanceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  145. {
  146. auto fn = [this, request, handler, context]()
  147. {
  148. handler(this, request, getInstance(request), context);
  149. };
  150. asyncExecute(new Runnable(fn));
  151. }
  152. OtsClient::GetInstanceOutcomeCallable OtsClient::getInstanceCallable(const GetInstanceRequest &request) const
  153. {
  154. auto task = std::make_shared<std::packaged_task<GetInstanceOutcome()>>(
  155. [this, request]()
  156. {
  157. return this->getInstance(request);
  158. });
  159. asyncExecute(new Runnable([task]() { (*task)(); }));
  160. return task->get_future();
  161. }
  162. OtsClient::InsertInstanceOutcome OtsClient::insertInstance(const InsertInstanceRequest &request) const
  163. {
  164. auto endpointOutcome = endpointProvider_->getEndpoint();
  165. if (!endpointOutcome.isSuccess())
  166. return InsertInstanceOutcome(endpointOutcome.error());
  167. auto outcome = makeRequest(endpointOutcome.result(), request);
  168. if (outcome.isSuccess())
  169. return InsertInstanceOutcome(InsertInstanceResult(outcome.result()));
  170. else
  171. return InsertInstanceOutcome(outcome.error());
  172. }
  173. void OtsClient::insertInstanceAsync(const InsertInstanceRequest& request, const InsertInstanceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  174. {
  175. auto fn = [this, request, handler, context]()
  176. {
  177. handler(this, request, insertInstance(request), context);
  178. };
  179. asyncExecute(new Runnable(fn));
  180. }
  181. OtsClient::InsertInstanceOutcomeCallable OtsClient::insertInstanceCallable(const InsertInstanceRequest &request) const
  182. {
  183. auto task = std::make_shared<std::packaged_task<InsertInstanceOutcome()>>(
  184. [this, request]()
  185. {
  186. return this->insertInstance(request);
  187. });
  188. asyncExecute(new Runnable([task]() { (*task)(); }));
  189. return task->get_future();
  190. }
  191. OtsClient::InsertTagsOutcome OtsClient::insertTags(const InsertTagsRequest &request) const
  192. {
  193. auto endpointOutcome = endpointProvider_->getEndpoint();
  194. if (!endpointOutcome.isSuccess())
  195. return InsertTagsOutcome(endpointOutcome.error());
  196. auto outcome = makeRequest(endpointOutcome.result(), request);
  197. if (outcome.isSuccess())
  198. return InsertTagsOutcome(InsertTagsResult(outcome.result()));
  199. else
  200. return InsertTagsOutcome(outcome.error());
  201. }
  202. void OtsClient::insertTagsAsync(const InsertTagsRequest& request, const InsertTagsAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  203. {
  204. auto fn = [this, request, handler, context]()
  205. {
  206. handler(this, request, insertTags(request), context);
  207. };
  208. asyncExecute(new Runnable(fn));
  209. }
  210. OtsClient::InsertTagsOutcomeCallable OtsClient::insertTagsCallable(const InsertTagsRequest &request) const
  211. {
  212. auto task = std::make_shared<std::packaged_task<InsertTagsOutcome()>>(
  213. [this, request]()
  214. {
  215. return this->insertTags(request);
  216. });
  217. asyncExecute(new Runnable([task]() { (*task)(); }));
  218. return task->get_future();
  219. }
  220. OtsClient::ListClusterTypeOutcome OtsClient::listClusterType(const ListClusterTypeRequest &request) const
  221. {
  222. auto endpointOutcome = endpointProvider_->getEndpoint();
  223. if (!endpointOutcome.isSuccess())
  224. return ListClusterTypeOutcome(endpointOutcome.error());
  225. auto outcome = makeRequest(endpointOutcome.result(), request);
  226. if (outcome.isSuccess())
  227. return ListClusterTypeOutcome(ListClusterTypeResult(outcome.result()));
  228. else
  229. return ListClusterTypeOutcome(outcome.error());
  230. }
  231. void OtsClient::listClusterTypeAsync(const ListClusterTypeRequest& request, const ListClusterTypeAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  232. {
  233. auto fn = [this, request, handler, context]()
  234. {
  235. handler(this, request, listClusterType(request), context);
  236. };
  237. asyncExecute(new Runnable(fn));
  238. }
  239. OtsClient::ListClusterTypeOutcomeCallable OtsClient::listClusterTypeCallable(const ListClusterTypeRequest &request) const
  240. {
  241. auto task = std::make_shared<std::packaged_task<ListClusterTypeOutcome()>>(
  242. [this, request]()
  243. {
  244. return this->listClusterType(request);
  245. });
  246. asyncExecute(new Runnable([task]() { (*task)(); }));
  247. return task->get_future();
  248. }
  249. OtsClient::ListInstanceOutcome OtsClient::listInstance(const ListInstanceRequest &request) const
  250. {
  251. auto endpointOutcome = endpointProvider_->getEndpoint();
  252. if (!endpointOutcome.isSuccess())
  253. return ListInstanceOutcome(endpointOutcome.error());
  254. auto outcome = makeRequest(endpointOutcome.result(), request);
  255. if (outcome.isSuccess())
  256. return ListInstanceOutcome(ListInstanceResult(outcome.result()));
  257. else
  258. return ListInstanceOutcome(outcome.error());
  259. }
  260. void OtsClient::listInstanceAsync(const ListInstanceRequest& request, const ListInstanceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  261. {
  262. auto fn = [this, request, handler, context]()
  263. {
  264. handler(this, request, listInstance(request), context);
  265. };
  266. asyncExecute(new Runnable(fn));
  267. }
  268. OtsClient::ListInstanceOutcomeCallable OtsClient::listInstanceCallable(const ListInstanceRequest &request) const
  269. {
  270. auto task = std::make_shared<std::packaged_task<ListInstanceOutcome()>>(
  271. [this, request]()
  272. {
  273. return this->listInstance(request);
  274. });
  275. asyncExecute(new Runnable([task]() { (*task)(); }));
  276. return task->get_future();
  277. }
  278. OtsClient::ListTagsOutcome OtsClient::listTags(const ListTagsRequest &request) const
  279. {
  280. auto endpointOutcome = endpointProvider_->getEndpoint();
  281. if (!endpointOutcome.isSuccess())
  282. return ListTagsOutcome(endpointOutcome.error());
  283. auto outcome = makeRequest(endpointOutcome.result(), request);
  284. if (outcome.isSuccess())
  285. return ListTagsOutcome(ListTagsResult(outcome.result()));
  286. else
  287. return ListTagsOutcome(outcome.error());
  288. }
  289. void OtsClient::listTagsAsync(const ListTagsRequest& request, const ListTagsAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  290. {
  291. auto fn = [this, request, handler, context]()
  292. {
  293. handler(this, request, listTags(request), context);
  294. };
  295. asyncExecute(new Runnable(fn));
  296. }
  297. OtsClient::ListTagsOutcomeCallable OtsClient::listTagsCallable(const ListTagsRequest &request) const
  298. {
  299. auto task = std::make_shared<std::packaged_task<ListTagsOutcome()>>(
  300. [this, request]()
  301. {
  302. return this->listTags(request);
  303. });
  304. asyncExecute(new Runnable([task]() { (*task)(); }));
  305. return task->get_future();
  306. }
  307. OtsClient::ListVpcInfoByInstanceOutcome OtsClient::listVpcInfoByInstance(const ListVpcInfoByInstanceRequest &request) const
  308. {
  309. auto endpointOutcome = endpointProvider_->getEndpoint();
  310. if (!endpointOutcome.isSuccess())
  311. return ListVpcInfoByInstanceOutcome(endpointOutcome.error());
  312. auto outcome = makeRequest(endpointOutcome.result(), request);
  313. if (outcome.isSuccess())
  314. return ListVpcInfoByInstanceOutcome(ListVpcInfoByInstanceResult(outcome.result()));
  315. else
  316. return ListVpcInfoByInstanceOutcome(outcome.error());
  317. }
  318. void OtsClient::listVpcInfoByInstanceAsync(const ListVpcInfoByInstanceRequest& request, const ListVpcInfoByInstanceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  319. {
  320. auto fn = [this, request, handler, context]()
  321. {
  322. handler(this, request, listVpcInfoByInstance(request), context);
  323. };
  324. asyncExecute(new Runnable(fn));
  325. }
  326. OtsClient::ListVpcInfoByInstanceOutcomeCallable OtsClient::listVpcInfoByInstanceCallable(const ListVpcInfoByInstanceRequest &request) const
  327. {
  328. auto task = std::make_shared<std::packaged_task<ListVpcInfoByInstanceOutcome()>>(
  329. [this, request]()
  330. {
  331. return this->listVpcInfoByInstance(request);
  332. });
  333. asyncExecute(new Runnable([task]() { (*task)(); }));
  334. return task->get_future();
  335. }
  336. OtsClient::ListVpcInfoByVpcOutcome OtsClient::listVpcInfoByVpc(const ListVpcInfoByVpcRequest &request) const
  337. {
  338. auto endpointOutcome = endpointProvider_->getEndpoint();
  339. if (!endpointOutcome.isSuccess())
  340. return ListVpcInfoByVpcOutcome(endpointOutcome.error());
  341. auto outcome = makeRequest(endpointOutcome.result(), request);
  342. if (outcome.isSuccess())
  343. return ListVpcInfoByVpcOutcome(ListVpcInfoByVpcResult(outcome.result()));
  344. else
  345. return ListVpcInfoByVpcOutcome(outcome.error());
  346. }
  347. void OtsClient::listVpcInfoByVpcAsync(const ListVpcInfoByVpcRequest& request, const ListVpcInfoByVpcAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  348. {
  349. auto fn = [this, request, handler, context]()
  350. {
  351. handler(this, request, listVpcInfoByVpc(request), context);
  352. };
  353. asyncExecute(new Runnable(fn));
  354. }
  355. OtsClient::ListVpcInfoByVpcOutcomeCallable OtsClient::listVpcInfoByVpcCallable(const ListVpcInfoByVpcRequest &request) const
  356. {
  357. auto task = std::make_shared<std::packaged_task<ListVpcInfoByVpcOutcome()>>(
  358. [this, request]()
  359. {
  360. return this->listVpcInfoByVpc(request);
  361. });
  362. asyncExecute(new Runnable([task]() { (*task)(); }));
  363. return task->get_future();
  364. }
  365. OtsClient::UnbindInstance2VpcOutcome OtsClient::unbindInstance2Vpc(const UnbindInstance2VpcRequest &request) const
  366. {
  367. auto endpointOutcome = endpointProvider_->getEndpoint();
  368. if (!endpointOutcome.isSuccess())
  369. return UnbindInstance2VpcOutcome(endpointOutcome.error());
  370. auto outcome = makeRequest(endpointOutcome.result(), request);
  371. if (outcome.isSuccess())
  372. return UnbindInstance2VpcOutcome(UnbindInstance2VpcResult(outcome.result()));
  373. else
  374. return UnbindInstance2VpcOutcome(outcome.error());
  375. }
  376. void OtsClient::unbindInstance2VpcAsync(const UnbindInstance2VpcRequest& request, const UnbindInstance2VpcAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  377. {
  378. auto fn = [this, request, handler, context]()
  379. {
  380. handler(this, request, unbindInstance2Vpc(request), context);
  381. };
  382. asyncExecute(new Runnable(fn));
  383. }
  384. OtsClient::UnbindInstance2VpcOutcomeCallable OtsClient::unbindInstance2VpcCallable(const UnbindInstance2VpcRequest &request) const
  385. {
  386. auto task = std::make_shared<std::packaged_task<UnbindInstance2VpcOutcome()>>(
  387. [this, request]()
  388. {
  389. return this->unbindInstance2Vpc(request);
  390. });
  391. asyncExecute(new Runnable([task]() { (*task)(); }));
  392. return task->get_future();
  393. }
  394. OtsClient::UpdateInstanceOutcome OtsClient::updateInstance(const UpdateInstanceRequest &request) const
  395. {
  396. auto endpointOutcome = endpointProvider_->getEndpoint();
  397. if (!endpointOutcome.isSuccess())
  398. return UpdateInstanceOutcome(endpointOutcome.error());
  399. auto outcome = makeRequest(endpointOutcome.result(), request);
  400. if (outcome.isSuccess())
  401. return UpdateInstanceOutcome(UpdateInstanceResult(outcome.result()));
  402. else
  403. return UpdateInstanceOutcome(outcome.error());
  404. }
  405. void OtsClient::updateInstanceAsync(const UpdateInstanceRequest& request, const UpdateInstanceAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
  406. {
  407. auto fn = [this, request, handler, context]()
  408. {
  409. handler(this, request, updateInstance(request), context);
  410. };
  411. asyncExecute(new Runnable(fn));
  412. }
  413. OtsClient::UpdateInstanceOutcomeCallable OtsClient::updateInstanceCallable(const UpdateInstanceRequest &request) const
  414. {
  415. auto task = std::make_shared<std::packaged_task<UpdateInstanceOutcome()>>(
  416. [this, request]()
  417. {
  418. return this->updateInstance(request);
  419. });
  420. asyncExecute(new Runnable([task]() { (*task)(); }));
  421. return task->get_future();
  422. }