var JL = require('jsnlog').JL;
var jsnlog_nodejs = require('jsnlog-nodejs').jsnlog_nodejs;
var logger = JL('app.js');
-var CONFIG = require('./config.json');
+var AppConfig = require('./config.json');
+
var app = express();
/* app config */
-app.set('port', process.env.PORT || CONFIG.TIC_WEB.PORT);
+app.set('port', process.env.PORT || AppConfig.TIC_WEB.PORT);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, '/public/src'))); //module directory
"PATH": "/var/tmp/tic-web/",
"PATH_ABSTRACT": "/tic/",
"LOG_FILE" : "/var/tmp/tic-web/tic-web.log",
- "KS_FILE_NAME": "default.ks",
"LOG_FILE_NAME": "mic.log",
"IMAGE_FILE_NAME": "image.tar.gz"
},
+ "DATABASE": {
+ "USERNAME": "tic",
+ "PASSWORD": "tic",
+ "DATABASE": "pdk",
+ "HOST": "localhost",
+ "TRACE": true,
+ "DIALECT": "mariasql",
+ "POOL": {
+ "MAX": 5,
+ "MIN": 1,
+ "IDLETIMEOUT": 500000,
+ "REAPINTERVAL": 500
+ }
+ },
"TIC_CORE": {
"PORT" : 8082
},
--- /dev/null
+'use strict'
+
+var generic_pool = require('generic-pool');
+var mariasql = require('mariasql');
+var JL = require('jsnlog').JL;
+var logger = JL('dbpool.js');
+
+var AppConfig = require('../config.json');
+
+
+function dbPool () {
+ var self = this;
+
+ self.configMariasql = {
+ host: AppConfig.DATABASE.HOST,
+ user: AppConfig.DATABASE.USERNAME,
+ password: AppConfig.DATABASE.PASSWORD,
+ db: AppConfig.DATABASE.DATABASE,
+ trace: AppConfig.DATABASE.TRACE,
+ pingInactive: 1000,
+ metadata: false
+ };
+
+ self.pool = generic_pool.createPool({
+ name: AppConfig.DATABASE.DIALECT,
+
+ create: function (callback) {
+ return new Promise(function (resolve, reject) {
+ var mariasqlClient = new mariasql(self.configMariasql);
+ mariasqlClient.connect(function (err) {
+ if (err) {
+ logger.error('DB Connection Error !');
+ logger.error(err);
+ reject(err);
+ }
+
+ logger.info('DB Connection Success !');
+ resolve(mariasqlClient);
+ });
+
+ // mariasqlClient.on('connect', function () {
+ // logger.info('DB - connect');
+ // resolve(client);
+ // })
+ // .on('error', function (err) {
+ // logger.info('DB - error');
+ // reject(err);
+ // }).on('close', function (hadError) {
+ // logger.info('DB - close');
+ // resolve();
+ // }).on('ready', function () {
+ // logger.info('DB - ready');
+ // resolve(mariasqlClient);
+ // });
+ });
+ },
+
+ destroy: function (client) {
+ return new Promise(function (resolve, reject) {
+ client.on('end', function () {
+ resolve();
+ });
+ client.disconnect();
+ });
+ // cliend.end();
+ // client._handle = null;
+ },
+
+ validate: function (client) {
+ return client.connected;
+ },
+
+ max: AppConfig.DATABASE.POOL.MAX,
+
+ min: AppConfig.DATABASE.POOL.MIN,
+
+ idleTimeoutMillis: AppConfig.DATABASE.POOL.IDLETIMEOUT,
+
+ reapIntervalMillis: AppConfig.DATABASE.POOL.REAPINTERVAL,
+
+ returnToHead: true
+ });
+
+ // self.pool.drain().then(function () {
+ // self.pool.clear();
+ // });
+
+
+};
+
+dbPool.prototype.query = function query (query, params) {
+ var mariaPool = this.pool;
+ return new Promise (function (resolve, reject) {
+ mariaPool.acquire().then(function (client) {
+ var meta = {
+ result: []
+ };
+
+ client.query(query, params, {
+ metadata: false
+ }, function (err, rows) {
+ if (err) {
+ mariaPool.destroy(client);
+ meta.result = err;
+ return reject(meta);
+ }
+
+ meta.result = rows;
+ mariaPool.release(client);
+ logger.info(JSON.stringify(meta));
+ return resolve(meta);
+ });
+ }).catch(function (err) {
+ return reject(err);
+ });
+ });
+};
+
+
+// process.on('exit', function () {
+// dbPool.drain(function () {
+// dbpool.clear();
+// });
+// });
+
+module.exports = dbPool;
\ No newline at end of file
var mariaSql = require('mariasql');
var JL = require('jsnlog').JL;
-var logger = JL('mariadb.js');
+var logger = JL('dbquery.js');
var _ = require('lodash');
+// var sequelize = require('./dbpool');
+var dbpool = require('./dbpool');
+
+var pool = new dbpool({});
+// function fnCallback() {};
+// setInterval(function () {
+// pool.query('show tables', {});
+// console.log(process.memoryUsage());
+// }, 1000);
+
+process.on('exit', function () {
+ pool.drain(function () {
+ pool.clear();
+ });
+});
+
/**
* Client
*/
]
};
-mariadb.doQuery = function doQuery(queryString, callback) {
- return mariaSqlClient.query(queryString, callback);
+mariadb.doQuery = function doQuery(queryString) {
+ return pool.query(queryString, []);
};
/**
var queryString, strJobId, reqParam,
job_status, job_deleted, job_hasksfile, job_image_id, job_ks, job_arch;
- function onSuccess(err, rows) {
- if (err) {
- logger.error(err);
- throw err;
- }
-
+ function onSuccess(rows) {
logger.info('editJob.success');
- res.json(rows);
+ res.json(rows.result);
}
strJobId = req.params.id;
logger.info('editJob: query = ' + queryString);
- this.doQuery(queryString, onSuccess);
+ // call
+ this.doQuery(queryString).then(onSuccess);
};
/**
mariadb.addJob = function addJob(req, res) {
var queryString;
- function onSuccess(err, rows) {
- if (err) {
- logger.error(err);
- throw err;
- }
-
- logger.info('addJob.success: {job_id: ' + rows.info.insertId + '}');
+ function onSuccess(rows) {
+ logger.info('addJob.success: {job_id: ' + rows.result.info.insertId + '}');
res.json({
- job_id: rows.info.insertId
+ job_id: rows.result.info.insertId
});
}
logger.info('addJob: query = ' + queryString);
// call
- this.doQuery(queryString, onSuccess);
+ this.doQuery(queryString).then(onSuccess);
};
/**
mariadb.getJobById = function getJobById(req, res) {
var queryString, strJobId;
- function onSuccess(err, rows) {
- if (err) {
- logger.error(err);
- throw err;
- }
- res.json(rows);
+ function onSuccess(rows) {
+ res.json(rows.result);
}
strJobId = req.params.id;
logger.info('getJobById: query = ' + queryString);
// call
- this.doQuery(queryString, onSuccess);
+ this.doQuery(queryString).then(onSuccess);
};
/**
mariadb.getJobsTotalCount = function getJobsTotalCount(req, res) {
var queryString;
- function onSuccess(err, rows) {
- if (err) {
- logger.error(err);
- throw err;
- }
- res.json(rows);
+ function onSuccess(rows) {
+ res.json(rows.result);
}
queryString = _.join(this.queries['getJobsTotalCount'], '');
logger.info('getJobsTotalCount: query = ' + queryString);
// call
- this.doQuery(queryString, onSuccess);
+ this.doQuery(queryString).then(onSuccess);
};
/**
mariadb.getJobsAllList = function getJobsAllList(req, res) {
var queryString, reqParam, pageNum, startNum;
- function onSuccess(err, rows) {
- if (err) {
- logger.error(err);
- throw err;
- }
- res.json(rows);
+ function onSuccess(rows) {
+ res.json(rows.result);
}
// strNum
logger.info('getJobsAllList: query = ' + queryString);
// call
- this.doQuery(queryString, onSuccess);
+ this.doQuery(queryString).then(onSuccess);
};
mariadb.getImagesAllList = function getImagesAllList(req, res) {
var queryString, reqParam, pageNum, startNum;
- function onSuccess(err, rows) {
- if (err) {
- logger.error(err);
- throw err;
- }
- res.json(rows);
+ function onSuccess(rows) {
+ res.json(rows.result);
}
// strNum
logger.info('getImagesAllList: query = ' + queryString);
// call
- this.doQuery(queryString, onSuccess);
+ this.doQuery(queryString).then(onSuccess);
};
/**
mariadb.getImagesTotalCount = function getImagesTotalCount(req, res) {
var queryString;
- function onSuccess(err, rows) {
- if (err) {
- logger.error(err);
- throw err;
- }
- res.json(rows);
+ function onSuccess(rows) {
+ res.json(rows.result);
}
queryString = _.join(this.queries['getImagesTotalCount'], '');
logger.info('getImagesTotalCount: query = ' + queryString);
// call
- this.doQuery(queryString, onSuccess);
+ this.doQuery(queryString).then(onSuccess);
+
+
};
/**
mariadb.addImage = function addImage (req, res) {
var queryString, paramObj;
- function onSuccess(err, rows) {
- if (err) {
- logger.error(err);
- throw err;
- }
-
- logger.info('addJob: result = {image_id: ' + rows.info.insertId + '}');
+ function onSuccess(rows) {
+ var result = rows.result;
+ logger.info('addJob: result = {image_id: ' + result.info.insertId + '}');
res.json({
- image_id: rows.info.insertId
+ image_id: result.info.insertId
});
}
logger.info('addJob: query = ' + queryString);
// call
- this.doQuery(queryString, onSuccess);
+ this.doQuery(queryString).then(onSuccess);
};
var queryString, strJobId, reqParam,
job_status, job_deleted, job_hasksfile, job_image_id;
- function onSuccess(err, rows) {
- if (err) {
- logger.error(err);
- throw err;
- }
-
+ function onSuccess(rows) {
logger.info('editJob.success');
- res.json(rows);
+ res.json(rows.result);
}
strJobId = req.params.id;
logger.info('editJob: query = ' + queryString);
- this.doQuery(queryString, onSuccess);
+ // call
+ this.doQuery(queryString).then(onSuccess);
};
* @desc get user information
*/
mariadb.getUser = function getUser(query, success, error) {
- function onSuccess(err, rows) {
- if (err) {
- logger.error(err);
- error(err);
- } else {
- var resultObj = {
- data: null
- };
- if (rows.length !== NO_DATA) {
- resultObj.data = rows[0];
- }
- success(resultObj);
+ function onSuccess(rows) {
+ var resultObj = {
+ data: null
+ };
+ if (rows && rows.result && rows.result.length !== NO_DATA) {
+ resultObj.data = rows.result[0];
}
+ success(resultObj);
}
var queryString = _.template(_.join(this.queries['getUser'], ''))({
logger.info('getUser: query = ' + queryString);
// call
- this.doQuery(queryString, onSuccess);
+ this.doQuery(queryString).then(onSuccess);
};
/**
logger.info('hasUser: query = ' + queryString);
// call
- this.doQuery(queryString, onSuccess);
+ this.doQuery(queryString).then(onSuccess);
};
/**
.then(self.connectToClient);
};
-mariadb.init();
+// mariadb.init();
module.exports = mariadb;
var http = require('http');
var core = require('./ticcore');
-var client = require('./mariadb');
+var client = require('./dbquery');
var session = require('./session');
var config = require('../config.json');
var filesystem = require('./filesystem');
'use strict';
-var mariadb = require('./mariadb');
+var dbquery = require('./dbquery');
var JL = require('jsnlog').JL;
var logger = JL('session.js');
if (req.session) {
// check email and password
if (req.body.email) {
- mariadb.getUser({
+ dbquery.getUser({
email: req.body.email,
password: req.body.password
}, function success(user) {
if (user.data === null) {
// check email
- mariadb.hasUser({
+ dbquery.hasUser({
email: req.body.email
}, function success(result) {
// email validation
var mariaSql = require('mariasql');
var JL = require('jsnlog').JL;
-var logger = JL('mariadb.js');
+var logger = JL('ticcore.js');
var http = require('http');
var AppConfig = require('../config.json');
var _ = require('lodash');
"moment": "~2.17.1",
"tree-kill": "https://github.com/leechwin/node-tree-kill.git#master",
"mariasql": "~0.2.6",
+ "generic-pool": "~3.7.1",
"request": "~2.79.0",
"express-session": "~1.15.1"
},
width: 100%;
float: left;
display: table;
- margin-top: 12px;
- height: 3vh;
+ padding-top: 20px;
+ height: 4vh;
}
#tic-image-list-content {
height: calc(100vh - 320px);
background-color: #f9f9f9;
border: 1px solid #ccc;
border-radius: 5px;
+ position: fixed;
}
.log-view-content-header {
border-bottom-color: #ccc;
// initially, hide the log view
// in job and image section
$('#log-view-content').hide();
+ $('.log-view-content .log-view-content-close').on('click', function (e) {
+ e.preventDefault();
+ $('#log-view-content-body').empty();
+ $('#log-view-content').hide();
+ });
}
_.forEach(arrImages, function (value, index) {
targetBody.append(new ImageItem(value, index).getTemplate());
});
+
+ // bind events
+ $('#tic-image-list a.btnbiglog').on('click', function (e) {
+ e.preventDefault();
+ Util.showBigLogView(this);
+ });
}
});
}
ModelJobList = [];
ModelJobPaging;
- function _hideLogView () {
- logger.info('_hideLogView');
-
- }
- function _readLog (jobId) {
- logger.info('JOB_READ_LOG: ' + jobId);
-
- Util.POST(AppConfig.EVENT.JOB.JOB_READ_LOG + jobId)
- .then(function (line) {
- $('#log-view-content-body').append(line);
- });
- }
-
- function _showLogView (btn) {
- var linkid, linkurl, currentPosition, currentWidth, currentHeight;
-
- logger.info('_showLogView');
-
- linkid = $(btn).data('jobid');
- linkurl = $(btn).data('link');
-
- logger.info('(job_id:' + linkid + ') the url of link is ' + linkurl);
-
- // get value
- currentPosition = $('#tic-job-list').offset();
- currentWidth = $('#tic-job-list').width();
- currentHeight = $('#tic-job-list').height();
-
- // set value
- $('#log-view-content').width(currentWidth);
- $('#log-view-content').height(currentHeight);
- $('#log-view-content').offset({
- top: currentPosition.top,
- left: currentPosition.left
- });
-
- // show
- $('#log-view-content-body').empty();
- $('#log-view-content-download').attr('href', linkurl);
- $('#log-view-content').show();
- _readLog(linkid);
- }
-
function _updateView (arrJobs) {
return new Promise(function (resolve, reject) {
logger.info('_updateView');
// bind events
$('#tic-job-list a.btnbiglog').on('click', function (e) {
e.preventDefault();
- _showLogView(this);
+ Util.showBigLogView(this);
});
}
});
_initSocket(Util.getWebSocket());
updateList();
});
-
- $('.log-view-content .log-view-content-close').on('click', function (e) {
- e.preventDefault();
- $('#log-view-content-body').empty();
- $('#log-view-content').hide();
- });
}
init();
var socket = null;
var config = null;
+ function showBigLogView(btn) {
+ var linkid, linkurl, logViewTop, logViewLeft, logViewWidth, logViewHeight;
+
+ if (config === null) {
+ getAppConfig();
+ }
+
+ function readLog () {
+ POST(config.EVENT.JOB.JOB_READ_LOG + linkid)
+ .then(function (line) {
+ $('#log-view-content-body').append(line);
+ });
+ }
+
+ function getClientWidth () {
+ return (window.innerWidth) ? window.innerWidth : document.documentElement.clientWidth || document.body.clientWidth || 0;
+ }
+
+ function getClientHeight () {
+ return(window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight || document.body.clientHeight || 0;
+ }
+
+ linkid = $(btn).data('jobid');
+ linkurl = $(btn).data('link');
+
+ console.log('Util.showBigLogView: job_id="' + linkid + '", log_url="' + linkurl + '"');
+
+ // get value
+ logViewWidth = getClientWidth() - 18;
+ logViewHeight = getClientHeight() - 50;
+ logViewTop = 50;
+ logViewLeft = 0;
+
+ // set value
+ $('#log-view-content').width(logViewWidth);
+ $('#log-view-content').height(logViewHeight);
+ $('#log-view-content').offset({
+ top: logViewTop,
+ left: logViewLeft
+ });
+
+ // show
+ $('#log-view-content-body').empty();
+ $('#log-view-content-download').attr('href', linkurl);
+ $('#log-view-content').show();
+
+ readLog(linkid);
+ }
+
function setAnimateScroll() {
$('a.tic-page-scroll').bind('click', function(event) {
var body = $('html, body');
return {
/**
+ * Display the mic.log
+ * @method showBigLogView
+ * @param {object} btn for Log Button Element
+ */
+ showBigLogView: showBigLogView,
+
+ /**
* Set smooth scrolling, one page websites
* @method setAnimateScroll
*/
'<div class="image-list-name" title="<%= jobId %>_<%= imageFileName %>">#<%= jobId %>. <%= imageFileName %></div>',
'<div class="image-list-name-btndownload"><a class="image-list-btndownload" href="<%= imagePath %>" title="<%= imageFileName %>" date-name="<%= imageFileName %>">Download</a></div>',
'<div class="image-list-name-btndownload"><a class="image-list-btndownload <%= classJobKsPath %>" href="<%= ksPath %>" title="<%= ksFileName %>" date-name="<%= ksFileName %>">KS</a></div>',
- '<div class="image-list-name-btndownload"><a class="image-list-btndownload" href="<%= logPath %>" title="Log" date-name="<%= logFileName %>">Log</a></div>',
+ '<div class="image-list-name-btndownload"><a class="image-list-btndownload btnbiglog" data-link="<%= logPath %>" data-jobid="<%= jobId %>" title="Log" date-name="<%= logFileName %>">Log</a></div>',
'</div>',
'<div class="image-item-info">',
'<p class="image-list-detail"><b>Job ID:</b> <%= jobId %></p>',
fileSize: item.getImageSize(),
fileTime: item.getImageUptime(),
imageFileName: item.getImageName(),
- ksFileName: item.getImageKs(),
+ ksFileName: item.getImageKs() || 'None',
logFileName: AppConfig.TIC_WEB.LOG_FILE_NAME,
imagePath: item.getJobAbsImagePath(),
classJobKsPath: item.getImageHasKsFile() === '0' ? 'btnnotactive' : '',