Commit 856f8d15 authored by priit's avatar priit

Dockeri alge

parent ceae0926
...@@ -11,5 +11,5 @@ tmp_tests/94megafile ...@@ -11,5 +11,5 @@ tmp_tests/94megafile
tmp_tests/189megafile tmp_tests/189megafile
keeleliin.log keeleliin.log
coverage coverage
wrapper_configs/local_global.js global_config/local_global.js
updateWrappers.sh updateWrappers.sh
\ No newline at end of file
FROM ubuntu:14.04 # docker build -t kl_wrapper .
# docker run --name kl_redis --rm --restart=no redis
# docker run --name kl_wrapper -d -it --link kl_redis:redis -p 3000:3000 -v /config:/config -v /logs:/logs kl_wrapper
# docker kill kl_wrapper
# docker rm kl_wrapper
#
MAINTAINER priit@bitweb.ee FROM ubuntu:14.04
RUN apt-get update && \ RUN apt-get update && apt-get -y install nodejs npm git
apt-get -y install curl && \
curl -sL https://deb.nodesource.com/setup | sudo bash - && \
apt-get -y install python build-essential nodejs
# Provides cached layer for node_modules RUN npm install -g forever
ADD package.json /tmp/package.json
RUN cd /tmp && npm install && npm install -g forever
RUN mkdir -p /src && cp -a /tmp/node_modules /src/
# Define working directory RUN mkdir -p /src
WORKDIR /src RUN cd /src && git clone 'https://github.com/BitWeb/keeleliin-wrapper-service.git' . && echo "Git is cloned 1"
ADD . /src RUN cd /src && npm install && echo "NPM is installed 1"
# Expose port #Expose port
EXPOSE 3000 EXPOSE 3000
VOLUME ["/wrapper"] VOLUME ["/src"]
# Run app using forever CMD /./src/docker_start.sh
CMD ["forever", "/src/app.js"] \ No newline at end of file
\ No newline at end of file
var config = require('./wrapper_configs/global'); var config = require('./global_config/global');
//config.serverUrl = 'http://localhost';
//config.redis = {
// host: process.env.REDIS_PORT_6379_TCP_ADDR || "127.0.0.1",
// port: process.env.REDIS_PORT_6379_TCP_PORT || 6379
//};
//config.integration = [
// {
// installUrl: 'http://keeleliin.keeleressursid.ee:3000/api/v1/service/install',
// apiKey: 'server-wrapper-api-key'
// }
//];
//config.fs = {
// storagePath: "/wrapper/files",
// tmpPath: "/wrapper/tmp"
//};
/*config.log4js.appenders.push({ /*config.log4js.appenders.push({
"type": "logLevelFilter", "type": "logLevelFilter",
...@@ -30,10 +50,52 @@ var config = require('./wrapper_configs/global'); ...@@ -30,10 +50,52 @@ var config = require('./wrapper_configs/global');
} }
});*/ });*/
config.serverUrl = process.env.SERVER_URL || 'http://dev.bitweb.ee'; config.wrapper = {
config.wrapper = process.env.WRAPPER ? (config.availableWrappers + process.env.WRAPPER) : config.availableWrappers.CONCAT; id: 'concat', // unikaalne lühinimi
title: 'Lihtne konjateneerija', //Avalik nimi
description: 'Konkateneerib etteantud failid üheks suureks failiks', //Kirjeldus
port: 3000, //port
class: 'simpleLocalCommand', //wrapperi failinimi wrapper kaustast, mida utiliidi käivitamiseks kasutatakse
command: 'cat [data]', // utiliidi käsurea käsk
requestConf: { //Päringu seadistus
requestBodyParamsMappings: {
isAsync: {
type: config.paramTypes.SELECT,
options: ['0', '1'],
value: '1',
usageType: config.paramUsageTypes.META,
filter: function (value) {
return value == 1;
},
required: true,
allowEmpty: false,
validator: function (value, request) {
if( typeof value != 'boolean' ){
request.setMessage('isAsync', 'Peab olema boolean');
return false;
}
return true;
}
}
},
requestFiles: {
content: {
type: 'text',
sizeLimit: 0,
sizeUnit: 'byte',
isList: true
}
}
},
outputTypes: [ //teenuse väljundressursside kirjldused
{
type: 'text',
key: 'output'
}
],
sessionMaxLifetime: 600 // sessiooni maksimaalne kestvus
};
config.fs.storagePath = "/files";
config.fs.tmpPath = "/tmp";
module.exports = config; module.exports = config;
\ No newline at end of file
...@@ -13,9 +13,6 @@ router.get('/config', function(req, res) { ...@@ -13,9 +13,6 @@ router.get('/config', function(req, res) {
router.post('/', function ( req, res ) { router.post('/', function ( req, res ) {
logger.debug(req.body);
logger.debug(req.files);
var serviceRequest = new ServiceRequest( req.body, req.files ); var serviceRequest = new ServiceRequest( req.body, req.files );
if(!serviceRequest.isValid()){ if(!serviceRequest.isValid()){
...@@ -23,6 +20,8 @@ router.post('/', function ( req, res ) { ...@@ -23,6 +20,8 @@ router.post('/', function ( req, res ) {
return; return;
} }
logger.debug(serviceRequest );
wrapperService.execute( serviceRequest, function (err, data) { wrapperService.execute( serviceRequest, function (err, data) {
if(err) return res.send({errors: err}); if(err) return res.send({errors: err});
res.send(data); res.send(data);
......
#!/bin/bash #!/bin/bash
if [ ! -f /config/config.js ]; then
cp -R -u -p /src/config_dist.js /config/config.js
fi
if [ ! -f /src/config.js ]; then if [ ! -f /src/config.js ]; then
ln -s /config/config.js /src/config.js cp -R -u -p /src/config_dist.js /src/config.js
fi
if [ ! -f /config/wrapper_configs/global.js ]; then
mkdir -p /config/wrapper_configs
ln -s /src/wrapper_configs/global.js /config/wrapper_configs/global.js
fi fi
forever /src/app.js forever /src/app.js
\ No newline at end of file
...@@ -5,13 +5,9 @@ config.redis = { ...@@ -5,13 +5,9 @@ config.redis = {
port: process.env.REDIS_PORT_6379_TCP_PORT || 6379 port: process.env.REDIS_PORT_6379_TCP_PORT || 6379
}; };
config.serverUrl = 'http://dev.bitweb.ee'; config.serverUrl = 'http://localhost';
config.integration = [ config.integration = [
{
installUrl: 'http://dev.bitweb.ee:3000/api/v1/service/install',
apiKey: 'server-wrapper-api-key'
},
{ {
installUrl: 'http://keeleliin.keeleressursid.ee:3000/api/v1/service/install', installUrl: 'http://keeleliin.keeleressursid.ee:3000/api/v1/service/install',
apiKey: 'server-wrapper-api-key' apiKey: 'server-wrapper-api-key'
...@@ -23,6 +19,11 @@ config.fs = { ...@@ -23,6 +19,11 @@ config.fs = {
tmpPath: "/wrapper/tmp" tmpPath: "/wrapper/tmp"
}; };
config.paramTypes = {
TEXT: 'text',
SELECT: 'select'
};
config.paramUsageTypes = { config.paramUsageTypes = {
META: 'meta', //ei kasutata utiliidi parameetrina META: 'meta', //ei kasutata utiliidi parameetrina
STRING: 'string', //parameeter asendatakse väärtusega STRING: 'string', //parameeter asendatakse väärtusega
...@@ -33,7 +34,7 @@ config.log4js = { ...@@ -33,7 +34,7 @@ config.log4js = {
appenders: [ appenders: [
{ {
"type": "logLevelFilter", "type": "logLevelFilter",
"level": "ERROR", "level": "DEBUG",
"appender": { "appender": {
type: 'console', type: 'console',
layout: { layout: {
...@@ -53,7 +54,7 @@ config.log4js = { ...@@ -53,7 +54,7 @@ config.log4js = {
"level": "ERROR", "level": "ERROR",
"appender": { "appender": {
type: 'file', type: 'file',
filename: '/logs/wrapper.log', filename: __dirname + '/../wrapper.log',
layout: { layout: {
type: 'pattern', type: 'pattern',
pattern: "[%d] %[[%x{port}-%x{pid}][%5.5p]%] %c - %m", pattern: "[%d] %[[%x{port}-%x{pid}][%5.5p]%] %c - %m",
...@@ -69,48 +70,8 @@ config.log4js = { ...@@ -69,48 +70,8 @@ config.log4js = {
] ]
}; };
config.wrapper = { config.isAsyncParamDescription = {
id: null, // unique service identifier type: config.paramTypes.SELECT,
title: null,
description: '',
port: null,
class: null,
command: null,
requestConf: null
};
config.availableCommands = {
TOKENIZER: {
commandTemplate: 'python /wrapper/utils/picoutils/tokenizer.py -i [data] -o [output]'
},
MORFANALYSAATOR: {
commandTemplate: '/wrapper/utils/./morfanalyzer.sh [data]'
},
LAUSESTAJA: {
commandTemplate: '/wrapper/utils/./lausestaja.sh [data]'
},
OSALAUSESTAJA: {
commandTemplate: '/wrapper/utils/./osalausestaja.sh [data]'
},
MORFYHESTAJA: {
commandTemplate: '/wrapper/utils/./morfyhestaja.sh [data]'
},
PIND_SYN: {
commandTemplate: '/wrapper/utils/./pindsyn.sh [data]'
},
S6LT_SYN: {
commandTemplate: '/wrapper/utils/./s6ltsyn.sh [data]'
},
CONCAT: {
commandTemplate: 'cat [data]'
},
MORPH_TAGGER: {
commandTemplate: 'python /wrapper/utils/picoutils/morph_tagger.py -i [data] -o [output]'
}
};
var isAsyncParamValue = {
type: 'select',
options: ['0', '1'], options: ['0', '1'],
value: '1', value: '1',
usageType: config.paramUsageTypes.META, usageType: config.paramUsageTypes.META,
...@@ -124,8 +85,8 @@ var isAsyncParamValue = { ...@@ -124,8 +85,8 @@ var isAsyncParamValue = {
} }
}; };
var stringKeyValue = { config.stringKeyDescription = {
type: 'text', type: config.paramTypes.TEXT,
value: undefined, value: undefined,
usageType: config.paramUsageTypes.STRING, usageType: config.paramUsageTypes.STRING,
filter: null, filter: null,
...@@ -136,8 +97,8 @@ var stringKeyValue = { ...@@ -136,8 +97,8 @@ var stringKeyValue = {
} }
}; };
var fileKeyValue = { config.fileKeyDescription = {
type: 'text', type: config.paramTypes.TEXT,
value: undefined, value: undefined,
usageType: config.paramUsageTypes.FILE, usageType: config.paramUsageTypes.FILE,
filter: null, filter: null,
...@@ -148,18 +109,62 @@ var fileKeyValue = { ...@@ -148,18 +109,62 @@ var fileKeyValue = {
} }
}; };
config.wrapper = {
id: null, // unikaalne lühinimi
title: null, //Avalik nimi
description: '', //Kirjeldus
port: null, //port
class: null, //wrapperi failinimi wrapper kaustast, mida utiliidi käivitamiseks kasutatakse
command: null, // utiliidi käsurea käsk
requestConf: null, //Päringu seadistus
outputTypes: null, //teenuse väljundressursside kirjldus
sessionMaxLifetime: 600 // sessiooni maksimaalne kestvus
};
config.availableCommands = {
TOKENIZER: {
commandTemplate: 'python /var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/picoutils/tokenizer.py -i [data] -o [output]'
},
MORFANALYSAATOR: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./morfanalyzer.sh [data]'
},
LAUSESTAJA: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./lausestaja.sh [data]'
},
OSALAUSESTAJA: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./osalausestaja.sh [data]'
},
MORFYHESTAJA: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./morfyhestaja.sh [data]'
},
PIND_SYN: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./pindsyn.sh [data]'
},
S6LT_SYN: {
commandTemplate: '/var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/./s6ltsyn.sh [data]'
},
CONCAT: {
commandTemplate: 'cat [data]'
},
MORPH_TAGGER: {
commandTemplate: 'python /var/www/bitweb.ee/keeleliin.bitweb.ee/wrapper/utils/picoutils/morph_tagger.py -i [data] -o [output]'
}
};
config.availableWrappers = { config.availableWrappers = {
LAUSESTAJA: { LAUSESTAJA: {
title: 'Lausestaja', title: 'Lausestaja',
description: '', description: '',
id: 'lau', id: 'lau',
port: process.env.SERVER_PORT || 3001, port: 3001,
class: 'simpleLocalCommand', class: 'simpleLocalCommand',
command: config.availableCommands.LAUSESTAJA, command: config.availableCommands.LAUSESTAJA,
requestConf: { requestConf: {
requestBodyParamsMappings: { requestBodyParamsMappings: {
isAsync: isAsyncParamValue isAsync: config.isAsyncParamDescription
}, },
requestFiles: { requestFiles: {
content: { content: {
...@@ -182,12 +187,12 @@ config.availableWrappers = { ...@@ -182,12 +187,12 @@ config.availableWrappers = {
title: 'Morfoloogiline analüüs', title: 'Morfoloogiline analüüs',
description: '', description: '',
id: 'moa', id: 'moa',
port: process.env.SERVER_PORT || 3002, port: 3002,
class: 'simpleLocalCommand', class: 'simpleLocalCommand',
command: config.availableCommands.MORFANALYSAATOR, command: config.availableCommands.MORFANALYSAATOR,
requestConf: { requestConf: {
requestBodyParamsMappings: { requestBodyParamsMappings: {
isAsync: isAsyncParamValue isAsync: config.isAsyncParamDescription
}, },
requestFiles: { requestFiles: {
content: { content: {
...@@ -210,12 +215,12 @@ config.availableWrappers = { ...@@ -210,12 +215,12 @@ config.availableWrappers = {
title: 'Osalausestaja', title: 'Osalausestaja',
description: '', description: '',
id: 'osl', id: 'osl',
port: process.env.SERVER_PORT || 3003, port: 3003,
class: 'simpleLocalCommand', class: 'simpleLocalCommand',
command: config.availableCommands.OSALAUSESTAJA, command: config.availableCommands.OSALAUSESTAJA,
requestConf: { requestConf: {
requestBodyParamsMappings: { requestBodyParamsMappings: {
isAsync: isAsyncParamValue isAsync: config.isAsyncParamDescription
}, },
requestFiles: { requestFiles: {
content: { content: {
...@@ -238,12 +243,12 @@ config.availableWrappers = { ...@@ -238,12 +243,12 @@ config.availableWrappers = {
title: 'Morfoloogiline ühestamine (kitsenduste grammatika)', title: 'Morfoloogiline ühestamine (kitsenduste grammatika)',
description: '', description: '',
id: 'moy', id: 'moy',
port: process.env.SERVER_PORT || 3004, port: 3004,
class: 'simpleLocalCommand', class: 'simpleLocalCommand',
command: config.availableCommands.MORFYHESTAJA, command: config.availableCommands.MORFYHESTAJA,
requestConf: { requestConf: {
requestBodyParamsMappings: { requestBodyParamsMappings: {
isAsync: isAsyncParamValue isAsync: config.isAsyncParamDescription
}, },
requestFiles: { requestFiles: {
content: { content: {
...@@ -266,12 +271,12 @@ config.availableWrappers = { ...@@ -266,12 +271,12 @@ config.availableWrappers = {
title: 'Pindsüntaktiline analüüs', title: 'Pindsüntaktiline analüüs',
description: '', description: '',
id: 'pia', id: 'pia',
port: process.env.SERVER_PORT || 3005, port: 3005,
class: 'simpleLocalCommand', class: 'simpleLocalCommand',
command: config.availableCommands.PIND_SYN, command: config.availableCommands.PIND_SYN,
requestConf: { requestConf: {
requestBodyParamsMappings: { requestBodyParamsMappings: {
isAsync: isAsyncParamValue isAsync: config.isAsyncParamDescription
}, },
requestFiles: { requestFiles: {
content: { content: {
...@@ -294,12 +299,12 @@ config.availableWrappers = { ...@@ -294,12 +299,12 @@ config.availableWrappers = {
title: 'Sõltuvussüntaktiline analüüs (ja järeltöötlus)', title: 'Sõltuvussüntaktiline analüüs (ja järeltöötlus)',
description: '', description: '',
id: 's6a', id: 's6a',
port: process.env.SERVER_PORT || 3006, port: 3006,
class: 'simpleLocalCommand', class: 'simpleLocalCommand',
command: config.availableCommands.S6LT_SYN, command: config.availableCommands.S6LT_SYN,
requestConf: { requestConf: {
requestBodyParamsMappings: { requestBodyParamsMappings: {
isAsync: isAsyncParamValue isAsync: config.isAsyncParamDescription
}, },
requestFiles: { requestFiles: {
content: { content: {
...@@ -323,11 +328,11 @@ config.availableWrappers = { ...@@ -323,11 +328,11 @@ config.availableWrappers = {
title: 'Arhiivi lahtipakkija', title: 'Arhiivi lahtipakkija',
description: '', description: '',
id: 'uzip', id: 'uzip',
port: process.env.SERVER_PORT || 3007, port: 3007,
class: 'archiveExtractor', class: 'archiveExtractor',
requestConf: { requestConf: {
requestBodyParamsMappings: { requestBodyParamsMappings: {
isAsync: isAsyncParamValue isAsync: config.isAsyncParamDescription
}, },
requestFiles: { requestFiles: {
content: { content: {
...@@ -350,12 +355,12 @@ config.availableWrappers = { ...@@ -350,12 +355,12 @@ config.availableWrappers = {
title: 'Sõnestaja pipe', title: 'Sõnestaja pipe',
description: '', description: '',
id: 'tok', id: 'tok',
port: process.env.SERVER_PORT || 3008, port: 3008,
class: 'inputOutputLocalCommand', class: 'inputOutputLocalCommand',
command: config.availableCommands.TOKENIZER, command: config.availableCommands.TOKENIZER,
requestConf: { requestConf: {
requestBodyParamsMappings: { requestBodyParamsMappings: {
isAsync: isAsyncParamValue isAsync: config.isAsyncParamDescription
}, },
requestFiles: { requestFiles: {
content: { content: {
...@@ -377,12 +382,12 @@ config.availableWrappers = { ...@@ -377,12 +382,12 @@ config.availableWrappers = {
CONCAT: { CONCAT: {
title: 'Lihtne konkateneerija', title: 'Lihtne konkateneerija',
id: 'concat', id: 'concat',
port: process.env.SERVER_PORT || 3009, port: 3009,
class: 'simpleLocalCommand', class: 'simpleLocalCommand',
command: config.availableCommands.CONCAT, command: config.availableCommands.CONCAT,
requestConf: { requestConf: {
requestBodyParamsMappings: { requestBodyParamsMappings: {
isAsync: isAsyncParamValue isAsync: config.isAsyncParamDescription
}, },
requestFiles: { requestFiles: {
content: { content: {
...@@ -404,12 +409,12 @@ config.availableWrappers = { ...@@ -404,12 +409,12 @@ config.availableWrappers = {
MORPH_TAGGER: { MORPH_TAGGER: {
title: 'Morfoloogiline ühestaja pipe', title: 'Morfoloogiline ühestaja pipe',
id: 'tag', id: 'tag',
port: process.env.SERVER_PORT || 3010, port: 3010,
class: 'inputOutputLocalCommand', class: 'inputOutputLocalCommand',
command: config.availableCommands.MORPH_TAGGER, command: config.availableCommands.MORPH_TAGGER,
requestConf: { requestConf: {
requestBodyParamsMappings: { requestBodyParamsMappings: {
isAsync: isAsyncParamValue isAsync: config.isAsyncParamDescription
}, },
requestFiles: { requestFiles: {
content: { content: {
......
...@@ -44,7 +44,7 @@ function ServiceRequest( requestBody, requestFiles ) { ...@@ -44,7 +44,7 @@ function ServiceRequest( requestBody, requestFiles ) {
continue; continue;
} }
if(!value){ if(value === null || value === undefined){
value = mapping.value; value = mapping.value;
} }
......
...@@ -13,14 +13,6 @@ function InputOutputLocalCommand(){ ...