Skip to content

Commit

Permalink
fix(interactive): Make sure admin service always return response in `…
Browse files Browse the repository at this point in the history
…application/json` (#3752)

- Make sure admin Service return response in `application/json` format
- Parse the gremlin port in service config, and return in
`service_status`.

see
[seastar-api-doc](https://docs.seastar.io/master/structseastar_1_1http_1_1reply.html#a0a03fbc0116a2832df3325605a5ba9e4)
zhanglei1949 authored Apr 26, 2024
1 parent b28ece8 commit fcde5b4
Showing 4 changed files with 43 additions and 7 deletions.
8 changes: 7 additions & 1 deletion flex/engines/http_server/actor/admin_actor.act.cc
Original file line number Diff line number Diff line change
@@ -339,6 +339,10 @@ seastar::future<admin_query_result> admin_actor::run_create_graph(
return seastar::make_ready_future<admin_query_result>(
gs::Result<seastar::sstring>(res_yaml.status()));
}
// set default value
if (!yaml["store_type"]) {
yaml["store_type"] = "mutable_csr";
}

auto parse_schema_res = gs::Schema::LoadFromYamlNode(res_yaml.value());
if (!parse_schema_res.ok()) {
@@ -980,7 +984,9 @@ seastar::future<admin_query_result> admin_actor::service_status(
nlohmann::json res;
if (query_port != 0) {
res["status"] = hqps_service.is_actors_running() ? "Running" : "Stopped";
res["query_port"] = query_port;
res["hqps_port"] = query_port;
res["bolt_port"] = hqps_service.get_service_config().bolt_port;
res["gremlin_port"] = hqps_service.get_service_config().gremlin_port;
if (running_graph_res.ok()) {
res["graph_id"] = running_graph_res.value();
} else {
6 changes: 4 additions & 2 deletions flex/engines/http_server/handler/admin_http_handler.cc
Original file line number Diff line number Diff line change
@@ -436,7 +436,8 @@ class admin_http_job_handler_impl : public seastar::httpd::handler_base {
} else if (method == "DELETE") {
if (!req->param.exists("job_id")) {
rep->set_status(seastar::httpd::reply::status_type::bad_request);
rep->write_body("application/json",
rep->set_content_type("application/json");
rep->write_body("json",
seastar::sstring("expect field 'job_id' in request"));
rep->done();
return seastar::make_ready_future<
@@ -451,7 +452,8 @@ class admin_http_job_handler_impl : public seastar::httpd::handler_base {
});
} else {
rep->set_status(seastar::httpd::reply::status_type::bad_request);
rep->write_body("application/json",
rep->set_content_type("application/json");
rep->write_body("json",
seastar::sstring("Unsupported method: ") + method);
rep->done();
return seastar::make_ready_future<std::unique_ptr<seastar::httpd::reply>>(
11 changes: 7 additions & 4 deletions flex/engines/http_server/handler/http_utils.cc
Original file line number Diff line number Diff line change
@@ -20,7 +20,8 @@ namespace server {
seastar::future<std::unique_ptr<seastar::httpd::reply>> new_bad_request_reply(
std::unique_ptr<seastar::httpd::reply> rep, const std::string& msg) {
rep->set_status(seastar::httpd::reply::status_type::bad_request);
rep->write_body("application/json", seastar::sstring(msg));
rep->set_content_type("application/json");
rep->write_body("json", seastar::sstring(msg));
rep->done();
return seastar::make_ready_future<std::unique_ptr<seastar::httpd::reply>>(
std::move(rep));
@@ -72,7 +73,8 @@ catch_exception_and_return_reply(std::unique_ptr<seastar::httpd::reply> rep,
} catch (std::exception& e) {
LOG(ERROR) << "Exception: " << e.what();
seastar::sstring what = e.what();
rep->write_body("application/json", std::move(what));
rep->set_content_type("application/json");
rep->write_body("json", std::move(what));
rep->set_status(seastar::httpd::reply::status_type::bad_request);
rep->done();
return seastar::make_ready_future<std::unique_ptr<seastar::httpd::reply>>(
@@ -91,10 +93,11 @@ return_reply_with_result(std::unique_ptr<seastar::httpd::reply> rep,
auto status_code =
status_code_to_http_code(result.content.status().error_code());
rep->set_status(status_code);
rep->set_content_type("application/json");
if (status_code == seastar::httpd::reply::status_type::ok) {
rep->write_body("application/json", std::move(result.content.value()));
rep->write_body("json", std::move(result.content.value()));
} else {
rep->write_body("application/json",
rep->write_body("json",
seastar::sstring(result.content.status().error_message()));
}
rep->done();
25 changes: 25 additions & 0 deletions flex/engines/http_server/service/hqps_service.h
Original file line number Diff line number Diff line change
@@ -39,9 +39,11 @@ struct ServiceConfig {
static constexpr const uint32_t DEFAULT_QUERY_PORT = 10000;
static constexpr const uint32_t DEFAULT_ADMIN_PORT = 7777;
static constexpr const uint32_t DEFAULT_BOLT_PORT = 7687;
static constexpr const uint32_t DEFAULT_GREMLIN_PORT = 8182;

// Those has default value
uint32_t bolt_port;
uint32_t gremlin_port;
uint32_t admin_port;
uint32_t query_port;
uint32_t shard_num;
@@ -195,6 +197,29 @@ struct convert<server::ServiceConfig> {
LOG(ERROR) << "Fail to find http_service configuration";
return false;
}

auto compiler_node = config["compiler"];
if (compiler_node) {
auto endpoint_node = compiler_node["endpoint"];
if (endpoint_node) {
auto bolt_node = endpoint_node["bolt_connector"];
if (bolt_node && bolt_node["port"] &&
bolt_node["disabled"].as<bool>() == false) {
service_config.bolt_port = bolt_node["port"].as<uint32_t>();
} else {
LOG(INFO) << "bolt_port not found, or disabled";
}
auto gremlin_node = endpoint_node["gremlin_connector"];
if (gremlin_node && gremlin_node["port"] &&
gremlin_node["disabled"].as<bool>() == false) {
service_config.gremlin_port = gremlin_node["port"].as<uint32_t>();
} else {
LOG(INFO) << "gremlin_port not found, use default value "
<< service_config.gremlin_port;
}
}
}

auto default_graph_node = config["default_graph"];
std::string default_graph;
if (default_graph_node) {

0 comments on commit fcde5b4

Please sign in to comment.