Commit 7251ad72 authored by priit's avatar priit
Browse files

Erinevate teenuste confi refactor + lausestaja

parent e3de7032
var config = {};
config.port = 8000;
config.redis = {
host: "127.0.0.1",
port: 6379
};
config.log4js = {
appenders: [
{ type: 'console',
layout: {
type: 'pattern',
pattern: "[%d] %[[%x{pid}] [%5.5p]%] %c - %m",
tokens: {
pid: process.pid
}
}
},
{ type: 'file',
filename: __dirname + 'keeleliin-server.log'
},
{
"type": "logLevelFilter",
"level": "ERROR",
"appender": {
"type": "smtp",
"recipients": "**********",
"sendInterval": 10, //sec
"transport": "SMTP",
"SMTP": {
"host": "smtp.gmail.com",
"secureConnection": false,
"port": 587,
"auth": {
"user": "***********",
"pass": "***********"
},
"debug": true
}
}
}
]
};
config.serviceTypes = {
LOCAL: 'LOCAL'
};
config.availableWappers = {
CONTENT_TOKENIZER : {
class: 'contentTokenizer',
commandTemplate: 'python /home/priit/Programs/KEELELIIN/pyutil/tokenizer.py -i [data] -o [outputPath1]'
},
MORFYHESTAJA : {
class: 'morfyhestaja',
commandTemplate: '/home/priit/Downloads/morfyhestaja/./parse.sh [data]'
},
ARCHIVE_EXTRACTOR: {
class: 'archiveExtractor',
commandTemplate: ''
}
};
config.paramUsageTypes = {
META: 'meta', //ei kasutata utiliidi parameetrina
STRING : 'string', //parameeter asendatakse väärtusega
FILE : 'file' //parameeteri väärtus salvestatakse faili ja faili pathi kasutatakse argumendina
};
config.service = {
title: 'Wrapper',
description: 'Wrapperi kirjeldus',
//Siia peab olema märgitud kõik võimalikud parameetrid va sisendfailid
requestBodyTemplate: {
is_async: null//,
//someparam: null
},
//Iga parameeter peab ka siin esindatud olema
requestBodyParamsMappings: {
is_async: {
usageType: config.paramUsageTypes.META,
filter: function(value){
return value == 1;
},
required: true,
allowEmpty: false,
validator: function(value, request){ return true; }
}/*,
someparam: {
usageType: config.paramUsageTypes.STRING,
filter: function(value){
if(value == 'yes'){
return '-o';
}
return null;
},
required: false,
allowEmpty: true,
validator: function(value, request){ return true; }
}*/
},
requestFiles: {
content: null
},
staticParams: {
uniqueId: 'wrapper_1',
wrapper: config.availableWappers.MORFYHESTAJA.class,
storagePath: "/home/priit/wrapper",
tmpPath: "/tmp/wrapper/",
sessionMaxLifetime: 600, //(s) Sessioonid, mille failide viimased muudatused on vanemad kui antud aeg, kustutatakse süsteemist
//siin saab päringu parameetrite väärtused üle kirjutada
isAsync: undefined //väärtustega true/false saab päringu väärtuse üle kirjutada
}
};
module.exports = config;
\ No newline at end of file
/**
* Kopeeri antud fail faili config.js
*
* require soovitud wrapperi conf ja kirjuta üle vajalikud parameetrid
*/
// var config = require('./wrapper_configs/config_tokenizer');
/*
config.port = 8001;
config.log4js.appenders.push({
"type": "logLevelFilter",
"level": "ERROR",
"appender": {
"type": "smtp",
"recipients": "test@test.com",
"sendInterval": 10, //sec
"transport": "SMTP",
"SMTP": {
"host": "smtp.gmail.com",
"secureConnection": false,
"port": 587,
"auth": {
"user": "***********",
"pass": "***********"
},
"debug": true
}
}
});
config.availableWappers.TOKENIZER.commandTemplate = 'python /home/priit/Programs/KEELELIIN/pyutil/tokenizer.py -i [data] -o [outputPath1]';
config.service.staticParams.storagePath = "/home/priit/wrapper";
config.service.staticParams.tmpPath = "/tmp/wrapper/";
module.exports = config;*/
var logger = require('log4js').getLogger('wrapper');
var config = require('./../config');
var localExecutor = require('./../src/service/executor/localExecutor');
var Session = require('../src/model/session');
var CommandModel = require('../src/mapper/commandModel');
var fs = require('fs');
var mime = require('mime');
var path = require('path');
function Lausestaja(){
var self = this;
this.process = function ( session, callback) {
self.getCommandModel(session, function (err, model) {
logger.debug('GetCommandModel callback');
if(err) return callback(err);
localExecutor.execute( model, function ( err, response ) {
if(err) return callback(err);
logger.debug('Program is finished');
if(response.isSuccess){
session.message = Session.messages.OK;
} else {
session.setErrors(response.errors);
}
session.addOutputFile('output', {
type: 'output',
fileName: path.basename(response.stdOutPath),
filePath: response.stdOutPath,
contentType: mime.lookup(response.stdOutPath)
});
return callback( err, session );
});
});
};
this.getCommandModel = function (session, callback) {
var model = new CommandModel();
model.serviceProperties.commandTemplate = config.availableWappers.LAUSESTAJA.commandTemplate;
model.init( session );
model.setTextValue('data', session.requestFiles.content);
model.render(function (err) {
logger.debug('Render callback');
callback(err, model);
});
}
}
module.exports = Lausestaja;
\ No newline at end of file
......@@ -7,7 +7,7 @@ var fs = require('fs');
var mime = require('mime');
var path = require('path');
function ContentTokenizer(){
function Morfyhestaja(){
var self = this;
......@@ -51,4 +51,4 @@ function ContentTokenizer(){
}
}
module.exports = ContentTokenizer;
\ No newline at end of file
module.exports = Morfyhestaja;
\ No newline at end of file
......@@ -9,7 +9,7 @@ var fs = require('fs');
var mime = require('mime');
var path = require('path');
function ContentTokenizer(){
function Tokenizer(){
var self = this;
......@@ -97,7 +97,7 @@ function ContentTokenizer(){
this.getCommandModel = function (session, callback) {
var model = new CommandModel();
model.serviceProperties.commandTemplate = config.availableWappers.CONTENT_TOKENIZER.commandTemplate;
model.serviceProperties.commandTemplate = config.availableWappers.TOKENIZER.commandTemplate;
model.init( session );
model.setTextValue('data', session.requestFiles.content);
model.addOutputPath('outputPath1');
......@@ -108,4 +108,4 @@ function ContentTokenizer(){
}
}
module.exports = ContentTokenizer;
\ No newline at end of file
module.exports = Tokenizer;
\ No newline at end of file
var config = require('./config_global');
config.port = 3004;
config.service.title = 'Arhiivi lahtipakkija';
config.service.staticParams.uniqueId = 'unzipper';
config.service.staticParams.wrapper = config.availableWappers.ARCHIVE_EXTRACTOR.class;
module.exports = config;
\ No newline at end of file
var config = {};
config.port = 3000;
config.redis = {
host: "127.0.0.1",
port: 6379
};
config.log4js = {
appenders: [
{ type: 'console',
layout: {
type: 'pattern',
pattern: "[%d] %[[%x{pid}] [%5.5p]%] %c - %m",
tokens: {
pid: process.pid
}
}
},
{ type: 'file',
filename: __dirname + '/../wrapper.log'
}/*,
{ // Error reporting
"type": "logLevelFilter",
"level": "ERROR",
"appender": {
"type": "smtp",
"recipients": "**********",
"sendInterval": 10, //sec
"transport": "SMTP",
"SMTP": {
"host": "smtp.gmail.com",
"secureConnection": false,
"port": 587,
"auth": {
"user": "***********",
"pass": "***********"
},
"debug": true
}
}
}*/
]
};
config.availableWappers = {
TOKENIZER : {
class: 'tokenizer',
commandTemplate: 'python /var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/tokenizer/tokenizer.py -i [data] -o [outputPath1]'
},
MORFANALYZER : {
class: 'morfanalyzer',
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./morfanalyzer.sh [data]'
},
LAUSESTAJA : {
class: 'lausestaja',
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./lausestaja.sh [data]'
},
OSALAUSESTAJA : {
class: 'osalausestaja',
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./osalausestaja.sh [data]'
},
ARCHIVE_EXTRACTOR: {
class: 'archiveExtractor',
commandTemplate: ''
}
};
config.paramUsageTypes = {
META: 'meta', //ei kasutata utiliidi parameetrina
STRING : 'string', //parameeter asendatakse väärtusega
FILE : 'file' //parameeteri väärtus salvestatakse faili ja faili pathi kasutatakse argumendina
};
config.service = {
title: 'Teenus',
description: 'Teenuse kirjeldus',
//Siia peab olema märgitud kõik võimalikud parameetrid va sisendfailid
requestBodyTemplate: {
is_async: null//,
//someparam: null
},
//Iga parameeter peab ka siin esindatud olema
requestBodyParamsMappings: {
is_async: {
usageType: config.paramUsageTypes.META,
filter: function(value){
return value == 1;
},
required: true,
allowEmpty: false,
validator: function(value, request){ return true; }
}/*,
someparam: {
usageType: config.paramUsageTypes.STRING,
filter: function(value){
if(value == 'yes'){
return '-o';
}
return null;
},
required: false,
allowEmpty: true,
validator: function(value, request){ return true; }
}*/
},
requestFiles: {
content: null
},
staticParams: {
uniqueId: 'wrapper',
wrapper: config.availableWappers.TOKENIZER.class,
storagePath: "/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/tmp",
tmpPath: "/tmp/wrapper/",
sessionMaxLifetime: 600, //(s) Sessioonid, mille failide viimased muudatused on vanemad kui antud aeg, kustutatakse süsteemist
//siin saab päringu parameetrite väärtused üle kirjutada
isAsync: undefined //väärtustega true/false saab päringu väärtuse üle kirjutada
}
};
module.exports = config;
\ No newline at end of file
var config = require('./config_global');
config.port = 3005;
config.service.title = 'Lausestaja';
config.service.staticParams.uniqueId = 'sentence';
config.service.staticParams.wrapper = config.availableWappers.LAUSESTAJA.class;
module.exports = config;
\ No newline at end of file
var config = require('./config_global');
config.port = 3003;
config.service.title = 'Morfoloogiline analüüs';
config.service.staticParams.uniqueId = 'morfanalyzer';
config.service.staticParams.wrapper = config.availableWappers.OSALAUSESTAJA.class;
module.exports = config;
\ No newline at end of file
var config = require('./config_global');
config.port = 3002;
config.service.title = 'Sõnestaja';
config.service.staticParams.uniqueId = 'tokenizer';
config.service.staticParams.wrapper = config.availableWappers.TOKENIZER.class;
module.exports = config;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment