Commit 025f2666 authored by Indrek Jentson's avatar Indrek Jentson

Lisatud runtime-check teenus

Signed-off-by: Indrek Jentson's avatarIndrek Jentson <indrek.jentson@ut.ee>
parent a97d5de3
var logger = require('log4js').getLogger('check_controller');
var express = require('express');
var router = express.Router();
var checker = require(__base + '/src/service/checkService');
var config = require(__base + 'config');
router.get('/', function(req, res) {
var makeCheck = function () {
var results = [];
new Promise(function(resolve, reject){
logger.debug('check 0');
resolve(results);
}).then(function(results){
logger.debug('check 1');
return checker.checkStorages(config.fs.tmpPath);
}).then(function(msg){
logger.debug('msg: ' + JSON.stringify(msg));
results.push(msg);
return results;
}).then(function(results){
logger.debug('check 2');
return checker.checkStorages(config.fs.storagePath);
}).then(function(msg){
logger.debug('msg: ' + JSON.stringify(msg));
results.push(msg);
return results;
}).then(function(results){
logger.debug('check 3');
return checker.checkDao();
}).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):'?'))
res.render('check', {
title: 'Diagnostika: ' + config.wrapper.title,
results: (results?results:[]),
});
}).catch(function(error) {
logger.error(error.message);
});
}
makeCheck();
});
module.exports = router;
......@@ -4,6 +4,7 @@ var config = require(__base + 'config');
router.use('/api/v1/service', require(__base + 'controllers/api/v1/service'));
router.use('/api/v1/statistics', require(__base + 'controllers/api/v1/statistics'));
router.use('/api/v1/check', require(__base + 'controllers/api/v1/check'));
/* GET home page. Service description from config */
router.get('/', function( req, res ) {
......
var logger = require('log4js').getLogger('check_service');
var redis = require('redis');
var config = require(__base + 'config');
var FileUtil = require(__base +'/src/util/file');
var fs = require('fs');
var daoService = require('./daoService');
var CheckService = function(){
var self = this;
this.checkStorages = function(path) {
return new Promise( function(resolve, reject) {
try {
var mvSource = path + '/mvSource';
var mvTarget = path + '/mvTarget';
fs.writeFileSync(mvSource, 'Faili sisu');
if(!fs.existsSync(mvSource))
resolve({type:'ERR', msg:'faili kirjutamine kataloogi ' + path + ' ebaõnnestus'});
else {
// kontrollime kopeerimist
fs.unlink(mvTarget, function () {
if(fs.existsSync(mvTarget))
resolve({type:'ERR', msg:'kopeeritav fail ' + mvTarget + ' on juba olemas'});
else {
FileUtil.cp(mvSource, mvTarget, function(){
if(!fs.existsSync(mvTarget))
resolve({type:'ERR', msg:'faili kopeerimine kataloogi ' + path + ' ebaõnnestus'});
else {
fs.unlink(mvTarget, function () {
resolve({type:'OK', msg:'faili kopeerimine ja kustutamine kataloogis ' + path + ' õnnestus'});
});
}
});
}
});
}
} catch (err) {
resolve({type:'ERR', msg:err.message});
}
});
}
this.checkDao = function() {
return new Promise( function(resolve, reject) {
try {
daoService.set('check', 'true', function(err, replay) {
if (err) resolve({type:'ERR', msg:'andmehoidlasse lisamine ei tööta: ' + err});
else {
daoService.exists('check', function(err, replay){
if (err) resolve({type:'ERR', msg:'andmehoidla kontroll ei tööta: ' + err});
else {
daoService.get('check', function(err, replay){
if (err) resolve({type:'ERR', msg:'andmehoidlast lugemine ei tööta: ' + err});
else if (replay !== 'true')
resolve({type:'ERR', msg:'andmehoidlast lugemine ei tööta: tagastatud väärtus on ' + replay});
else {
daoService.delete('check', function(err, replay) {
if (err) resolve({type:'ERR', msg:'andmehoidlast eemaldamine ei tööta: ' + err});
else {
resolve({type:'OK', msg:'andmehoidla töötab'});
}
});
};
});
};
});
}
});
} catch (err) {
resolve({type:'ERR', msg:err.message});
}
});
}
this.checkTemplate = function() {
return new Promise( function(resolve, reject) {
try {
// checking code here
} catch (err) {
resolve({type:'ERR', msg:err.message});
}
});
}
}
module.exports = new CheckService();
\ No newline at end of file
extends layout
block content
h1= title
ul
each res in results
li= res['type'] + ' : ' + res['msg']
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