Commit 87a2dc1a authored by priit's avatar priit
Browse files

Mitme faili haldamise err

parent 85da787d
......@@ -10,4 +10,5 @@ tmp_tests/jmeter.log
tmp_tests/94megafile
tmp_tests/189megafile
keeleliin.log
coverage
\ No newline at end of file
coverage
wrapper_configs/local_global.js
\ No newline at end of file
......@@ -27,16 +27,17 @@ function LocalCommand( commandModel ) {
this._parseParams = function () {
for(index in this.templateParams){
this._parseOnIndex( index );
}
};
this._parseOnIndex = function (index) {
var propertyItem = this.templateParams[index];
var propertyKey = propertyItem.substr(1, (propertyItem.length - 2));
var value = keyValues[propertyKey];
var propertyItem = this.templateParams[index];
var propertyKey = propertyItem.substr(1, (propertyItem.length - 2));
var value = keyValues[propertyKey];
self._replacePropertyValue(propertyItem, value);
if(!value){
throw new Error('Value not detected for property ' + propertyKey);
}
self._replacePropertyValue(propertyItem, value);
}
};
this._replacePropertyValue = function (propertyItem, value) {
......
......@@ -8,7 +8,6 @@ function ServiceRequest( requestBody, requestFiles ) {
this.files = requestFiles;
var messages = null;
this.isValid = function(){
self._mapParams();
self._checkFiles();
......@@ -58,8 +57,7 @@ function ServiceRequest( requestBody, requestFiles ) {
this._checkFiles = function () {
for( var fileId in config.wrapper.requestConf.requestFiles ){
var file = this.files[fileId];
if(!file){
if(!self.files[fileId]){
self.setMessage(fileId, 'Nõutud faili ei saadetud');
}
}
......
......@@ -25,6 +25,24 @@ Session.prototype.setErrors = function(errors, path){
this.message = Session.messages.ERROR
};
Session.prototype.getFile = function( key ){
var fileValue = this.requestFiles[ key ];
if(Array.isArray(fileValue)){
return fileValue.pop();
}
return fileValue;
};
Session.prototype.getFiles = function( key ){
var fileValue = this.requestFiles[ key ];
if(Array.isArray(fileValue)){
return fileValue;
}
return [fileValue];
};
Session.messages = {
RUNNING: 'RUNNING',
OK: 'OK',
......
......@@ -26,7 +26,6 @@ function LocalExecutor() {
logger.debug(localCommand.command);
logger.debug(localCommand.commandParams);
logger.debug(response);
try {
var process = spawn(command, commandParams);
......@@ -55,6 +54,15 @@ function LocalExecutor() {
response.errors.push({util:data.toString()});
});
process.on('exit', function (code, signal) {
logger.error('Child process EXIT due to receipt of signal: ' + signal + ' code: ' + code);
if(code && code > 0){
response.isSuccess = false;
process.kill();
}
});
process.on('close', function (code, signal) {
logger.debug('child process terminated due to receipt of signal: ' + signal + ' code: ' + code);
callback(null, response);
......
......@@ -49,23 +49,39 @@ function SessionService() {
this._storeRequestFiles = function (session, files, cb) {
var tmpList = [];
for(var i in files){
tmpList.push(files[i]);
if(!files){
cb();
}
async.eachSeries(
tmpList,
files,
function (item, callback) {
var tmpFile = item;
var sessionFilePath = self.getNewFilePath(session.id);
FileUtil.mv(tmpFile.path, sessionFilePath, function(err){
if(err) return callback(err);
session.requestFiles[tmpFile.fieldname] = sessionFilePath;
callback();
});
if(Array.isArray(item)){
async.eachSeries(item, function (itemFile, innerCallback) {
var tmpFile = itemFile;
var sessionFilePath = self.getNewFilePath(session.id);
FileUtil.mv(tmpFile.path, sessionFilePath, function(err){
if(err) return callback(err);
if(session.requestFiles[tmpFile.fieldname] == undefined){
session.requestFiles[tmpFile.fieldname] = []
}
session.requestFiles[tmpFile.fieldname].push( sessionFilePath );
innerCallback();
});
}, function (err) {
callback(err);
});
} else {
var tmpFile = item;
var sessionFilePath = self.getNewFilePath(session.id);
FileUtil.mv(tmpFile.path, sessionFilePath, function(err){
if(err) return callback(err);
session.requestFiles[tmpFile.fieldname] = sessionFilePath;
callback();
});
}
},
function ( err ) {
cb(err);
......
var logger = require('log4js').getLogger('wrapper');
var logger = require('log4js').getLogger('simple_local_command_wrapper');
var config = require('./../config');
var localExecutor = require('./../src/service/executor/localExecutor');
var Session = require('../src/model/session');
......@@ -16,7 +16,10 @@ function SimpleLocalCommand(){
self.getCommandModel(session, function (err, model) {
logger.debug('GetCommandModel callback');
if(err) return callback(err);
if(err){
logger.error(err);
return callback(err);
}
localExecutor.execute( model, function ( err, response ) {
if(err) return callback(err);
......@@ -44,7 +47,8 @@ function SimpleLocalCommand(){
var model = new CommandModel();
model.serviceProperties.commandTemplate = config.wrapper.command.commandTemplate;
model.init( session );
model.setTextValue('data', session.requestFiles.content);
model.setTextValue('data', session.getFiles('content').join(' '));
//model.setTextValue('data', session.getFile('content'));
model.render(function (err) {
logger.debug('Render callback');
callback(err, model);
......
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