Commit 0b13eade authored by priit's avatar priit
Browse files

Error first

parent 02f5b8ef
......@@ -8,4 +8,5 @@ scan
tests/contentTokenizer.js
tests/jmeter.log
tests/94megafile
tests/189megafile
\ No newline at end of file
tests/189megafile
keeleliin.log
\ No newline at end of file
......@@ -18,12 +18,22 @@ var routerMiddleware = require('./middlewares/router');
var errorhandlerMiddleware = require('./middlewares/errorhandler');
app.set('views', path.join(__dirname, 'views'));// view engine setup
app.set('view engine', 'jade');// view engine setup
log4js.configure({
appenders: [
{ type: 'console' },
{ type: 'console',
layout: {
type: 'pattern',
pattern: "[%d] [%[%x{pid}] [%5.5p%]] - %m",
tokens: {
pid: process.pid
}
}
},
{ type: 'file', filename: 'keeleliin.log' }
]
});
var log4jsLogger = log4js.getLogger('app_js');
app.use(logger('dev'));
......@@ -39,19 +49,20 @@ app.use(errorhandlerMiddleware.error404);
* Create HTTP server.
*/
var numCPUs = require('os').cpus().length;
log4jsLogger.debug('NumCPUs: ' + numCPUs);
numCPUs = 1; //todo delete
///
if (cluster.isMaster) {
log4jsLogger.debug('NumCPUs: ' + numCPUs);
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
log4jsLogger.info('worker ' + worker.process.pid + ' died; Code' + code + '; Signal: ' + signal);
log4jsLogger.info('worker ' + worker.process.pid + ' died; Code: ' + code + '; Signal: ' + signal);
});
} else {
// Workers can share any TCP connection
// In this case its a HTTP server
var port = normalizePort(config.port);
app.set('port', port);
var server = http.createServer(app);
......@@ -107,7 +118,7 @@ function onError(error) {
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
log4jsLogger.debug('Listening on ' + bind);
log4jsLogger.debug('Listening on ' + bind + ' process: ' + process.pid );
}
module.exports = app;
\ No newline at end of file
......@@ -15,6 +15,7 @@ router.post('/', function ( req, res ) {
var wrapperService = new WrapperService();
wrapperService.execute( serviceRequest.getData() , function (err, data) {
if(err) return res.send({errors: err});
res.send(data);
});
});
......@@ -23,6 +24,7 @@ router.get('/:instanceId', function(req, res) {
var wrapperService = new WrapperService();
wrapperService.getServiceResponse(req.params.instanceId, function (err, data) {
if(err) return res.send({errors: err});
res.send(data);
});
});
......
......@@ -42,6 +42,8 @@ function CommandModel(){
this._storeToFile = function (index, callback) {
var fileValue = fileValues[index];
sessionService.storeToFile(self.session.id, fileValue['value'], function (err, path) {
if(err) return callback(err);
self.keyValues[fileValue['key']] = path;
index = index + 1;
......
......@@ -43,7 +43,7 @@ var DaoService = function(){
logger.debug('Got redis data');
logger.debug(reply);
if(cb != undefined){
return cb(reply);
return cb(null, reply);
}
});
};
......
......@@ -20,10 +20,10 @@ function LocalExecutor() {
var localCommand = new LocalCommand(commandModel);
localCommand.generateLocalCommand();
self.executeLocalCommand(localCommand, response, callback);
self._executeLocalCommand(localCommand, response, callback);
};
this.executeLocalCommand = function (localCommand, response, callback) {
this._executeLocalCommand = function (localCommand, response, callback) {
var spawn = require('child_process').spawn;
var command = localCommand.command;
......@@ -34,10 +34,10 @@ function LocalExecutor() {
logger.debug(response);
var process = spawn(command, commandParams);
self.run(response, process, callback);
self._run(response, process, callback);
};
this.run = function (response, process, callback) {
this._run = function (response, process, callback) {
var outputStream = fs.createWriteStream(response.stdOutPath, {flags: 'a'});
process.stdout.pipe(outputStream);
......
......@@ -15,7 +15,9 @@ function SessionService() {
this.getSession = function (sessionId, callback) {
daoService.get(sessionId, function (session) {
daoService.get(sessionId, function (err, session) {
if(err) return callback(err);
if (session == null) {
session = new Session(sessionId);
}
......@@ -52,6 +54,7 @@ function SessionService() {
session.isFinished = true;
self.storeToFile(session.id, JSON.stringify( output ), function (err, path) {
if(err) return callback(err);
session.outputPath = path;
self.saveSession(session, callback);
});
......@@ -83,10 +86,10 @@ function SessionService() {
this.removeSession = function (sessionId, callback) {
self._removeStorage(self.getStorePath(sessionId), function () {
console.log('Session file storage removed');
daoService.delete(sessionId, function () {
logger.debug('Session file storage removed');
daoService.delete(sessionId, function (err) {
logger.debug('Session redis storage removed');
callback();
callback(err);
});
})
};
......
......@@ -9,6 +9,7 @@ function WrapperService() {
this.execute = function(serviceRequest, callback) {
self._initSession(serviceRequest, function (err, session) {
if(err) return callback(err);
if (session.isAsync == true) {
self.getServiceResponse(session.id, callback);
......@@ -17,13 +18,16 @@ function WrapperService() {
var Processor = require(__base + '/wrapper/' + config.service.staticOptions.wrapper);
var processor = new Processor();
processor.process(serviceRequest, session, function ( error, session, finalPipecontent ) {
processor.process(serviceRequest, session, function ( err, session, finalPipecontent ) {
if(err) return callback(err);
sessionService.closeSession(session, finalPipecontent, function (err, session) {
logger.debug('Sessioon on lõpetanud ja savestatud');
if (session.isAsync == false) {
if (error) return callback(error);
if(err) return callback(err);
self.getServiceResponse(session.id, callback);
}
......@@ -35,11 +39,14 @@ function WrapperService() {
this._initSession = function(serviceRequest, callback){
sessionService.getSession( serviceRequest.service.meta.sessionId, function(err, session){
if(err) return callback(err);
session.message = Session.messages.RUNNING;
session.success = true;
session.isAsync = serviceRequest.service.meta.isAsync;
session.isFinished = false;
sessionService.saveSession(session, function(){
sessionService.saveSession(session, function(err){
if(err) return callback(err);
return callback(null, session);
});
});
......@@ -47,6 +54,7 @@ function WrapperService() {
this.getServiceResponse = function (instanceId, callback) {
sessionService.getSession(instanceId, function (err, session) {
if(err) return callback(err);
sessionService.getApiResponse(session, callback);
});
};
......
......@@ -15,12 +15,15 @@ function ContentTokenizer(){
var sourceText = new Buffer(pipeContent.content, 'base64').toString();
self.getCommandModel(session, sourceText, function (err, model) {
executorService.execute( model, function ( error, response ) {
if(err) return callback(err);
executorService.execute( model, function ( err, response ) {
if(err) return callback(err);
/* response = { isSuccess: BOOLEAN, stdOutPath: STRING, outputPaths: { key: value, ...} } */
logger.debug('Väline programm on lõpetanud');
fs.readFile(response.outputPaths.outputPath, function (err, output) {
if(err) return callback(err);
var wrapperOutput = output.toString();
var outputStrings = wrapperOutput.split("\n");
var tokens = [];
......
Supports Markdown
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