Commit 97ab1cc8 authored by Indrek Jentson's avatar Indrek Jentson

Runtime-check teenusele lisatud serveri ühenduse kontroll

Signed-off-by: Indrek Jentson's avatarIndrek Jentson <indrek.jentson@ut.ee>
parent af3f34b9
......@@ -33,6 +33,13 @@ router.get('/', function(req, res) {
logger.debug('msg: ' + JSON.stringify(msg));
results.push(msg);
return results;
}).then(function(results){
logger.debug('check 4');
return checker.checkServer();
}).then(function(msg){
logger.debug('msg: ' + JSON.stringify(msg));
results.push(msg);
return results;
}).then(function (results){
logger.debug('publish, R is ' + (results?results.length:'?'));
logger.debug('results: ' + (results?JSON.stringify(results):'?'))
......
{
"name": "keeleliin-wrapper-service",
"version": "1.1.1",
"version": "1.1.2",
"private": true,
"scripts": {
"start": "node ./app.js",
......
......@@ -73,6 +73,21 @@ var CheckService = function(){
});
}
this.checkServer = function() {
return new Promise( function(resolve, reject) {
try {
request.get(config.serverUrl + ':3000', function(err, replay) {
if (err) resolve({type:'ERR', msg: 'ühendus serveriga ' + config.serverUr + ' ei tööta: ' + err});
else {
resolve({type:'OK', msg: 'ühendus serveriga ' + config.serverUr + ' töötab'});
}
});
} catch (err) {
resolve({type:'ERR', msg:err.message});
}
});
}
this.checkTemplate = function() {
return new Promise( function(resolve, reject) {
try {
......
......@@ -17,6 +17,7 @@ var InstallService = function() {
}
var messages = [];
logger.debug(config.integration);
async.each(config.integration, function (serverConf, innerCb) {
......
......@@ -27,7 +27,7 @@ function WrapperService() {
}
sessionService.closeSession(session, function (err, session) {
logger.debug('Sessioon on lõpetanud ja savestatud. isAsync:' + session.isAsync);
logger.debug('Sessioon on lõpetanud ja salvestatud. isAsync:' + session.isAsync);
if (session.isAsync === false) {
logger.debug('Send response');
if(err){
......
......@@ -19,7 +19,7 @@ describe('Services', function() {
buildData = function(body, fileName) {
var form = {};
form['body'] = body;
form['body'] = JSON.stringify(body);
var file = { key: 'content', path: fileName };
var attachment = fs.createReadStream( fileName );
......@@ -50,13 +50,13 @@ describe('Services', function() {
var tmpPath = config.fs.tmpPath;
var source = tmpPath + '/test.txt';
fs.writeFileSync(source, 'Faili sisu');
var formData = buildData(JSON.stringify(body), source);
var formData = buildData(body, source);
request
.post({"url":url+'/api/v1/service', formData:formData}, function(err,res,body) {
if (err) {
throw err;
}
// console.log('res: '+JSON.stringify(res));
console.log('sync res: '+JSON.stringify(res));
var body = JSON.parse(res.body);
body.response.should.have.property('success');
body.response.success.should.equal(true);
......@@ -78,61 +78,20 @@ describe('Services', function() {
var tmpPath = config.fs.tmpPath;
var source = tmpPath + '/test.txt';
fs.writeFileSync(source, 'Faili sisu');
var formData = buildData(JSON.stringify(body), source);
var formData = buildData(body, source);
console.log('async form: '+JSON.stringify(formData));
request
.post({"url":url+'/api/v1/service', formData:formData}, function(err,res,body) {
if (err) {
throw err;
}
// console.log('res: '+JSON.stringify(res));
console.log('async res: '+JSON.stringify(res));
var body = JSON.parse(res.body);
body.response.should.have.property('success');
body.response.success.should.equal(true);
done();
});
/*
request(url)
.post('/api/v1/service')
.field('body', body)
.attach('files', source)
.expect('Content-Type', /json/)
.expect(200) //Status code
.end(function(err,res) {
if (err) {
throw err;
}
res.body.should.have.property('success');
if (res.body.success) {
res.body.should.have.property('response');
res.body.response.should.have.property('sessionId');
res.body.response.message.should.equal('RUNNING');
res.body.response.should.not.have.property('pipecontent');
var sessionId = res.body.response.serviceId;
setTimeout(function () {
request(url)
.get('/api/v1/service/' + sessionId)
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) {
throw err;
}
res.body.should.not.have.property('errors');
res.body.response.message.should.equal('OK');
res.body.response.should.have.property('pipecontent');
done();
});
}, 5000);
} else {
console.log('THIS is NOT working :(');
done()
};
});
*/
});
});
});
\ No newline at end of file
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