Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.
Open
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
6 changes: 6 additions & 0 deletions conf/settings-default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ location= "tcp:127.0.0.1:10200" # The connection string for the R-Operator to us

[uploader]
directory="uploader" # The name of the directory where the uploader stores the files

[log]
logtofile=false # If logs should be written to file instead of error stream
#logfilelocation="" # Location to store the logs
logfilelevel="DEBUG" # The maximum level to be logged to file
cgilogfilename="gci_logs.txt" # The name for CGI log file, that is shared between program instances.
30 changes: 26 additions & 4 deletions src/cgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ JPEG32: 120703 (90%)
* A thread function that handles fcgi request
*/
void fcgiThread(int fd) {
FCGX_Init();
std::stringstream id_stream;
id_stream << std::this_thread::get_id();
std::string thread_id(id_stream.str());
Log::debug("Start of thread: " + thread_id);

FCGX_Init();

FCGX_Request request;

Expand All @@ -54,14 +59,26 @@ void fcgiThread(int fd) {
fcgi_streambuf streambuf_in(request.in);
fcgi_streambuf streambuf_out(request.out);
fcgi_streambuf streambuf_err(request.err);

Log::setThreadRequestId(request.requestId);
char * ip_ptr = FCGX_GetParam("REMOTE_ADDR", request.envp);
std::string ip = ip_ptr != nullptr ? ip_ptr : "";
Log::debug(concat("New request ", request.requestId, " from ip ", ip, ", on thread ", thread_id));
HTTPService::run(&streambuf_in, &streambuf_out, &streambuf_err, request);
Log::debug(concat("Finished request ", request.requestId));
}
Log::debug("End of thread: " + thread_id);
}

int main() {
Configuration::loadFromDefaultPaths();
Log::off();
Log::streamAndMemoryOff();

const bool isCgiMode = getenv("FCGI_WEB_SERVER_ADDRS") == nullptr;

if(Configuration::get<bool>("log.logtofile")){
Log::logToFile(isCgiMode);
Log::logRequestId(true);
}

/*
* Initialize Cache
Expand Down Expand Up @@ -107,9 +124,13 @@ int main() {
FeatureCollectionDB::initFromConfiguration();


if (getenv("FCGI_WEB_SERVER_ADDRS") == nullptr) {
if (isCgiMode) {
// CGI mode
long time_id = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
Log::setThreadRequestId(time_id); //time as request id, to differentiate the requests
Log::debug("New CGI request.");
HTTPService::run(std::cin.rdbuf(), std::cout.rdbuf(), std::cerr.rdbuf());
Log::debug("Finished Request.");
}
else {
// FCGI mode
Expand All @@ -129,4 +150,5 @@ int main() {
threads[i].join();
}
}
Log::fileOff();
}
3 changes: 3 additions & 0 deletions src/mapping_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,9 @@ int main(int argc, char *argv[]) {
NopCacheManager cm;
CacheManager::init(&cm);

if(Configuration::get<bool>("log.logtofile")){
Log::logToFile(false);
}
Log::logToStream(Log::LogLevel::WARN, &std::cerr);

const char *command = argv[1];
Expand Down
2 changes: 2 additions & 0 deletions src/services/artifact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "util/exceptions.h"
#include "util/curl.h"
#include "util/timeparser.h"
#include "util/log.h"

#include <cstring>
#include <sstream>
Expand Down Expand Up @@ -62,6 +63,7 @@ void ArtifactService::run() {

auto session = UserDB::loadSession(params.get("sessiontoken"));
auto user = session->getUser();
Log::debug("User: " + user.getUserIDString());

if(request == "create") {
std::string type = params.get("type");
Expand Down
3 changes: 2 additions & 1 deletion src/services/featurecollectiondb.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

#include "datatypes/plot.h"
#include "operators/operator.h"

#include "services/ogcservice.h"
#include "featurecollectiondb/featurecollectiondb.h"
#include "util/enumconverter.h"
#include "util/log.h"

static const std::vector< std::pair<Query::ResultType, std::string> > featureTypeMap = {
std::make_pair(Query::ResultType::POINTS, "points"),
Expand Down Expand Up @@ -80,6 +80,7 @@ Json::Value FeatureCollectionDBService::metaDataToJson(const FeatureCollectionDB
void FeatureCollectionDBService::run() {
auto session = UserDB::loadSession(params.get("sessiontoken"));
auto& user = session->getUser();
Log::debug("User: " + user.getUserIDString());

if(!FeatureCollectionDB::isAvailable()){
throw SourceException("FeatureCollectionDB is not available.");
Expand Down
21 changes: 19 additions & 2 deletions src/services/httpservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ void HTTPService::run(std::streambuf *in, std::streambuf *out, std::streambuf *e
std::ostream error(err);
HTTPResponseStream response(out);

//read query input to string and log it. reset input istream position to the beginning afterwards.
std::string query_string((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
input.seekg(0, std::ios_base::beg);
Log::debug(query_string);

Log::logToStream(Log::LogLevel::WARN, &error);
Log::logToMemory(Log::LogLevel::INFO);
try {
Expand All @@ -57,21 +62,24 @@ void HTTPService::run(std::streambuf *in, std::streambuf *out, std::streambuf *e
auto servicename = params.get("service");
auto service = HTTPService::getRegisteredService(servicename, params, response, error);

Log::debug("Running new service: " + servicename);

service->run();
}
catch(const MappingException &e){
catchExceptions(response, e);
}
catch (const std::exception &e) {
error << "Request failed with an exception: " << e.what() << "\n";
Log::debug(e.what());
if (Configuration::get<bool>("global.debug", false)) {
response.send500(concat("invalid request: ", e.what()));
} else {
response.send500("invalid request");
}

}
Log::off();
Log::streamAndMemoryOff();
}

/**
Expand All @@ -82,6 +90,11 @@ void HTTPService::run(std::streambuf *in, std::streambuf *out, std::streambuf *e
std::ostream error(err);
HTTPResponseStream response(out);

//read query input to string and log it. reset input istream position to the beginning afterwards.
std::string query_string((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
input.seekg(0, std::ios_base::beg);
Log::debug(query_string);

Log::logToStream(Log::LogLevel::WARN, &error);
Log::logToMemory(Log::LogLevel::INFO);
try {
Expand All @@ -93,20 +106,23 @@ void HTTPService::run(std::streambuf *in, std::streambuf *out, std::streambuf *e
auto servicename = params.get("service");
auto service = HTTPService::getRegisteredService(servicename, params, response, error);

Log::debug("Running new service: " + servicename);

service->run();
}
catch(const MappingException &e){
catchExceptions(response, e);
}
catch (const std::exception &e) {
error << "Request failed with an exception: " << e.what() << "\n";
Log::debug(e.what());
if (Configuration::get<bool>("global.debug", false)) {
response.send500(concat("invalid request: ", e.what()));
} else {
response.send500("invalid request");
}
}
Log::off();
Log::streamAndMemoryOff();
}

void HTTPService::catchExceptions(HTTPResponseStream& response, const MappingException &me){
Expand All @@ -126,6 +142,7 @@ void HTTPService::catchExceptions(HTTPResponseStream& response, const MappingExc
}
response.sendHeader("Status", "500 Internal Server Error");
response.sendJSON(exceptionJson);
Log::debug(exceptionJson.asString());
} else {
response.send500("invalid request");
}
Expand Down
3 changes: 2 additions & 1 deletion src/services/plot.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include "datatypes/plot.h"
#include "operators/operator.h"

#include "util/log.h"
#include "services/ogcservice.h"

/*
Expand All @@ -24,6 +24,7 @@ REGISTER_HTTP_SERVICE(PlotService, "plot");
void PlotService::run() {
auto session = UserDB::loadSession(params.get("sessiontoken"));
auto user = session->getUser();
Log::debug("User: " + user.getUserIDString());

std::string queryString = params.get("query", "");
if(queryString == "")
Expand Down
2 changes: 2 additions & 0 deletions src/services/provenance.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include "services/ogcservice.h"
#include "operators/operator.h"
#include "util/log.h"

/*
* This class serves provenance information of a query.
Expand All @@ -27,6 +28,7 @@ REGISTER_HTTP_SERVICE(ProvenanceService, "provenance");
void ProvenanceService::run() {
auto session = UserDB::loadSession(params.get("sessiontoken"));
auto user = session->getUser();
Log::debug("User: " + user.getUserIDString());

std::string type = params.get("type", "");
if(type != "points" && type != "lines" && type != "polygons" && type != "raster") {
Expand Down
2 changes: 2 additions & 0 deletions src/services/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <util/gdal_source_datasets.h>
#include <util/ogr_source_datasets.h>
#include <boost/filesystem.hpp>
#include <util/log.h>

/**
* This class provides user specific methods
Expand Down Expand Up @@ -47,6 +48,7 @@ void UserService::run() {
// anything except login is only allowed with a valid session, so check for it.
auto session = UserDB::loadSession(params.get("sessiontoken"));
auto user = session->getUser();
Log::debug("User: " + user.getUserIDString());

if (request == "logout") {
session->logout();
Expand Down
2 changes: 2 additions & 0 deletions src/services/wcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "operators/operator.h"
#include "datatypes/raster.h"
#include "util/timeparser.h"
#include "util/log.h"

/**
* Implementation of the OGC WCS standard http://www.opengeospatial.org/standards/wcs
Expand Down Expand Up @@ -81,6 +82,7 @@ static int getWcsParameterInteger(const std::string &wcsParameterString){
void WCSService::run() {
auto session = UserDB::loadSession(params.get("sessiontoken"));
auto user = session->getUser();
Log::debug("User: " + user.getUserIDString());

/*http://www.myserver.org:port/path?
* service=WCS &version=2.0
Expand Down
2 changes: 2 additions & 0 deletions src/services/wfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "pointvisualization/CircleClusteringQuadTree.h"
#include "util/timeparser.h"
#include "util/enumconverter.h"
#include "util/log.h"

#include <string>
#include <cmath>
Expand Down Expand Up @@ -90,6 +91,7 @@ void WFSService::getCapabilities() {
void WFSService::getFeature() {
auto session = UserDB::loadSession(params.get("sessiontoken"));
auto user = session->getUser();
Log::debug("User: " + user.getUserIDString());

if(!params.hasParam("typenames"))
throw ArgumentException("WFSService: typeNames parameter not specified");
Expand Down
1 change: 1 addition & 0 deletions src/services/wms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ REGISTER_HTTP_SERVICE(WMSService, "WMS");
void WMSService::run() {
auto session = UserDB::loadSession(params.get("sessiontoken"));
auto user = session->getUser();
Log::debug("User: " + user.getUserIDString());

bool debug = params.getBool("debug", Configuration::get<bool>("global.debug", false));
auto query_crsId = parseCrsId(params, "crs");
Expand Down
2 changes: 1 addition & 1 deletion src/uploader/uploader_cgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

int main() {
Configuration::loadFromDefaultPaths();
Log::off();
Log::streamAndMemoryOff();
UserDB::initFromConfiguration();

UploadService service(std::cin.rdbuf(), std::cout.rdbuf(), std::cerr.rdbuf());
Expand Down
Loading