]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/migration/HttpStream.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / migration / HttpStream.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "librbd/migration/HttpStream.h"
5 #include "common/dout.h"
6 #include "common/errno.h"
7 #include "librbd/AsioEngine.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/asio/Utils.h"
10 #include "librbd/migration/HttpClient.h"
11 #include <boost/beast/http.hpp>
12
13 namespace librbd {
14 namespace migration {
15
16 namespace {
17
18 const std::string URL_KEY {"url"};
19
20 } // anonymous namespace
21
22 #define dout_subsys ceph_subsys_rbd
23 #undef dout_prefix
24 #define dout_prefix *_dout << "librbd::migration::HttpStream: " << this \
25 << " " << __func__ << ": "
26
27 template <typename I>
28 HttpStream<I>::HttpStream(I* image_ctx, const json_spirit::mObject& json_object)
29 : m_image_ctx(image_ctx), m_cct(image_ctx->cct),
30 m_asio_engine(image_ctx->asio_engine), m_json_object(json_object) {
31 }
32
33 template <typename I>
34 HttpStream<I>::~HttpStream() {
35 }
36
37 template <typename I>
38 void HttpStream<I>::open(Context* on_finish) {
39 auto& url_value = m_json_object[URL_KEY];
40 if (url_value.type() != json_spirit::str_type) {
41 lderr(m_cct) << "failed to locate '" << URL_KEY << "' key" << dendl;
42 on_finish->complete(-EINVAL);
43 return;
44 }
45
46 m_url = url_value.get_str();
47 ldout(m_cct, 10) << "url=" << m_url << dendl;
48
49 m_http_client.reset(HttpClient<I>::create(m_image_ctx, m_url));
50 m_http_client->open(on_finish);
51 }
52
53 template <typename I>
54 void HttpStream<I>::close(Context* on_finish) {
55 ldout(m_cct, 10) << dendl;
56
57 if (!m_http_client) {
58 on_finish->complete(0);
59 return;
60 }
61
62 m_http_client->close(on_finish);
63 }
64
65 template <typename I>
66 void HttpStream<I>::get_size(uint64_t* size, Context* on_finish) {
67 ldout(m_cct, 10) << dendl;
68
69 m_http_client->get_size(size, on_finish);
70 }
71
72 template <typename I>
73 void HttpStream<I>::read(io::Extents&& byte_extents, bufferlist* data,
74 Context* on_finish) {
75 ldout(m_cct, 20) << "byte_extents=" << byte_extents << dendl;
76
77 m_http_client->read(std::move(byte_extents), data, on_finish);
78 }
79
80 } // namespace migration
81 } // namespace librbd
82
83 template class librbd::migration::HttpStream<librbd::ImageCtx>;