1
0
Fork 0

small cleanup

This commit is contained in:
Jan Steemann 2013-09-11 14:21:54 +02:00
parent 1c4581c525
commit c22fd49d84
6 changed files with 40 additions and 196 deletions

View File

@ -111,19 +111,6 @@ string const& RestActionHandler::queue () const {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
HttpHandler::status_e RestActionHandler::execute () { HttpHandler::status_e RestActionHandler::execute () {
static LoggerData::Task const logDelete("ACTION [delete]");
static LoggerData::Task const logGet("ACTION [get]");
static LoggerData::Task const logHead("ACTION [head]");
static LoggerData::Task const logIllegal("ACTION [illegal]");
static LoggerData::Task const logOptions("ACTION [options]");
static LoggerData::Task const logPost("ACTION [post]");
static LoggerData::Task const logPut("ACTION [put]");
static LoggerData::Task const logPatch("ACTION [patch]");
LoggerData::Task const * task = &logIllegal;
bool res = false;
// need an action // need an action
if (_action == 0) { if (_action == 0) {
generateNotImplemented(_request->requestPath()); generateNotImplemented(_request->requestPath());
@ -140,24 +127,6 @@ HttpHandler::status_e RestActionHandler::execute () {
// extract the sub-request type // extract the sub-request type
HttpRequest::HttpRequestType type = _request->requestType(); HttpRequest::HttpRequestType type = _request->requestType();
// prepare logging
switch (type) {
case HttpRequest::HTTP_REQUEST_DELETE: task = &logDelete; break;
case HttpRequest::HTTP_REQUEST_GET: task = &logGet; break;
case HttpRequest::HTTP_REQUEST_POST: task = &logPost; break;
case HttpRequest::HTTP_REQUEST_PUT: task = &logPut; break;
case HttpRequest::HTTP_REQUEST_HEAD: task = &logHead; break;
case HttpRequest::HTTP_REQUEST_OPTIONS: task = &logOptions; break;
case HttpRequest::HTTP_REQUEST_PATCH: task = &logPatch; break;
case HttpRequest::HTTP_REQUEST_ILLEGAL: task = &logIllegal; break;
}
_timing << *task;
#ifdef TRI_ENABLE_LOGGER
// if ifdef is not used, the compiler will complain
LOGGER_REQUEST_IN_START_I(_timing, "");
#endif
// execute one of the HTTP methods // execute one of the HTTP methods
switch (type) { switch (type) {
case HttpRequest::HTTP_REQUEST_GET: case HttpRequest::HTTP_REQUEST_GET:
@ -167,19 +136,16 @@ HttpHandler::status_e RestActionHandler::execute () {
case HttpRequest::HTTP_REQUEST_HEAD: case HttpRequest::HTTP_REQUEST_HEAD:
case HttpRequest::HTTP_REQUEST_OPTIONS: case HttpRequest::HTTP_REQUEST_OPTIONS:
case HttpRequest::HTTP_REQUEST_PATCH: { case HttpRequest::HTTP_REQUEST_PATCH: {
res = executeAction(); executeAction();
break; break;
} }
default: default:
res = false;
generateNotImplemented("METHOD"); generateNotImplemented("METHOD");
break; break;
} }
} }
_timingResult = res ? RES_ERR : RES_OK;
// this handler is done // this handler is done
return HANDLER_DONE; return HANDLER_DONE;
} }

View File

@ -97,49 +97,17 @@ string const& RestDocumentHandler::queue () const {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
HttpHandler::status_e RestDocumentHandler::execute () { HttpHandler::status_e RestDocumentHandler::execute () {
// extract the sub-request type // extract the sub-request type
HttpRequest::HttpRequestType type = _request->requestType(); HttpRequest::HttpRequestType type = _request->requestType();
// prepare logging
static LoggerData::Task const logCreate(DOCUMENT_PATH + " [create]");
static LoggerData::Task const logRead(DOCUMENT_PATH + " [read]");
static LoggerData::Task const logUpdate(DOCUMENT_PATH + " [update]");
static LoggerData::Task const logDelete(DOCUMENT_PATH + " [delete]");
static LoggerData::Task const logHead(DOCUMENT_PATH + " [head]");
static LoggerData::Task const logOptions(DOCUMENT_PATH + " [options]");
static LoggerData::Task const logPatch(DOCUMENT_PATH + " [patch]");
static LoggerData::Task const logIllegal(DOCUMENT_PATH + " [illegal]");
LoggerData::Task const * task = &logCreate;
switch (type) {
case HttpRequest::HTTP_REQUEST_DELETE: task = &logDelete; break;
case HttpRequest::HTTP_REQUEST_GET: task = &logRead; break;
case HttpRequest::HTTP_REQUEST_HEAD: task = &logHead; break;
case HttpRequest::HTTP_REQUEST_ILLEGAL: task = &logIllegal; break;
case HttpRequest::HTTP_REQUEST_OPTIONS: task = &logOptions; break;
case HttpRequest::HTTP_REQUEST_POST: task = &logCreate; break;
case HttpRequest::HTTP_REQUEST_PUT: task = &logUpdate; break;
case HttpRequest::HTTP_REQUEST_PATCH: task = &logUpdate; break;
}
_timing << *task;
#ifdef TRI_ENABLE_LOGGER
// if logger is not activated, the compiler will complain, so enclose it in ifdef
LOGGER_REQUEST_IN_START_I(_timing, "");
#endif
// execute one of the CRUD methods // execute one of the CRUD methods
bool res = false;
switch (type) { switch (type) {
case HttpRequest::HTTP_REQUEST_DELETE: res = deleteDocument(); break; case HttpRequest::HTTP_REQUEST_DELETE: deleteDocument(); break;
case HttpRequest::HTTP_REQUEST_GET: res = readDocument(); break; case HttpRequest::HTTP_REQUEST_GET: readDocument(); break;
case HttpRequest::HTTP_REQUEST_HEAD: res = checkDocument(); break; case HttpRequest::HTTP_REQUEST_HEAD: checkDocument(); break;
case HttpRequest::HTTP_REQUEST_POST: res = createDocument(); break; case HttpRequest::HTTP_REQUEST_POST: createDocument(); break;
case HttpRequest::HTTP_REQUEST_PUT: res = replaceDocument(); break; case HttpRequest::HTTP_REQUEST_PUT: replaceDocument(); break;
case HttpRequest::HTTP_REQUEST_PATCH: res = updateDocument(); break; case HttpRequest::HTTP_REQUEST_PATCH: updateDocument(); break;
case HttpRequest::HTTP_REQUEST_ILLEGAL: case HttpRequest::HTTP_REQUEST_ILLEGAL:
default: { default: {
@ -148,8 +116,6 @@ HttpHandler::status_e RestDocumentHandler::execute () {
} }
} }
_timingResult = res ? RES_ERR : RES_OK;
// this handler is done // this handler is done
return HANDLER_DONE; return HANDLER_DONE;
} }

View File

@ -53,7 +53,8 @@ using namespace triagens::arango;
/// @brief constructor /// @brief constructor
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
RestEdgeHandler::RestEdgeHandler (HttpRequest* request, TRI_vocbase_t* vocbase) RestEdgeHandler::RestEdgeHandler (HttpRequest* request,
TRI_vocbase_t* vocbase)
: RestDocumentHandler(request, vocbase) { : RestDocumentHandler(request, vocbase) {
} }

View File

@ -54,7 +54,8 @@ using namespace triagens::arango;
/// @brief constructor /// @brief constructor
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
RestImportHandler::RestImportHandler (HttpRequest* request, TRI_vocbase_t* vocbase) RestImportHandler::RestImportHandler (HttpRequest* request,
TRI_vocbase_t* vocbase)
: RestVocbaseBaseHandler(request, vocbase) { : RestVocbaseBaseHandler(request, vocbase) {
} }
@ -94,30 +95,9 @@ string const& RestImportHandler::queue () const {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
HttpHandler::status_e RestImportHandler::execute () { HttpHandler::status_e RestImportHandler::execute () {
// extract the sub-request type // extract the sub-request type
HttpRequest::HttpRequestType type = _request->requestType(); HttpRequest::HttpRequestType type = _request->requestType();
// prepare logging
static LoggerData::Task const logCreate(DOCUMENT_IMPORT_PATH + " [create]");
static LoggerData::Task const logIllegal(DOCUMENT_IMPORT_PATH + " [illegal]");
LoggerData::Task const * task = &logCreate;
switch (type) {
case HttpRequest::HTTP_REQUEST_POST: task = &logCreate; break;
default: task = &logIllegal; break;
}
_timing << *task;
// if ifdef is not used, the compiler will complain
#ifdef TRI_ENABLE_LOGGER
LOGGER_REQUEST_IN_START_I(_timing, "");
#endif
bool res = false;
switch (type) { switch (type) {
case HttpRequest::HTTP_REQUEST_POST: { case HttpRequest::HTTP_REQUEST_POST: {
// extract the import type // extract the import type
@ -129,23 +109,20 @@ HttpHandler::status_e RestImportHandler::execute () {
documentType == "array" || documentType == "array" ||
documentType == "list" || documentType == "list" ||
documentType == "auto")) { documentType == "auto")) {
res = createFromJson(documentType); createFromJson(documentType);
} }
else { else {
// CSV // CSV
res = createFromKeyValueList(); createFromKeyValueList();
} }
break; break;
} }
default: default:
res = false;
generateNotImplemented("ILLEGAL " + DOCUMENT_IMPORT_PATH); generateNotImplemented("ILLEGAL " + DOCUMENT_IMPORT_PATH);
break; break;
} }
_timingResult = res ? RES_ERR : RES_OK;
// this handler is done // this handler is done
return HANDLER_DONE; return HANDLER_DONE;
} }

View File

@ -57,36 +57,12 @@ using namespace triagens::arango;
/// @{ /// @{
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief result RES-OK
////////////////////////////////////////////////////////////////////////////////
LoggerData::Extra const RestVocbaseBaseHandler::RES_OK;
////////////////////////////////////////////////////////////////////////////////
/// @brief result RES-ERR
////////////////////////////////////////////////////////////////////////////////
LoggerData::Extra const RestVocbaseBaseHandler::RES_ERR;
////////////////////////////////////////////////////////////////////////////////
/// @brief result RES-ERR
////////////////////////////////////////////////////////////////////////////////
LoggerData::Extra const RestVocbaseBaseHandler::RES_FAIL;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief batch path /// @brief batch path
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
string RestVocbaseBaseHandler::BATCH_PATH = "/_api/batch"; string RestVocbaseBaseHandler::BATCH_PATH = "/_api/batch";
////////////////////////////////////////////////////////////////////////////////
/// @brief collection path
////////////////////////////////////////////////////////////////////////////////
string RestVocbaseBaseHandler::COLLECTION_PATH = "/_api/collection";
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief document path /// @brief document path
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -137,21 +113,12 @@ string RestVocbaseBaseHandler::UPLOAD_PATH = "/_api/upload";
RestVocbaseBaseHandler::RestVocbaseBaseHandler (HttpRequest* request, RestVocbaseBaseHandler::RestVocbaseBaseHandler (HttpRequest* request,
TRI_vocbase_t* vocbase) TRI_vocbase_t* vocbase)
: RestBaseHandler(request), : RestBaseHandler(request),
_vocbase(vocbase), _context(static_cast<VocbaseContext*>(request->getRequestContext())),
_resolver(vocbase), _vocbase(_context->getVocbase()),
_timing(), _resolver(_vocbase) {
_timingResult(RES_FAIL) {
RequestContext* rc = request->getRequestContext(); // this is to ensure we have not forgotten anything
_context = static_cast<VocbaseContext*>(rc); assert(_vocbase == vocbase);
assert(_context != 0);
// overwrite vocbase. TODO FIXME: move into init list
_vocbase = _context->getVocbase();
assert(_vocbase != 0);
_resolver = _context->getVocbase();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -159,7 +126,6 @@ RestVocbaseBaseHandler::RestVocbaseBaseHandler (HttpRequest* request,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
RestVocbaseBaseHandler::~RestVocbaseBaseHandler () { RestVocbaseBaseHandler::~RestVocbaseBaseHandler () {
LOGGER_REQUEST_IN_END_I(_timing, _timingResult);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -421,7 +387,7 @@ void RestVocbaseBaseHandler::generateTransactionError (const string& collectionN
} }
else { else {
// collection name specified but collection not found // collection name specified but collection not found
generateError(HttpResponse::NOT_FOUND, res, "collection " + COLLECTION_PATH + "/" + collectionName + " not found"); generateError(HttpResponse::NOT_FOUND, res, "collection '" + collectionName + "' not found");
} }
return; return;

View File

@ -45,11 +45,12 @@
// --SECTION-- forward declarations // --SECTION-- forward declarations
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
extern "C" {
struct TRI_json_s;
struct TRI_primary_collection_s; struct TRI_primary_collection_s;
struct TRI_result_set_s;
struct TRI_vocbase_col_s; struct TRI_vocbase_col_s;
struct TRI_vocbase_s; struct TRI_vocbase_s;
struct TRI_json_s; }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// --SECTION-- class RestVocbaseBaseHandler // --SECTION-- class RestVocbaseBaseHandler
@ -80,36 +81,12 @@ namespace triagens {
public: public:
////////////////////////////////////////////////////////////////////////////////
/// @brief result RES-OK
////////////////////////////////////////////////////////////////////////////////
static basics::LoggerData::Extra const RES_OK;
////////////////////////////////////////////////////////////////////////////////
/// @brief result RES-ERR
////////////////////////////////////////////////////////////////////////////////
static basics::LoggerData::Extra const RES_ERR;
////////////////////////////////////////////////////////////////////////////////
/// @brief result RES-ERR
////////////////////////////////////////////////////////////////////////////////
static basics::LoggerData::Extra const RES_FAIL;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief batch path /// @brief batch path
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static string BATCH_PATH; static string BATCH_PATH;
////////////////////////////////////////////////////////////////////////////////
/// @brief collection path
////////////////////////////////////////////////////////////////////////////////
static string COLLECTION_PATH;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief document path /// @brief document path
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -155,7 +132,8 @@ namespace triagens {
/// @brief constructor /// @brief constructor
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
RestVocbaseBaseHandler (rest::HttpRequest* request, struct TRI_vocbase_s* vocbase); RestVocbaseBaseHandler (rest::HttpRequest*,
struct TRI_vocbase_s*);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief destructor /// @brief destructor
@ -314,7 +292,8 @@ namespace triagens {
/// @note @FA{header} must be lowercase. /// @note @FA{header} must be lowercase.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_voc_rid_t extractRevision (char const*, char const*); TRI_voc_rid_t extractRevision (char const*,
char const*);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief extracts the update policy /// @brief extracts the update policy
@ -347,7 +326,9 @@ namespace triagens {
/// @brief parses a document handle /// @brief parses a document handle
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int parseDocumentId (string const&, TRI_voc_cid_t&, TRI_voc_key_t&); int parseDocumentId (string const&,
TRI_voc_cid_t&,
TRI_voc_key_t&);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @} /// @}
@ -364,6 +345,12 @@ namespace triagens {
/// @{ /// @{
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief request context
////////////////////////////////////////////////////////////////////////////////
VocbaseContext* _context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief the vocbase /// @brief the vocbase
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -376,25 +363,6 @@ namespace triagens {
triagens::arango::CollectionNameResolver _resolver; triagens::arango::CollectionNameResolver _resolver;
////////////////////////////////////////////////////////////////////////////////
/// @brief timing data structure
////////////////////////////////////////////////////////////////////////////////
triagens::basics::LoggerTiming _timing;
////////////////////////////////////////////////////////////////////////////////
/// @brief timing result
////////////////////////////////////////////////////////////////////////////////
triagens::basics::LoggerData::Extra _timingResult;
////////////////////////////////////////////////////////////////////////////////
/// @brief timing result
////////////////////////////////////////////////////////////////////////////////
VocbaseContext* _context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @} /// @}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////