Commit c218ee19 authored by priit's avatar priit

Teenuse install

parent 78ca7290
......@@ -24,29 +24,30 @@ function ServiceRequest( requestBody, requestFiles ) {
this._mapParams = function(){
var staticParams = config.wrapper.requestConf.staticParams;
for(var property in config.wrapper.requestConf.requestBodyTemplate){
for(var property in config.wrapper.requestConf.requestBodyParamsMappings){
var value = self.data[property];
var mapping = config.wrapper.requestConf.requestBodyParamsMappings[property];
if(staticParams[property] != undefined){
value = staticParams[property];
}
if(mapping.filter){
value = mapping.filter(value);
}
if(mapping.required == true && value == undefined){
self.setMessage(property, 'Väli on nõutud');
continue;
}
if(mapping.allowEmpty == false && (value === null || value === '') ){
self.setMessage(property, 'Väli on täitmata');
continue;
}
if(!value){
value = mapping.value;
}
if(mapping.validator){
mapping.validator(value, self);
}
......
......@@ -14,7 +14,7 @@ var CleanerService = function () {
this.init = function(){
logger.debug('init');
if(!config.wrapper.requestConf.staticParams.sessionMaxLifetime){
if(!config.wrapper.sessionMaxLifetime){
return;
}
......@@ -74,7 +74,7 @@ var CleanerService = function () {
var timeModified = stat.mtime.getTime();
var currentTime = new Date().getTime();
if(currentTime - timeModified > ( config.wrapper.requestConf.staticParams.sessionMaxLifetime * 1000 )){
if(currentTime - timeModified > ( config.wrapper.sessionMaxLifetime * 1000 )){
sessionService.removeSession(file, function (err) {
if(err){
logger.error('Session delete failed: ' + file);
......
......@@ -60,16 +60,15 @@ var InstallService = function() {
}
configuration.parameters = [];
var requestBodyTemplate = wrapper.requestConf.requestBodyTemplate;
for(var property in requestBodyTemplate){
if (requestBodyTemplate.hasOwnProperty(property)) {
configuration.parameters.push({
key: property,
type: wrapper.requestConf.requestBodyParamsMappings[property].type,
options: wrapper.requestConf.requestBodyParamsMappings[property].options,
value: requestBodyTemplate[property]
});
}
for(var property in wrapper.requestConf.requestBodyParamsMappings){
configuration.parameters.push({
key: property,
type: wrapper.requestConf.requestBodyParamsMappings[property].type,
options: wrapper.requestConf.requestBodyParamsMappings[property].options,
value: wrapper.requestConf.requestBodyParamsMappings[property].value
});
}
}
......
var config = {};
config.redis = {
......@@ -20,18 +19,8 @@ config.fs = {
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.wrapper = {
id: null, // unique service identifier
title: null,
description: '',
port: null,
class: null,
command: null,
requestConf: null
STRING: 'string', //parameeter asendatakse väärtusega
FILE: 'file' //parameeteri väärtus salvestatakse faili ja faili pathi kasutatakse argumendina
};
config.log4js = {
......@@ -74,159 +63,170 @@ config.log4js = {
]
};
/*var someCommandRequest = {
requestBodyTemplate: {
isAsync: null//,
someparam: null
},
requestBodyParamsMappings: {
isAsync: {
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: {
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
}
};*/
var simpleCommandRequest = {
requestBodyTemplate: {
isAsync: null
//key: null
},
requestBodyParamsMappings: {
isAsync: {
type: 'select',
options: ['0','1'],
usageType: config.paramUsageTypes.META,
filter: function (value) {
return value == 1;
},
required: true,
allowEmpty: false,
validator: function (value, request) {
return true;
}
}
/**
* , key: {
type: 'text',
usageType: config.paramUsageTypes.STRING,
filter: function(value){
return value == 1;
},
required: true,
allowEmpty: false,
validator: function(value, request){ return true; }
}
*/
},
requestFiles: {
content: {
type: 'text',
sizeLimit: 0,
sizeUnit: 'byte',
isList: false
}
},
staticParams: {
sessionMaxLifetime: 600,
isAsync: undefined
},
outputTypes: [
{
type: 'text',
key: 'output'
}
]
config.wrapper = {
id: null, // unique service identifier
title: null,
description: '',
port: null,
class: null,
command: null,
requestConf: null
};
config.availableCommands = {
TOKENIZER : {
TOKENIZER: {
commandTemplate: 'python /var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/picoutils/tokenizer.py -i [data] -o [output]'
},
MORFANALYSAATOR : {
MORFANALYSAATOR: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./morfanalyzer.sh [data]'
},
LAUSESTAJA : {
LAUSESTAJA: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./lausestaja.sh [data]'
},
OSALAUSESTAJA : {
OSALAUSESTAJA: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./osalausestaja.sh [data]'
},
MORFYHESTAJA : {
MORFYHESTAJA: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./morfyhestaja.sh [data]'
},
PIND_SYN : {
PIND_SYN: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./pindsyn.sh [data]'
},
S6LT_SYN : {
S6LT_SYN: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./s6ltsyn.sh [data]'
},
CONCAT : {
CONCAT: {
commandTemplate: 'cat [data]'
},
MORPH_TAGGER : {
MORPH_TAGGER: {
commandTemplate: 'python /var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/picoutils/morph_tagger.py -i [data] -o [output]'
}
};
var isAsyncParamValue = {
type: 'select',
options: ['0', '1'],
value: '1',
usageType: config.paramUsageTypes.META,
filter: function (value) {
return value == 1;
},
required: true,
allowEmpty: false,
validator: function (value, request) {
return true;
}
};
var stringKeyValue = {
type: 'text',
value: undefined,
usageType: config.paramUsageTypes.STRING,
filter: null,
required: false,
allowEmpty: true,
validator: function(value, request){
return true;
}
};
var fileKeyValue = {
type: 'text',
value: undefined,
usageType: config.paramUsageTypes.FILE,
filter: null,
required: false,
allowEmpty: true,
validator: function(value, request){
return true;
}
};
config.availableWrappers = {
LAUSESTAJA : {
LAUSESTAJA: {
title: 'Lausestaja',
description: '',
id: 'lau',
port: 3001,
class: 'simpleLocalCommand',
command: config.availableCommands.LAUSESTAJA,
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
requestConf: {
requestBodyParamsMappings: {
isAsync: isAsyncParamValue
},
requestFiles: {
content: {
type: 'text',
sizeLimit: 0,
sizeUnit: 'byte',
isList: false
}
}
},
outputTypes: [
{
type: 'lau_a',
key: 'output'
}
],
sessionMaxLifetime: 600
},
MORFANALYSAATOR : {
MORFANALYSAATOR: {
title: 'Morfoloogiline analüüs',
description: '',
id: 'moa',
port: 3002,
class: 'simpleLocalCommand',
command: config.availableCommands.MORFANALYSAATOR,
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
requestConf: {
requestBodyParamsMappings: {
isAsync: isAsyncParamValue
},
requestFiles: {
content: {
type: 'lau_a',
sizeLimit: 0,
sizeUnit: 'byte',
isList: false
}
}
},
outputTypes: [
{
type: 'moa_a',
key: 'output'
}
],
sessionMaxLifetime: 600
},
OSALAUSESTAJA : {
OSALAUSESTAJA: {
title: 'Osalausestaja',
description: '',
id: 'osl',
port: 3003,
class: 'simpleLocalCommand',
command: config.availableCommands.OSALAUSESTAJA,
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
requestConf: {
requestBodyParamsMappings: {
isAsync: isAsyncParamValue
},
requestFiles: {
content: {
type: 'moa_a',
sizeLimit: 0,
sizeUnit: 'byte',
isList: false
}
}
},
outputTypes: [
{
type: 'osl_a',
key: 'output'
}
],
sessionMaxLifetime: 600
},
MORFYHESTAJA: {
title: 'Morfoloogiline ühestamine (kitsenduste grammatika)',
......@@ -235,8 +235,26 @@ config.availableWrappers = {
port: 3004,
class: 'simpleLocalCommand',
command: config.availableCommands.MORFYHESTAJA,
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
requestConf: {
requestBodyParamsMappings: {
isAsync: isAsyncParamValue
},
requestFiles: {
content: {
type: 'osl_a',
sizeLimit: 0,
sizeUnit: 'byte',
isList: false
}
}
},
outputTypes: [
{
type: 'moy_a',
key: 'output'
}
],
sessionMaxLifetime: 600
},
PIND_SYN: {
title: 'Pindsüntaktiline analüüs',
......@@ -245,8 +263,26 @@ config.availableWrappers = {
port: 3005,
class: 'simpleLocalCommand',
command: config.availableCommands.PIND_SYN,
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
requestConf: {
requestBodyParamsMappings: {
isAsync: isAsyncParamValue
},
requestFiles: {
content: {
type: 'moy_a',
sizeLimit: 0,
sizeUnit: 'byte',
isList: false
}
}
},
outputTypes: [
{
type: 'pia_a',
key: 'output'
}
],
sessionMaxLifetime: 600
},
S6LT_SYN: {
title: 'Sõltuvussüntaktiline analüüs (ja järeltöötlus)',
......@@ -255,8 +291,26 @@ config.availableWrappers = {
port: 3006,
class: 'simpleLocalCommand',
command: config.availableCommands.S6LT_SYN,
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
requestConf: {
requestBodyParamsMappings: {
isAsync: isAsyncParamValue
},
requestFiles: {
content: {
type: 'pia_a',
sizeLimit: 0,
sizeUnit: 'byte',
isList: false
}
}
},
outputTypes: [
{
type: 's6a_a',
key: 'output'
}
],
sessionMaxLifetime: 600
},
ARCHIVE_EXTRACTOR: {
......@@ -266,23 +320,8 @@ config.availableWrappers = {
port: 3007,
class: 'archiveExtractor',
requestConf: {
requestBodyTemplate: {
isAsync: null
},
requestBodyParamsMappings: {
isAsync: {
type: 'select',
options: ['0','1'],
usageType: config.paramUsageTypes.META,
filter: function (value) {
return value == 1;
},
required: true,
allowEmpty: false,
validator: function (value, request) {
return true;
}
}
isAsync: isAsyncParamValue
},
requestFiles: {
content: {
......@@ -291,58 +330,53 @@ config.availableWrappers = {
sizeUnit: 'byte',
isList: false
}
},
staticParams: {
sessionMaxLifetime: 600,
isAsync: 0
}
},
outputTypes: [ { type: 'text', key: 'output' }]
outputTypes: [
{
type: 'text',
key: 'output'
}
],
sessionMaxLifetime: 600
},
TOKENIZER : {
TOKENIZER: {
title: 'Sõnestaja pipe',
description: '',
id: 'tok',
port: 3008,
class: 'inputOutputLocalCommand',
command: config.availableCommands.TOKENIZER,
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
requestConf: {
requestBodyParamsMappings: {
isAsync: isAsyncParamValue
},
requestFiles: {
content: {
type: 'text',
sizeLimit: 0,
sizeUnit: 'byte',
isList: false
}
}
},
outputTypes: [
{
type: 'tok_a',
key: 'output'
}
],
sessionMaxLifetime: 600
},
CONCAT : {
CONCAT: {
title: 'Lihtne konkateneerija',
id: 'concat',
port: 3009,
class: 'simpleLocalCommand',
command: config.availableCommands.CONCAT,
requestConf: {
requestBodyTemplate: {
isAsync: null,
key: null
},
requestBodyParamsMappings: {
isAsync: {
type: 'select',
options: ['0','1'],
usageType: config.paramUsageTypes.META,
filter: function (value) {
return value == 1;
},
required: true,
allowEmpty: false,
validator: function (value, request) {
return true;
}
}, key: {
type: 'text',
usageType: config.paramUsageTypes.STRING,
filter: function(value){
return value == 1;
},
required: true,
allowEmpty: false,
validator: function(value, request){ return true; }
}
isAsync: isAsyncParamValue
},
requestFiles: {
content: {
......@@ -351,22 +385,42 @@ config.availableWrappers = {
sizeUnit: 'byte',
isList: true
}
},
staticParams: {
sessionMaxLifetime: 600,
isAsync: undefined
}
},
outputTypes: [ { type: 'text', key: 'output' }]
outputTypes: [
{
type: 'text',
key: 'output'
}
],
sessionMaxLifetime: 600
},
MORPH_TAGGER : {
MORPH_TAGGER: {
title: 'Morfoloogiline ühestaja pipe',
id: 'tag',
port: 3010,
class: 'inputOutputLocalCommand',
command: config.availableCommands.MORPH_TAGGER,
requestConf: simpleCommandRequest,
outputTypes: [ { type: 'text', key: 'output' }]
requestConf: {
requestBodyParamsMappings: {
isAsync: isAsyncParamValue
},
requestFiles: {
content: {
type: 'text',
sizeLimit: 0,
sizeUnit: 'byte',
isList: false
}
}
},
outputTypes: [
{
type: 'tag_a',
key: 'output'
}
],
sessionMaxLifetime: 600
}
};
......
......@@ -80,7 +80,7 @@ function startCluster( instanceCount, cb ){
//Lase serveril üles ärgata
setTimeout(function(){
installService.install(function () {
log4jsLogger.error('Instal callback');
log4jsLogger.trace('Instal callback');
})
}, 10000);
......