Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / rgw / rgw_loadgen.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_RGW_LOADGEN_H
5 #define CEPH_RGW_LOADGEN_H
6
7 #include <map>
8 #include <string>
9
10 #include "rgw_client_io.h"
11
12
13 struct RGWLoadGenRequestEnv {
14   int port;
15   uint64_t content_length;
16   std::string content_type;
17   std::string request_method;
18   std::string uri;
19   std::string query_string;
20   std::string date_str;
21
22   std::map<std::string, std::string> headers;
23
24   RGWLoadGenRequestEnv()
25     : port(0),
26       content_length(0) {
27   }
28
29   void set_date(utime_t& tm);
30   int sign(RGWAccessKey& access_key);
31 };
32
33 /* XXX does RGWLoadGenIO actually want to perform stream/HTTP I/O,
34  * or (e.g) are these NOOPs? */
35 class RGWLoadGenIO : public rgw::io::RestfulClient
36 {
37   uint64_t left_to_read;
38   RGWLoadGenRequestEnv* req;
39   RGWEnv env;
40
41   void init_env(CephContext *cct) override;
42   size_t read_data(char *buf, size_t len);
43   size_t write_data(const char *buf, size_t len);
44
45 public:
46   explicit RGWLoadGenIO(RGWLoadGenRequestEnv* const req)
47     : left_to_read(0),
48       req(req) {
49   }
50
51   size_t send_status(int status, const char *status_name) override;
52   size_t send_100_continue() override;
53   size_t send_header(const boost::string_ref& name,
54                      const boost::string_ref& value) override;
55   size_t complete_header() override;
56   size_t send_content_length(uint64_t len) override;
57
58   size_t recv_body(char* buf, size_t max) override {
59     return read_data(buf, max);
60   }
61
62   size_t send_body(const char* buf, size_t len) override {
63     return write_data(buf, len);
64   }
65
66   void flush() override;
67
68   RGWEnv& get_env() noexcept override {
69     return env;
70   }
71
72   size_t complete_request() override;
73 };
74
75 #endif