forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StatusHandler.cpp
75 lines (60 loc) · 2.08 KB
/
StatusHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Copyright (c) 2019 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
#include "webservice/StatusHandler.h"
#include <proxygen/httpserver/RequestHandler.h>
#include <proxygen/lib/http/ProxygenErrorEnum.h>
#include <proxygen/httpserver/ResponseBuilder.h>
namespace nebula {
using proxygen::HTTPMessage;
using proxygen::HTTPMethod;
using proxygen::ProxygenError;
using proxygen::UpgradeProtocol;
using proxygen::ResponseBuilder;
void StatusHandler::onRequest(std::unique_ptr<HTTPMessage> headers) noexcept {
if (headers->getMethod().value() != HTTPMethod::GET) {
// Unsupported method
err_ = HttpCode::E_UNSUPPORTED_METHOD;
return;
}
}
void StatusHandler::onBody(std::unique_ptr<folly::IOBuf>) noexcept {
// Do nothing, we only support GET
}
void StatusHandler::onEOM() noexcept {
switch (err_) {
case HttpCode::E_UNSUPPORTED_METHOD:
ResponseBuilder(downstream_)
.status(WebServiceUtils::to(HttpStatusCode::METHOD_NOT_ALLOWED),
WebServiceUtils::toString(HttpStatusCode::METHOD_NOT_ALLOWED))
.sendWithEOM();
return;
default:
break;
}
folly::dynamic vals = getStatus();
ResponseBuilder(downstream_)
.status(WebServiceUtils::to(HttpStatusCode::OK),
WebServiceUtils::toString(HttpStatusCode::OK))
.body(folly::toJson(vals))
.sendWithEOM();
}
void StatusHandler::onUpgrade(UpgradeProtocol) noexcept {
// Do nothing
}
void StatusHandler::requestComplete() noexcept {
delete this;
}
void StatusHandler::onError(ProxygenError error) noexcept {
LOG(ERROR) << "Web service StorageHttpHandler got error: "
<< proxygen::getErrorString(error);
}
folly::dynamic StatusHandler::getStatus() {
folly::dynamic json = folly::dynamic::object();
json["status"] = "running";
json["git_info_sha"] = NEBULA_STRINGIFY(GIT_INFO_SHA);
return json;
}
} // namespace nebula