Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix response messages #118

Merged
merged 2 commits into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/PMGDQueryHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int PMGDQueryHandler::add_node(const protobufs::AddNode &cn,
{
long id = cn.identifier();
if (id >= 0 && _cached_nodes.find(id) != _cached_nodes.end()) {
set_response(response, PMGDCmdResponse::Error, "Reuse of _ref value\n");
set_response(response, PMGDCmdResponse::Error, "Reuse of _ref value");
return -1;
}

Expand Down Expand Up @@ -246,7 +246,7 @@ int PMGDQueryHandler::update_node(const protobufs::UpdateNode &un,

if (it == _cached_nodes.end()) {
if (!query) {
set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update\n");
set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update");
return -1;
}
else {
Expand All @@ -257,7 +257,7 @@ int PMGDQueryHandler::update_node(const protobufs::UpdateNode &un,
if (qn_id >= 0)
it = _cached_nodes.find(qn_id);
else {
set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update\n");
set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update");
return -1;
}
}
Expand Down Expand Up @@ -287,7 +287,7 @@ int PMGDQueryHandler::add_edge(const protobufs::AddEdge &ce,
response->set_node_edge(false);
long id = ce.identifier();
if (id >= 0 && _cached_edges.find(id) != _cached_edges.end()) {
set_response(response, PMGDCmdResponse::Error, "Reuse of _ref value\n");
set_response(response, PMGDCmdResponse::Error, "Reuse of _ref value");
return -1;
}

Expand Down Expand Up @@ -367,7 +367,7 @@ int PMGDQueryHandler::update_edge(const protobufs::UpdateEdge &ue,

if (it == _cached_edges.end()) {
if (!query) {
set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update\n");
set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update");
return -1;
}
else {
Expand All @@ -378,7 +378,7 @@ int PMGDQueryHandler::update_edge(const protobufs::UpdateEdge &ue,
if (qe_id >= 0)
it = _cached_edges.find(qe_id);
else {
set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update\n");
set_response(response, PMGDCmdResponse::Error, "Undefined _ref value used in update");
return -1;
}
}
Expand Down Expand Up @@ -451,7 +451,7 @@ int PMGDQueryHandler::query_node(const protobufs::QueryNode &qn,
long id = qn.identifier();
if (id >= 0 && _cached_nodes.find(id) != _cached_nodes.end()) {
set_response(response, PMGDCmdResponse::Error,
"Reuse of _ref value\n");
"Reuse of _ref value");
return -1;
}

Expand All @@ -462,15 +462,15 @@ int PMGDQueryHandler::query_node(const protobufs::QueryNode &qn,
if (link.nb_unique()) {
// TODO Add support for unique neighbors across iterators
set_response(response, PMGDCmdResponse::Error,
"Non-repeated neighbors not supported\n");
"Non-repeated neighbors not supported");
return -1;
}

long start_id = link.start_identifier();
auto start = _cached_nodes.find(start_id);
if (start == _cached_nodes.end()) {
set_response(response, PMGDCmdResponse::Error,
"Undefined _ref value used in link\n");
"Undefined _ref value used in link");
return -1;
}
start_ni = start->second;
Expand Down Expand Up @@ -499,7 +499,7 @@ int PMGDQueryHandler::query_node(const protobufs::QueryNode &qn,
: search.eval_nodes();
if (!bool(ni) && id >= 0) {
set_response(response, PMGDCmdResponse::Empty,
"Null search iterator\n");
"Null search iterator");
if (has_link)
start_ni->reset();
return -1;
Expand Down Expand Up @@ -528,7 +528,7 @@ int PMGDQueryHandler::query_node(const protobufs::QueryNode &qn,
tni->next();
if (bool(*tni)) { // Not unique and that is an error here.
set_response(response, PMGDCmdResponse::NotUnique,
"Query response not unique\n");
"Query response not unique");
if (has_link)
start_ni->reset();
delete tni;
Expand Down Expand Up @@ -572,14 +572,14 @@ int PMGDQueryHandler::query_edge(const protobufs::QueryEdge &qe,

if (qc.p_op() == protobufs::Or) {
set_response(response, PMGDCmdResponse::Error,
"Or operation not implemented\n");
"Or operation not implemented");
return -1;
}

long id = qe.identifier();
if (id >= 0 && _cached_edges.find(id) != _cached_edges.end()) {
set_response(response, PMGDCmdResponse::Error,
"Reuse of _ref value\n");
"Reuse of _ref value");
return -1;
}

Expand Down Expand Up @@ -615,7 +615,7 @@ int PMGDQueryHandler::query_edge(const protobufs::QueryEdge &qe,
EdgeIterator ei = PMGD::EdgeIterator(new NodeEdgeIteratorImpl(search, src_ni, dest_ni));
if (!bool(ei) && id >= 0) {
set_response(response, PMGDCmdResponse::Empty,
"Null search iterator\n");
"Null search iterator");
// Make sure the src and dest Node iterators are resettled.
if (src_ni != NULL) src_ni->reset();
if (dest_ni != NULL) dest_ni->reset();
Expand All @@ -642,7 +642,7 @@ int PMGDQueryHandler::query_edge(const protobufs::QueryEdge &qe,
tei->next();
if (bool(*tei)) { // Not unique and that is an error here.
set_response(response, PMGDCmdResponse::NotUnique,
"Query response not unique\n");
"Query response not unique");
delete tei;
if (src_ni != NULL) src_ni->reset();
if (dest_ni != NULL) dest_ni->reset();
Expand Down Expand Up @@ -818,7 +818,7 @@ void PMGDQueryHandler::build_results(Iterator &ni,
}
else {
set_response(response, PMGDCmdResponse::Error,
"Wrong first property for sum/average\n");
"Wrong first property for sum/average");
}
break;
}
Expand All @@ -832,7 +832,7 @@ void PMGDQueryHandler::build_results(Iterator &ni,
}
default:
set_response(response, PMGDCmdResponse::Error,
"Unknown operation type for query\n");
"Unknown operation type for query");
}
}

Expand Down
23 changes: 16 additions & 7 deletions src/QueryHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ void QueryHandler::process_query(protobufs::queryMessage& proto_query,
std::cerr << "End Failed Query: " << std::endl;
exception_error["info"] = error_msg.str();
exception_error["status"] = RSCommand::Error;
proto_res.set_json(fastWriter.write(exception_error));
Json::Value response;
response.append(exception_error);
proto_res.set_json(fastWriter.write(response));
};

try {
Expand Down Expand Up @@ -368,13 +370,20 @@ void QueryHandler::process_query(protobufs::queryMessage& proto_query,

Json::Value& tx_responses = pmgd_query.run();

if (tx_responses.size() != root.size()) { // error
cmd_current = "Transaction";
cmd_result = tx_responses;
cmd_result["info"] = "Failed PMGDTransaction";
if (!tx_responses.isArray() || tx_responses.size() != root.size()) {
Json::StyledWriter writer;
std::cerr << "PMGD Response:" << std::endl;
std::cerr << writer.write(tx_responses) << std::endl;

std::string tx_error_msg("Failed PMGD Transaction");
if (!tx_responses.isArray() && tx_responses.isMember("info")) {
tx_error_msg += ": " + tx_responses["info"].asString();
}

cmd_result["status"] = RSCommand::Error;
Json::StyledWriter w;
std::cerr << w.write(tx_responses);
cmd_result["info"] = tx_error_msg;

cmd_current = "Transaction";
error(cmd_result, cmd_current);
return;
}
Expand Down