upstart, stabilizing

This commit is contained in:
rjawor 2015-12-16 09:48:15 +01:00
parent 2724696875
commit c7459af387
9 changed files with 122 additions and 22 deletions

6
.gitignore vendored
View File

@ -1,5 +1,6 @@
build/
logs/concordia-server.log
logs/pgbouncer.log
concordia.cfg
concordia-server/config.hpp
index/
@ -9,6 +10,7 @@ scripts/stop.sh
scripts/restart.sh
scripts/watchdog.sh
scripts/watchdog.log
db/pgbouncer.log
db/pgbouncer.pid
db/pgbouncer.ini
upstart/concordia-server.conf
upstart/pgbouncer.conf

View File

@ -44,6 +44,21 @@ configure_file (
"${concordia-server_SOURCE_DIR}/scripts/watchdog.sh"
)
configure_file (
"${concordia-server_SOURCE_DIR}/upstart/cmake_stubs/concordia-server.conf.in"
"${concordia-server_SOURCE_DIR}/upstart/concordia-server.conf"
)
configure_file (
"${concordia-server_SOURCE_DIR}/upstart/cmake_stubs/pgbouncer.conf.in"
"${concordia-server_SOURCE_DIR}/upstart/pgbouncer.conf"
)
configure_file (
"${concordia-server_SOURCE_DIR}/db/pgbouncer.ini.in"
"${concordia-server_SOURCE_DIR}/db/pgbouncer.ini"
)
set(CONFIG_FILE_PATH "${concordia-server_SOURCE_DIR}/concordia.cfg")
set(LOG_FILE_PATH "${concordia-server_SOURCE_DIR}/logs/concordia-server.log")

View File

@ -32,9 +32,8 @@ std::string ConcordiaServer::handleRequest(std::string & requestString) {
rapidjson::Writer<rapidjson::StringBuffer> jsonWriter(outputJson);
std::stringstream outputString;
outputString << "Content-type: application/json\r\n\r\n";
try {
outputString << "Access-Control-Allow-Origin: *\r\n";
outputString << "Content-type: application/json\r\n\r\n";
rapidjson::Document d;
bool hasError = d.Parse(requestString.c_str()).HasParseError();
@ -44,16 +43,16 @@ std::string ConcordiaServer::handleRequest(std::string & requestString) {
", description: " << GetParseError_En(d.GetParseError());
JsonGenerator::signalError(jsonWriter, errorstream.str());
} else { // json parsed
std::string operation = d[OPERATION_PARAM].GetString();
if (operation == ADD_SENTENCE_OP) {
std::string sourceSentence = d[SOURCE_SENTENCE_PARAM].GetString();
std::string targetSentence = d[TARGET_SENTENCE_PARAM].GetString();
int tmId = d[TM_ID_PARAM].GetInt();
std::string operation = _getStringParameter(d, OPERATION_PARAM);
if (operation == ADD_SENTENCE_OP) {
std::string sourceSentence = _getStringParameter(d, SOURCE_SENTENCE_PARAM);
std::string targetSentence = _getStringParameter(d, TARGET_SENTENCE_PARAM);
int tmId = _getIntParameter(d, TM_ID_PARAM);
_indexController->addSentence(jsonWriter, sourceSentence, targetSentence, tmId);
} else if (operation == ADD_SENTENCES_OP) {
std::vector<std::string> sourceSentences;
std::vector<std::string> targetSentences;
int tmId = d[TM_ID_PARAM].GetInt();
int tmId = _getIntParameter(d, TM_ID_PARAM);
// loading data from json
const rapidjson::Value & sentencesArray = d[SENTENCES_PARAM];
Logger::log("addSentences");
@ -89,21 +88,21 @@ std::string ConcordiaServer::handleRequest(std::string & requestString) {
}
_indexController->addAlignedSentences(jsonWriter, sourceSentences, targetSentences, tmId);
} else if (operation == REFRESH_INDEX_OP) {
int tmId = d[TM_ID_PARAM].GetInt();
int tmId = _getIntParameter(d, TM_ID_PARAM);
_indexController->refreshIndexFromRAM(jsonWriter, tmId);
} else if (operation == SIMPLE_SEARCH_OP) {
std::string pattern = d[PATTERN_PARAM].GetString();
int tmId = d[TM_ID_PARAM].GetInt();
std::string pattern = _getStringParameter(d, PATTERN_PARAM);
int tmId = _getIntParameter(d, TM_ID_PARAM);
_searcherController->simpleSearch(jsonWriter, pattern, tmId);
} else if (operation == CONCORDIA_SEARCH_OP) {
std::string pattern = d[PATTERN_PARAM].GetString();
int tmId = d[TM_ID_PARAM].GetInt();
std::string pattern = _getStringParameter(d, PATTERN_PARAM);
int tmId = _getIntParameter(d, TM_ID_PARAM);
Logger::logString("concordia search pattern", pattern);
_searcherController->concordiaSearch(jsonWriter, pattern, tmId);
} else if (operation == ADD_TM_OP) {
int sourceLangId = d[SOURCE_LANG_PARAM].GetInt();
int targetLangId = d[TARGET_LANG_PARAM].GetInt();
std::string name = d[NAME_PARAM].GetString();
int sourceLangId = _getIntParameter(d, SOURCE_LANG_PARAM);
int targetLangId = _getIntParameter(d, TARGET_LANG_PARAM);
std::string name = _getStringParameter(d, NAME_PARAM);
int newId = _tmDAO.addTm(sourceLangId, targetLangId, name);
_addTm(newId);
@ -115,7 +114,7 @@ std::string ConcordiaServer::handleRequest(std::string & requestString) {
jsonWriter.EndObject();
} else {
JsonGenerator::signalError(jsonWriter, "no such operation");
JsonGenerator::signalError(jsonWriter, "no such operation: " + operation);
}
}
@ -131,6 +130,28 @@ std::string ConcordiaServer::handleRequest(std::string & requestString) {
}
std::string ConcordiaServer::_getStringParameter(rapidjson::Document & d, const char * name)
throw (ConcordiaException) {
rapidjson::Value::ConstMemberIterator itr = d.FindMember(name);
if (itr != d.MemberEnd()) {
std::string value = itr->value.GetString();
return value;
} else {
throw ConcordiaException("missing parameter: " + std::string(name));
}
}
int ConcordiaServer::_getIntParameter(rapidjson::Document & d, const char * name)
throw (ConcordiaException) {
rapidjson::Value::ConstMemberIterator itr = d.FindMember(name);
if (itr != d.MemberEnd()) {
int value = itr->value.GetInt();
return value;
} else {
throw ConcordiaException("missing parameter: " + std::string(name));
}
}
void ConcordiaServer::_addTm(int tmId) {
std::stringstream indexPath;
indexPath << INDEX_DIRECTORY << "/tm_" << tmId;

View File

@ -30,6 +30,10 @@ public:
std::string handleRequest(std::string & requestString);
private:
std::string _getStringParameter(rapidjson::Document & d, const char * name) throw (ConcordiaException);
int _getIntParameter(rapidjson::Document & d, const char * name) throw (ConcordiaException);
void _addTm(int tmId);
std::string _configFilePath;

View File

@ -131,6 +131,9 @@ void IndexController::refreshIndexFromRAM(rapidjson::Writer<rapidjson::StringBuf
std::vector<AlignedUnit> IndexController::_getAlignedUnits(const std::vector<std::string> & sourceSentences,
const std::vector<std::string> & targetSentences) {
//TODO
std::vector<AlignedUnit> result;
return result;
}

View File

@ -5,7 +5,7 @@ concordia_server = host=127.0.0.1 port=5432 dbname=concordia_server
listen_port = 6543
listen_addr = *
auth_type = md5
auth_file = users.txt
logfile = pgbouncer.log
pidfile = pgbouncer.pid
auth_file = /home/rafalj/projects/concordia-server/db/users.txt
logfile = /home/rafalj/projects/concordia-server/logs/pgbouncer.log
pidfile = /home/rafalj/projects/concordia-server/db/pgbouncer.pid
admin_users = concordia

11
db/pgbouncer.ini.in Normal file
View File

@ -0,0 +1,11 @@
[databases]
concordia_server = host=127.0.0.1 port=5432 dbname=concordia_server
[pgbouncer]
listen_port = 6543
listen_addr = *
auth_type = md5
auth_file = @concordia-server_SOURCE_DIR@/db/users.txt
logfile = @concordia-server_SOURCE_DIR@/logs/pgbouncer.log
pidfile = @concordia-server_SOURCE_DIR@/db/pgbouncer.pid
admin_users = concordia

View File

@ -0,0 +1,24 @@
# concordia server
#
# This service maintains concordia server
# started until it is shut down again.
description concordia-server
# When to start the service
start on started pgbouncer
# When to stop the service
stop on runlevel [016]
# Automatically restart process if crashed
respawn
# Essentially lets upstart know the process will detach itself to the background
expect fork
# Start the process
script
exec spawn-fcgi -p 8000 -n @COMPILED_BINARIES_PATH@/concordia_server_process &
end script

View File

@ -0,0 +1,20 @@
# PgBouncer Upstart script
description "pgbouncer"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
respawn
respawn limit 10 30
expect fork
script
exec pgbouncer -u rafalj @concordia-server_SOURCE_DIR@/db/pgbouncer.ini &
sleep 4
end script