]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/migration/HttpStream.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / migration / HttpStream.cc
CommitLineData
f67539c2
TL
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
13namespace librbd {
14namespace migration {
15
16namespace {
17
18const 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
27template <typename I>
28HttpStream<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
33template <typename I>
34HttpStream<I>::~HttpStream() {
35}
36
37template <typename I>
38void 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
53template <typename I>
54void 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
65template <typename I>
66void 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
72template <typename I>
73void 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
83template class librbd::migration::HttpStream<librbd::ImageCtx>;