This adds the API to urchin, all API related files will be placed under the api directory. The API server uses a context object to access global parameters, typically the different servers themselves. After this patch the api-doc will be available, though empty under: http://localhost:10000/api-doc Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
68 lines
2.8 KiB
C++
68 lines
2.8 KiB
C++
/*
|
|
* Copyright 2014 Cloudius Systems
|
|
*/
|
|
|
|
|
|
#include "database.hh"
|
|
#include "core/app-template.hh"
|
|
#include "core/distributed.hh"
|
|
#include "thrift/server.hh"
|
|
#include "transport/server.hh"
|
|
#include "http/httpd.hh"
|
|
#include "api/api.hh"
|
|
|
|
namespace bpo = boost::program_options;
|
|
|
|
int main(int ac, char** av) {
|
|
app_template app;
|
|
app.add_options()
|
|
("cql-port", bpo::value<uint16_t>()->default_value(9042), "CQL port")
|
|
("thrift-port", bpo::value<uint16_t>()->default_value(9160), "Thrift port")
|
|
("api-port", bpo::value<uint16_t>()->default_value(10000), "Http Rest API port")
|
|
("datadir", bpo::value<std::string>()->default_value("/var/lib/cassandra/data"), "data directory");
|
|
|
|
auto server = std::make_unique<distributed<thrift_server>>();
|
|
distributed<database> db;
|
|
distributed<cql3::query_processor> qp;
|
|
service::storage_proxy proxy{db};
|
|
api::http_context ctx;
|
|
|
|
return app.run(ac, av, [&] {
|
|
auto&& config = app.configuration();
|
|
uint16_t thrift_port = config["thrift-port"].as<uint16_t>();
|
|
uint16_t cql_port = config["cql-port"].as<uint16_t>();
|
|
sstring datadir = config["datadir"].as<std::string>();
|
|
uint16_t api_port = config["api-port"].as<uint16_t>();
|
|
|
|
return db.start().then([datadir, &db] {
|
|
engine().at_exit([&db] { return db.stop(); });
|
|
return db.invoke_on_all(&database::init_from_data_directory, datadir);
|
|
}).then([&db, &proxy, &qp] {
|
|
return qp.start(std::ref(proxy), std::ref(db)).then([&qp] {
|
|
engine().at_exit([&qp] { return qp.stop(); });
|
|
});
|
|
}).then([&db, &proxy, &qp, cql_port, thrift_port] {
|
|
auto cserver = new distributed<cql_server>;
|
|
cserver->start(std::ref(proxy), std::ref(qp)).then([server = std::move(cserver), cql_port] () mutable {
|
|
server->invoke_on_all(&cql_server::listen, ipv4_addr{cql_port});
|
|
}).then([cql_port] {
|
|
std::cout << "CQL server listening on port " << cql_port << " ...\n";
|
|
});
|
|
auto tserver = new distributed<thrift_server>;
|
|
tserver->start(std::ref(db)).then([server = std::move(tserver), thrift_port] () mutable {
|
|
server->invoke_on_all(&thrift_server::listen, ipv4_addr{thrift_port});
|
|
}).then([thrift_port] {
|
|
std::cout << "Thrift server listening on port " << thrift_port << " ...\n";
|
|
});
|
|
}).then([&db, api_port, &ctx]{
|
|
ctx.http_server.start().then([api_port, &ctx] {
|
|
return set_server(ctx);
|
|
}).then([&ctx, api_port] {
|
|
ctx.http_server.listen(api_port);
|
|
}).then([api_port] {
|
|
std::cout << "Seastar HTTP server listening on port " << api_port << " ...\n";
|
|
});
|
|
}).or_terminate();
|
|
});
|
|
}
|