Extract HTTP client functions from osd_t
parent
a61ede9951
commit
6202260018
6
Makefile
6
Makefile
|
@ -30,7 +30,7 @@ libfio_blockstore.so: ./libblockstore.so fio_engine.cpp json11.o
|
||||||
g++ $(CXXFLAGS) -shared -o libfio_blockstore.so fio_engine.cpp json11.o ./libblockstore.so -ltcmalloc_minimal -luring
|
g++ $(CXXFLAGS) -shared -o libfio_blockstore.so fio_engine.cpp json11.o ./libblockstore.so -ltcmalloc_minimal -luring
|
||||||
|
|
||||||
OSD_OBJS := osd.o osd_secondary.o osd_receive.o osd_send.o osd_peering.o osd_flush.o osd_peering_pg.o \
|
OSD_OBJS := osd.o osd_secondary.o osd_receive.o osd_send.o osd_peering.o osd_flush.o osd_peering_pg.o \
|
||||||
osd_primary.o osd_primary_subops.o osd_cluster.o osd_http.o osd_rmw.o json11.o timerfd_interval.o base64.o timerfd_manager.o
|
osd_primary.o osd_primary_subops.o osd_cluster.o http_client.o osd_rmw.o json11.o timerfd_interval.o base64.o timerfd_manager.o
|
||||||
base64.o: base64.cpp base64.h
|
base64.o: base64.cpp base64.h
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
osd_secondary.o: osd_secondary.cpp osd.h osd_ops.h ringloop.h
|
osd_secondary.o: osd_secondary.cpp osd.h osd_ops.h ringloop.h
|
||||||
|
@ -43,7 +43,7 @@ osd_peering.o: osd_peering.cpp osd.h osd_ops.h osd_peering_pg.h ringloop.h
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
osd_cluster.o: osd_cluster.cpp osd.h osd_ops.h ringloop.h
|
osd_cluster.o: osd_cluster.cpp osd.h osd_ops.h ringloop.h
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
osd_http.o: osd_http.cpp osd_http.h osd.h osd_ops.h ringloop.h
|
http_client.o: http_client.cpp http_client.h osd.h osd_ops.h ringloop.h
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
osd_flush.o: osd_flush.cpp osd.h osd_ops.h osd_peering_pg.h ringloop.h
|
osd_flush.o: osd_flush.cpp osd.h osd_ops.h osd_peering_pg.h ringloop.h
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
|
@ -57,7 +57,7 @@ osd_primary.o: osd_primary.cpp osd_primary.h osd_rmw.h osd.h osd_ops.h osd_peeri
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
osd_primary_subops.o: osd_primary_subops.cpp osd_primary.h osd_rmw.h osd.h osd_ops.h osd_peering_pg.h xor.h ringloop.h
|
osd_primary_subops.o: osd_primary_subops.cpp osd_primary.h osd_rmw.h osd.h osd_ops.h osd_peering_pg.h xor.h ringloop.h
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
osd.o: osd.cpp osd.h osd_http.h osd_ops.h osd_peering_pg.h ringloop.h
|
osd.o: osd.cpp osd.h http_client.h osd_ops.h osd_peering_pg.h ringloop.h
|
||||||
g++ $(CXXFLAGS) -c -o $@ $<
|
g++ $(CXXFLAGS) -c -o $@ $<
|
||||||
osd: ./libblockstore.so osd_main.cpp osd.h osd_ops.h $(OSD_OBJS)
|
osd: ./libblockstore.so osd_main.cpp osd.h osd_ops.h $(OSD_OBJS)
|
||||||
g++ $(CXXFLAGS) -o osd osd_main.cpp $(OSD_OBJS) ./libblockstore.so -ltcmalloc_minimal -luring
|
g++ $(CXXFLAGS) -o osd osd_main.cpp $(OSD_OBJS) ./libblockstore.so -ltcmalloc_minimal -luring
|
||||||
|
|
|
@ -2,13 +2,17 @@
|
||||||
#include <sys/epoll.h>
|
#include <sys/epoll.h>
|
||||||
|
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "osd.h"
|
|
||||||
#include "json11/json11.hpp"
|
#include "json11/json11.hpp"
|
||||||
#include "osd_http.h"
|
#include "http_client.h"
|
||||||
|
#include "timerfd_manager.h"
|
||||||
|
|
||||||
#define READ_BUFFER_SIZE 9000
|
#define READ_BUFFER_SIZE 9000
|
||||||
|
|
||||||
|
@ -64,8 +68,7 @@ struct http_co_t
|
||||||
|
|
||||||
#define DEFAULT_TIMEOUT 5000
|
#define DEFAULT_TIMEOUT 5000
|
||||||
|
|
||||||
// FIXME: Remove osd_t dependency from here
|
void http_request(timerfd_manager_t *tfd, const std::string & host, const std::string & request,
|
||||||
void osd_t::http_request(const std::string & host, const std::string & request,
|
|
||||||
const http_options_t & options, std::function<void(const http_response_t *response)> callback)
|
const http_options_t & options, std::function<void(const http_response_t *response)> callback)
|
||||||
{
|
{
|
||||||
http_co_t *handler = new http_co_t();
|
http_co_t *handler = new http_co_t();
|
||||||
|
@ -79,10 +82,10 @@ void osd_t::http_request(const std::string & host, const std::string & request,
|
||||||
handler->start_connection();
|
handler->start_connection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void osd_t::http_request_json(const std::string & host, const std::string & request,
|
void http_request_json(timerfd_manager_t *tfd, const std::string & host, const std::string & request,
|
||||||
int timeout, std::function<void(std::string, json11::Json r)> callback)
|
int timeout, std::function<void(std::string, json11::Json r)> callback)
|
||||||
{
|
{
|
||||||
http_request(host, request, { .timeout = timeout }, [this, callback](const http_response_t* res)
|
http_request(tfd, host, request, { .timeout = timeout }, [callback](const http_response_t* res)
|
||||||
{
|
{
|
||||||
if (res->error_code != 0)
|
if (res->error_code != 0)
|
||||||
{
|
{
|
||||||
|
@ -105,7 +108,7 @@ void osd_t::http_request_json(const std::string & host, const std::string & requ
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
websocket_t* osd_t::open_websocket(const std::string & host, const std::string & path,
|
websocket_t* open_websocket(timerfd_manager_t *tfd, const std::string & host, const std::string & path,
|
||||||
int timeout, std::function<void(const http_response_t *msg)> callback)
|
int timeout, std::function<void(const http_response_t *msg)> callback)
|
||||||
{
|
{
|
||||||
std::string request = "GET "+path+" HTTP/1.1\r\n"
|
std::string request = "GET "+path+" HTTP/1.1\r\n"
|
|
@ -2,6 +2,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <functional>
|
||||||
|
#include "json11/json11.hpp"
|
||||||
|
|
||||||
#define WS_CONTINUATION 0
|
#define WS_CONTINUATION 0
|
||||||
#define WS_TEXT 1
|
#define WS_TEXT 1
|
||||||
|
@ -10,6 +12,8 @@
|
||||||
#define WS_PING 9
|
#define WS_PING 9
|
||||||
#define WS_PONG 10
|
#define WS_PONG 10
|
||||||
|
|
||||||
|
class timerfd_manager_t;
|
||||||
|
|
||||||
struct http_options_t
|
struct http_options_t
|
||||||
{
|
{
|
||||||
int timeout;
|
int timeout;
|
||||||
|
@ -37,5 +41,16 @@ struct websocket_t
|
||||||
};
|
};
|
||||||
|
|
||||||
void parse_http_headers(std::string & res, http_response_t *parsed);
|
void parse_http_headers(std::string & res, http_response_t *parsed);
|
||||||
|
|
||||||
std::vector<std::string> getifaddr_list(bool include_v6 = false);
|
std::vector<std::string> getifaddr_list(bool include_v6 = false);
|
||||||
|
|
||||||
uint64_t stoull_full(const std::string & str, int base = 10);
|
uint64_t stoull_full(const std::string & str, int base = 10);
|
||||||
|
|
||||||
|
void http_request(timerfd_manager_t *tfd, const std::string & host, const std::string & request,
|
||||||
|
const http_options_t & options, std::function<void(const http_response_t *response)> callback);
|
||||||
|
|
||||||
|
void http_request_json(timerfd_manager_t *tfd, const std::string & host, const std::string & request,
|
||||||
|
int timeout, std::function<void(std::string, json11::Json r)> callback);
|
||||||
|
|
||||||
|
websocket_t* open_websocket(timerfd_manager_t *tfd, const std::string & host, const std::string & path,
|
||||||
|
int timeout, std::function<void(const http_response_t *msg)> callback);
|
1
osd.cpp
1
osd.cpp
|
@ -6,7 +6,6 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include "osd.h"
|
#include "osd.h"
|
||||||
#include "osd_http.h"
|
|
||||||
|
|
||||||
const char* osd_op_names[] = {
|
const char* osd_op_names[] = {
|
||||||
"",
|
"",
|
||||||
|
|
8
osd.h
8
osd.h
|
@ -18,7 +18,7 @@
|
||||||
#include "timerfd_manager.h"
|
#include "timerfd_manager.h"
|
||||||
#include "osd_ops.h"
|
#include "osd_ops.h"
|
||||||
#include "osd_peering_pg.h"
|
#include "osd_peering_pg.h"
|
||||||
#include "osd_http.h"
|
#include "http_client.h"
|
||||||
#include "json11/json11.hpp"
|
#include "json11/json11.hpp"
|
||||||
|
|
||||||
#define OSD_OP_IN 0
|
#define OSD_OP_IN 0
|
||||||
|
@ -294,12 +294,6 @@ class osd_t
|
||||||
uint64_t recovery_stat_bytes[2][2] = { 0 };
|
uint64_t recovery_stat_bytes[2][2] = { 0 };
|
||||||
|
|
||||||
// cluster connection
|
// cluster connection
|
||||||
void http_request(const std::string & host, const std::string & request,
|
|
||||||
const http_options_t & options, std::function<void(const http_response_t *response)> callback);
|
|
||||||
void http_request_json(const std::string & host, const std::string & request, int timeout,
|
|
||||||
std::function<void(std::string, json11::Json data)> callback);
|
|
||||||
websocket_t* open_websocket(const std::string & host, const std::string & path, int timeout,
|
|
||||||
std::function<void(const http_response_t *msg)> callback);
|
|
||||||
void etcd_call(std::string api, json11::Json payload, int timeout, std::function<void(std::string, json11::Json)> callback);
|
void etcd_call(std::string api, json11::Json payload, int timeout, std::function<void(std::string, json11::Json)> callback);
|
||||||
void etcd_txn(json11::Json txn, int timeout, std::function<void(std::string, json11::Json)> callback);
|
void etcd_txn(json11::Json txn, int timeout, std::function<void(std::string, json11::Json)> callback);
|
||||||
json_kv_t parse_etcd_kv(const json11::Json & kv_json);
|
json_kv_t parse_etcd_kv(const json11::Json & kv_json);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "osd.h"
|
#include "osd.h"
|
||||||
#include "osd_http.h"
|
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
|
|
||||||
#define ETCD_CONFIG_WATCH_ID 1
|
#define ETCD_CONFIG_WATCH_ID 1
|
||||||
|
@ -39,7 +38,7 @@ void osd_t::etcd_call(std::string api, json11::Json payload, int timeout, std::f
|
||||||
"Content-Length: "+std::to_string(req.size())+"\r\n"
|
"Content-Length: "+std::to_string(req.size())+"\r\n"
|
||||||
"Connection: close\r\n"
|
"Connection: close\r\n"
|
||||||
"\r\n"+req;
|
"\r\n"+req;
|
||||||
http_request_json(etcd_address, req, timeout, callback);
|
http_request_json(tfd, etcd_address, req, timeout, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Startup sequence:
|
// Startup sequence:
|
||||||
|
@ -244,7 +243,7 @@ void osd_t::report_statistics()
|
||||||
void osd_t::start_etcd_watcher()
|
void osd_t::start_etcd_watcher()
|
||||||
{
|
{
|
||||||
etcd_watches_initialised = 0;
|
etcd_watches_initialised = 0;
|
||||||
etcd_watch_ws = open_websocket(etcd_address, etcd_api_path+"/watch", ETCD_SLOW_TIMEOUT, [this](const http_response_t *msg)
|
etcd_watch_ws = open_websocket(tfd, etcd_address, etcd_api_path+"/watch", ETCD_SLOW_TIMEOUT, [this](const http_response_t *msg)
|
||||||
{
|
{
|
||||||
if (msg->body.length())
|
if (msg->body.length())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue