Commit 669143a5 authored by Indrek Jentson's avatar Indrek Jentson Committed by Indrek Jentson

Koodi parandused

Signed-off-by: default avatarIndrek Jentson <indrek.jentson@cgi.com>
parent e165c1f3
...@@ -3,7 +3,6 @@ keeleliin-wrapper-service.iml ...@@ -3,7 +3,6 @@ keeleliin-wrapper-service.iml
config.js config.js
node_modules node_modules
.idea .idea
dump.rdb
scan scan
tmp_tests/contentTokenizer.js tmp_tests/contentTokenizer.js
tmp_tests/jmeter.log tmp_tests/jmeter.log
...@@ -12,4 +11,5 @@ tmp_tests/189megafile ...@@ -12,4 +11,5 @@ tmp_tests/189megafile
keeleliin.log keeleliin.log
coverage coverage
global_config/local_global.js global_config/local_global.js
updateWrappers.sh updateWrappers.sh
\ No newline at end of file /wrapper.log
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
var server = require('./www/server'); var server = require('./www/server');
server.startCluster(1, function ( err ) { server.startCluster(1, function ( err ) {
console.log('Server started ' + process.pid); console.log('Server started ' + process.pid);
}); });
\ No newline at end of file
...@@ -68,8 +68,8 @@ config.serverUrl = 'http://localhost'; ...@@ -68,8 +68,8 @@ config.serverUrl = 'http://localhost';
config.wrapper = { //teenuse seadistus config.wrapper = { //teenuse seadistus
id: 'concat', // Unikaalne lühinimi id: 'concat', // Unikaalne lühinimi
title: 'Lihtne konjateneerija', //Avalik nimi title: 'Lihtne konkateneerija', //Avalik nimi
description: 'Konkateneerib etteantud failid üheks suureks failiks', //Kirjeldus description: 'Liidab etteantud failid üheks suureks failiks', //Kirjeldus
port: 3002, // port port: 3002, // port
class: 'simpleLocalCommand', // wrapperi failinimi wrapper kaustast, mida utiliidi käivitamiseks kasutatakse class: 'simpleLocalCommand', // wrapperi failinimi wrapper kaustast, mida utiliidi käivitamiseks kasutatakse
command: { commandTemplate: 'cat [data]' }, // utiliidi käsurea käsk command: { commandTemplate: 'cat [data]' }, // utiliidi käsurea käsk
...@@ -80,7 +80,7 @@ config.wrapper = { //teenuse seadistus ...@@ -80,7 +80,7 @@ config.wrapper = { //teenuse seadistus
options: ['0', '1'], // Võimalikud sobivad väärtused options: ['0', '1'], // Võimalikud sobivad väärtused
value: '1', // Soovituslik vaikeväärtus value: '1', // Soovituslik vaikeväärtus
filter: function (value) { // parameerile rakendatav filter. Antud juhul viiaks väärtus boolean kujule filter: function (value) { // parameerile rakendatav filter. Antud juhul viiaks väärtus boolean kujule
return value == 1; return value === 1;
}, },
required: true, // kas mittetühi väärtus on nõutud required: true, // kas mittetühi väärtus on nõutud
allowEmpty: false, // kas parameeter peab olema saadetud allowEmpty: false, // kas parameeter peab olema saadetud
......
...@@ -69,7 +69,7 @@ config.isAsyncParamDescription = { ...@@ -69,7 +69,7 @@ config.isAsyncParamDescription = {
options: ['0', '1'], options: ['0', '1'],
value: '1', value: '1',
filter: function (value) { filter: function (value) {
return value == 1; return value === 1;
}, },
required: true, required: true,
allowEmpty: false, allowEmpty: false,
......
This diff is collapsed.
{ {
"name": "keeleliin-wrapper-service", "name": "keeleliin-wrapper-service",
"version": "0.0.0", "version": "1.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"start": "node ./app.js", "start": "node ./app.js",
"test": "./node_modules/.bin/istanbul test _mocha -- -R spec --timeout 15000" "test": "mocha"
}, },
"dependencies": { "dependencies": {
"JSONStream": "^1.0.4", "JSONStream": "^1.0.4",
"async": "^1.4.0", "async": "^1.4.0",
"body-parser": "~1.12.4", "body-parser": "^1.18.3",
"debug": "~2.2.0", "debug": "^4.1.1",
"express": "~4.12.4", "express": "~4.16.0",
"fs": "0.0.2", "fs": "0.0.2",
"graceful-fs": "^4.1.2", "graceful-fs": "^4.1.2",
"is-gzip": "^1.0.0", "is-gzip": "^1.0.0",
"is-tar": "^1.0.0", "is-tar": "^1.0.0",
"is-zip": "^1.0.0", "is-zip": "^1.0.0",
"istextorbinary": "^1.0.2", "istextorbinary": "^1.0.2",
"jade": "~1.9.2",
"log4js": "^0.6.26", "log4js": "^0.6.26",
"mime": "^1.3.4", "mime": "^1.3.4",
"mkdirp": "~0.5.0", "mkdirp": "~0.5.0",
"morgan": "~1.5.3", "morgan": "~1.9.0",
"multer": "0.1.6", "multer": "0.1.6",
"node-schedule": "^0.2.9", "node-schedule": "^0.2.9",
"nodejs-disks": "^0.2.1", "pug": "^2.0.3",
"nodemailer": "^1.4.0",
"randomstring": "^1.0.5", "randomstring": "^1.0.5",
"recursive-readdir": "^1.2.1", "recursive-readdir": "^2.2.2",
"redis": "^0.12.1", "redis": "^0.12.1",
"request": "^2.57.0", "request": "^2.57.0",
"rimraf": "^2.4.0", "rimraf": "^2.4.0",
...@@ -37,8 +35,9 @@ ...@@ -37,8 +35,9 @@
}, },
"devDependencies": { "devDependencies": {
"assert": "^1.3.0", "assert": "^1.3.0",
"istanbul": "^0.3.15", "istanbul": "^0.4.5",
"mocha": "^5.2.0",
"should": "^7.0.1", "should": "^7.0.1",
"supertest": "^1.0.1" "supertest": "^3.3.0"
} }
} }
...@@ -20,7 +20,7 @@ function LocalCommand( commandModel ) { ...@@ -20,7 +20,7 @@ function LocalCommand( commandModel ) {
self._parseParams(); self._parseParams();
var paramsArray = commandParts.slice(commandParts); var paramsArray = commandParts.slice(commandParts);
self.command = paramsArray.shift(); self.command = paramsArray.shift();
self.commandParams = paramsArray.filter(function (value) { return value != '' && value != null && value != undefined; }); self.commandParams = paramsArray.filter(function (value) { return value !== '' && value != null && value !== undefined; });
return self; return self;
}; };
...@@ -45,7 +45,7 @@ function LocalCommand( commandModel ) { ...@@ -45,7 +45,7 @@ function LocalCommand( commandModel ) {
var newCommandParts = []; var newCommandParts = [];
for (i in commandParts) { for (i in commandParts) {
if( commandParts[i] == propertyItem){ if( commandParts[i] === propertyItem){
if(Array.isArray(value)){ if(Array.isArray(value)){
for(j in value){ for(j in value){
newCommandParts.push(value[j]); newCommandParts.push(value[j]);
......
...@@ -37,12 +37,12 @@ function ServiceRequest( requestBody, requestFiles ) { ...@@ -37,12 +37,12 @@ function ServiceRequest( requestBody, requestFiles ) {
value = mapping.filter(value); value = mapping.filter(value);
} }
if(mapping.required == true && value == undefined){ if(mapping.required === true && value === undefined){
self.setMessage(property, 'Väli on nõutud'); self.setMessage(property, 'Väli on nõutud');
continue; continue;
} }
if(mapping.allowEmpty == false && (value === null || value === '') ){ if(mapping.allowEmpty === false && (value === null || value === '') ){
self.setMessage(property, 'Väli on täitmata'); self.setMessage(property, 'Väli on täitmata');
continue; continue;
} }
...@@ -68,12 +68,12 @@ function ServiceRequest( requestBody, requestFiles ) { ...@@ -68,12 +68,12 @@ function ServiceRequest( requestBody, requestFiles ) {
var fileItem = self.files[fileId]; var fileItem = self.files[fileId];
if(!fileItem){ if(!fileItem){
logger.error('Nõutud faili ei saadetud' + fileId, self.files); logger.error('Nõutud faili ei saadetud: ' + fileId, self.files);
self.setMessage(fileId, 'Nõutud faili ei saadetud'); self.setMessage(fileId, 'Nõutud faili ei saadetud');
return innerCb(); return innerCb();
} }
if(requestFile.isList == false && Array.isArray( fileItem )){ if(requestFile.isList === false && Array.isArray( fileItem )){
self.setMessage(fileId, 'Lubatud on ainult 1 fail'); self.setMessage(fileId, 'Lubatud on ainult 1 fail');
return innerCb(); return innerCb();
} }
...@@ -81,16 +81,15 @@ function ServiceRequest( requestBody, requestFiles ) { ...@@ -81,16 +81,15 @@ function ServiceRequest( requestBody, requestFiles ) {
if(requestFile.sizeLimit > 0){ if(requestFile.sizeLimit > 0){
var limitLeft = requestFile.sizeLimit; var limitLeft = requestFile.sizeLimit;
var stat = fs.statSync(fileItem.path);
limitLeft = limitLeft - stat.size;
if( Array.isArray( fileItem ) ){ if( Array.isArray( fileItem ) ){
for(i in fileItem){ for(i in fileItem){
var fileItemItem = fileItem[i]; var fileItemItem = fileItem[i];
var stat = fs.statSync(fileItemItem.path); stat = fs.statSync(fileItemItem.path);
limitLeft = limitLeft - stat.size; limitLeft = limitLeft - stat.size;
} }
} else {
var stat = fs.statSync(fileItem.path);
limitLeft = limitLeft - stat.size;
} }
if(limitLeft < 0){ if(limitLeft < 0){
......
...@@ -30,7 +30,7 @@ var CleanerService = function () { ...@@ -30,7 +30,7 @@ var CleanerService = function () {
fs.readdir(folder, function(err, files) { fs.readdir(folder, function(err, files) {
logger.debug('readFolder'); logger.debug('readFolder');
if(files != undefined && files.length > 0){ if(files !== undefined && files.length > 0){
self.checkOnIndex(0, files, folder, function (err) { self.checkOnIndex(0, files, folder, function (err) {
if(err){ if(err){
return logger.error(err); return logger.error(err);
...@@ -65,7 +65,7 @@ var CleanerService = function () { ...@@ -65,7 +65,7 @@ var CleanerService = function () {
return continueScan(); return continueScan();
} }
if(stat == undefined){ if(stat === undefined){
logger.error('Stat is undefined for: ' + filePath); logger.error('Stat is undefined for: ' + filePath);
return continueScan(); return continueScan();
} }
......
...@@ -20,7 +20,7 @@ var DaoService = function(){ ...@@ -20,7 +20,7 @@ var DaoService = function(){
this.set = function(key, value, cb){ this.set = function(key, value, cb){
this.client.set(prefix + key, JSON.stringify(value), function (err, reply) { this.client.set(prefix + key, JSON.stringify(value), function (err, reply) {
if(cb != undefined){ if(cb !== undefined){
self.client.expire(prefix + key, config.wrapper.sessionMaxLifetime ); self.client.expire(prefix + key, config.wrapper.sessionMaxLifetime );
cb(err, reply); cb(err, reply);
} }
...@@ -30,7 +30,7 @@ var DaoService = function(){ ...@@ -30,7 +30,7 @@ var DaoService = function(){
this.get = function(key, cb){ this.get = function(key, cb){
this.client.get(prefix + key, function(err, reply) { this.client.get(prefix + key, function(err, reply) {
if(cb != undefined){ if(cb !== undefined){
if(err){ if(err){
return cb(err); return cb(err);
} }
...@@ -42,7 +42,7 @@ var DaoService = function(){ ...@@ -42,7 +42,7 @@ var DaoService = function(){
this.delete = function(key, cb){ this.delete = function(key, cb){
this.client.del(prefix + key, function (err, reply) { this.client.del(prefix + key, function (err, reply) {
if(cb != undefined){ if(cb !== undefined){
cb(err, reply); cb(err, reply);
} }
} ); } );
......
...@@ -86,7 +86,7 @@ function LocalExecutor() { ...@@ -86,7 +86,7 @@ function LocalExecutor() {
process.on('close', function (code, signal) { process.on('close', function (code, signal) {
logger.debug('child process terminated due to receipt of signal: ' + signal + ' code: ' + code); logger.debug('child process terminated due to receipt of signal: ' + signal + ' code: ' + code);
if(signal == 'SIGKILL'){ if(signal === 'SIGKILL'){
response.isSuccess = false; response.isSuccess = false;
response.errors.push({util:' Utiliidi töö katkestati!'}); response.errors.push({util:' Utiliidi töö katkestati!'});
} }
......
...@@ -12,7 +12,7 @@ var InstallService = function() { ...@@ -12,7 +12,7 @@ var InstallService = function() {
var wrapper = config.wrapper; var wrapper = config.wrapper;
var serviceConfig = self.getConfiguration(); var serviceConfig = self.getConfiguration();
if(!config.integration || config.integration.length == 0){ if(!config.integration || config.integration.length === 0){
return cb('Servereid ei ole seadistatud'); return cb('Servereid ei ole seadistatud');
} }
......
...@@ -71,7 +71,7 @@ function SessionService() { ...@@ -71,7 +71,7 @@ function SessionService() {
var sessionFilePath = self.getNewFilePath(session.id); var sessionFilePath = self.getNewFilePath(session.id);
FileUtil.mv(tmpFile.path, sessionFilePath, function(err){ FileUtil.mv(tmpFile.path, sessionFilePath, function(err){
if(err) return callback(err); if(err) return callback(err);
if(session.requestFiles[tmpFile.fieldname] == undefined){ if(session.requestFiles[tmpFile.fieldname] === undefined){
session.requestFiles[tmpFile.fieldname] = [] session.requestFiles[tmpFile.fieldname] = []
} }
session.requestFiles[tmpFile.fieldname].push( sessionFilePath ); session.requestFiles[tmpFile.fieldname].push( sessionFilePath );
...@@ -195,11 +195,11 @@ function SessionService() { ...@@ -195,11 +195,11 @@ function SessionService() {
response.errors = session.errors; response.errors = session.errors;
} }
if (session.message == Session.messages.RUNNING) { if (session.message === Session.messages.RUNNING) {
response.recheckInterval = session.recheckInterval; response.recheckInterval = session.recheckInterval;
} }
if (session.message != Session.messages.OK) { if (session.message !== Session.messages.OK) {
return callback(null, {response: response}); return callback(null, {response: response});
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
var logger = require('log4js').getLogger('statistics_service'); var logger = require('log4js').getLogger('statistics_service');
var async = require('async'); var async = require('async');
var os = require('os'); var os = require('os');
var njds = require('nodejs-disks'); // var njds = require('nodejs-disks');
function StatisticsService() { function StatisticsService() {
var self = this; var self = this;
......
...@@ -14,7 +14,7 @@ function WrapperService() { ...@@ -14,7 +14,7 @@ function WrapperService() {
return callback(err); return callback(err);
} }
if (session.isAsync == true) { if (session.isAsync === true) {
self.getServiceResponse(session.id, callback); self.getServiceResponse(session.id, callback);
} }
...@@ -28,7 +28,7 @@ function WrapperService() { ...@@ -28,7 +28,7 @@ function WrapperService() {
sessionService.closeSession(session, function (err, session) { sessionService.closeSession(session, function (err, session) {
logger.debug('Sessioon on lõpetanud ja savestatud. isAsync:' + session.isAsync); logger.debug('Sessioon on lõpetanud ja savestatud. isAsync:' + session.isAsync);
if (session.isAsync == false) { if (session.isAsync === false) {
logger.debug('Send response'); logger.debug('Send response');
if(err){ if(err){
return callback(err); return callback(err);
...@@ -91,7 +91,7 @@ function WrapperService() { ...@@ -91,7 +91,7 @@ function WrapperService() {
return callback(err); return callback(err);
} }
var processor = new Processor(); var processor = new Processor();
if(processor.kill != undefined){ if(processor.kill !== undefined){
processor.kill( session, function (err, response) { processor.kill( session, function (err, response) {
callback(null, mapResponse(err, response)); callback(null, mapResponse(err, response));
}); });
......
...@@ -9,7 +9,7 @@ var assert = require('assert'); ...@@ -9,7 +9,7 @@ var assert = require('assert');
var request = require('supertest'); var request = require('supertest');
describe('Routing', function() { describe('Routing', function() {
var url = 'http://127.0.0.1:' + config.port; var url = 'http://127.0.0.1:' + config.wrapper.port;
before(function(done) { before(function(done) {
server.startInstance( function(){ server.startInstance( function(){
...@@ -62,7 +62,7 @@ describe('Routing', function() { ...@@ -62,7 +62,7 @@ describe('Routing', function() {
throw err; throw err;
} }
res.body.should.have.property('errors'); res.body.should.have.property('errors');
res.body.errors.session.should.equal('Sessiooni ei leitud'); res.body.errors.should.equal('Sessiooni ei leitud');
done(); done();
}) })
}); });
...@@ -88,10 +88,11 @@ describe('Routing', function() { ...@@ -88,10 +88,11 @@ describe('Routing', function() {
throw err; throw err;
} }
res.body.response.should.have.property('sessionId'); res.body.should.have.property('success');
res.body.response.message.should.equal('OK'); res.body.success.should.equal(false);
res.body.response.should.have.property('pipecontent'); res.body.should.have.property('errors');
res.body.response.pipecontent.should.not.equal(undefined); res.body.errors.should.have.property('content');
res.body.errors.content.should.equal('Nõutud faili ei saadetud');
done(); done();
}); });
}); });
...@@ -118,7 +119,8 @@ describe('Routing', function() { ...@@ -118,7 +119,8 @@ describe('Routing', function() {
} }
res.body.should.have.property('errors'); res.body.should.have.property('errors');
res.body.errors.should.have.property('pipecontent'); res.body.errors.should.have.property('content');
res.body.errors.content.should.equal('Nõutud faili ei saadetud');
done(); done();
}); });
}); });
......
...@@ -10,9 +10,9 @@ var fs = require('fs'); ...@@ -10,9 +10,9 @@ var fs = require('fs');
describe('File util', function() { describe('File util', function() {
var tmpPath = config.service.staticParams.tmpPath; var tmpPath = config.fs.tmpPath;
var mvSource = tmpPath + 'mvSource'; var mvSource = tmpPath + '/mvSource';
var mvTarget = tmpPath + 'mvTarget'; var mvTarget = tmpPath + '/mvTarget';
before(function(done) { before(function(done) {
done(); done();
......
...@@ -15,7 +15,7 @@ var encoding = 'utf-8'; ...@@ -15,7 +15,7 @@ var encoding = 'utf-8';
var i = 0; var i = 0;
function loop(cb){ function loop(cb){
i++; i++;
if(i % 100000 == 0){ if(i % 100000 === 0){
console.log(i); console.log(i);
} }
if(i < 2300000){ if(i < 2300000){
...@@ -42,7 +42,7 @@ function parse(){ ...@@ -42,7 +42,7 @@ function parse(){
var index = 0; var index = 0;
parser.on('data', function (obj) { parser.on('data', function (obj) {
index++; index++;
if(index % 100000 == 0){ if(index % 100000 === 0){
console.log(index); console.log(index);
console.log(obj); // whatever you will do with each JSON object console.log(obj); // whatever you will do with each JSON object
} }
......
...@@ -45,7 +45,7 @@ function ArchiveExtractor() { ...@@ -45,7 +45,7 @@ function ArchiveExtractor() {
logger.debug('Check for callback. count:' + count + ' isClosed: ' + isClosed); logger.debug('Check for callback. count:' + count + ' isClosed: ' + isClosed);
if (count == 0 && isClosed == true) { if (count === 0 && isClosed === true) {
session.message = Session.messages.OK; session.message = Session.messages.OK;
return callback(null, session); return callback(null, session);
} }
...@@ -58,7 +58,7 @@ function ArchiveExtractor() { ...@@ -58,7 +58,7 @@ function ArchiveExtractor() {
.pipe(unzip.Parse()) .pipe(unzip.Parse())
.on('entry', function(entry) { .on('entry', function(entry) {
count++; count++;
var isFile = ('File' == entry.type); var isFile = ('File' === entry.type);
var savePath = SessionService.getStorePath(session.id); var savePath = SessionService.getStorePath(session.id);
var fullpath = path.join(savePath, entry.path); var fullpath = path.join(savePath, entry.path);
......
...@@ -17,7 +17,11 @@ var bodyParser = require('body-parser'); ...@@ -17,7 +17,11 @@ var bodyParser = require('body-parser');
var multer = require('multer'); var multer = require('multer');
var cluster = require('cluster'); var cluster = require('cluster');
var http = require('http'); var http = require('http');
var config = require('./../config'); try {
var config = require('./../config');
} catch (e) {
console.error('Can not read configuration: ' + e.toString());
}
var controllers = require('./../controllers/index'); var controllers = require('./../controllers/index');
var routerMiddleware = require('./../middlewares/router'); var routerMiddleware = require('./../middlewares/router');
var errorhandlerMiddleware = require('./../middlewares/errorhandler'); var errorhandlerMiddleware = require('./../middlewares/errorhandler');
...@@ -27,7 +31,7 @@ var cleanerService = require('./../src/service/cleanerService'); ...@@ -27,7 +31,7 @@ var cleanerService = require('./../src/service/cleanerService');
var installService = require('./../src/service/integration/installService'); var installService = require('./../src/service/integration/installService');