var jsnlog_nodejs = require('jsnlog-nodejs').jsnlog_nodejs;
var logger = JL('app.js');
var AppConfig = require('./config.json');
-var dbpool = require('./controller/dbpool');
var cleanup = require('./controller/cleanup');
var app = express();
res.send('');
});
-process.stdin.resume();
-
-var allCleanUp = function allCleanUp () {
- dbpool.clearAll();
-};
-cleanup.cleanup(allCleanUp);
+cleanup.cleanup();
"LOG": "mic.log"
},
"EVENT": {
- "SOCKET":{
+ "SOCKET": {
"FS_IMAGE_ADD_FROM": "ws/fs/image/add/from",
"FS_IMAGE_ADD_TO": "ws/fs/image/add/to",
"FS_IMAGE_ADD_FINISH": "ws/fs/image/add/finish",
"MIC_NEXT_JOB_TO": "ws/mic/nextjob/to",
"MIC_ADD_PID_JOB_TO": "ws/mic/pid/to"
},
- "JOB": {
- "ADD_JOB": "/api/jobs",
- "CANCEL_JOB": "/api/jobs/",
- "GET_JOBS": "/api/jobs",
- "READ_LOG": "/api/logs/"
- },
- "PACKAGE": {
+ "REST": {
+ "CONFIG": "/api/config",
+ "ANALYSIS": "/api/analysis",
"IMPORT": "/api/imports",
"EXPORT": "/api/exports",
"EXPORT_KS": "ks",
"EXPORT_RECIPE": "recipe",
- "ANALYSIS": "/api/analysis",
- "RECIPE": "/api/recipe"
- },
- "IMAGE": {
- "GET_IMAGES": "/api/images",
- "IMAGE_GET_ALL_COUNT": "/api/image/count/",
- "IMAGE_GET_ALL_LISTITEM": "/api/image/list/",
- "IMAGE_ADD_ONE": "/api/image/add/"
- },
- "SESSION": {
- "SESSION": "/api/session"
+ "RECIPE": "/api/recipe",
+ "SESSION": "/api/session",
+ "JOBS": "/api/jobs",
+ "IMAGES": "/api/images",
+ "LOGS": "/api/logs/"
}
}
}
\ No newline at end of file
function Auth() {
var permissions = [
// TODO: fix the api name
- { api: AppConfig.EVENT.JOB.JOB_ADD_ONE, method: 'POST', group: 'MASTER' }, // job create
- { api: '/api/jobs', method: 'PUT', group: 'MASTER' }, // job cancel
- { api: '/api/images', method: 'DELETE', group: 'ADMIN' } // image delete
+ { api: AppConfig.EVENT.REST.JOBS, method: 'POST', group: 'MASTER' }, // job create
+ { api: AppConfig.EVENT.REST.JOBS, method: 'PUT', group: 'MASTER' }, // job cancel
+ { api: AppConfig.EVENT.REST.IMAGES, method: 'DELETE', group: 'ADMIN' } // image delete
];
function getPermissions() {
var JL = require('jsnlog').JL;
var logger = JL('cleanup.js');
+var dbpool = require('./dbpool');
-function noOperation() {};
+var cleanup = function() {
-var cleanup = function cleanup (callback) {
- callback = callback || noOperation;
+ process.stdin.resume();
/**
* When app is closing
*/
- process.on('exit', callback);
+ process.on('exit', function() {
+ dbpool.clearAll();
+ });
/**
* When app catches ctrl + c event
*/
- process.on('SIGINT', function () {
+ process.on('SIGINT', function() {
logger.error('ctrl + c ...');
process.exit(2);
});
/**
* When app catches uncaught exceptions
*/
- process.on('uncaughtException', function (e) {
+ process.on('uncaughtException', function(e) {
logger.error('Uncaught exception ...');
logger.error(e.stack);
process.exit(99);
fs.readFile(strJobLogPath, { encoding: 'utf8' }, function (err, data) {
if (err) {
- // log file is not exist
- res.json({});
+ res.json({
+ result: false,
+ messaeg: 'log file is not exist'
+ });
} else {
- res.json(data);
+ res.json({
+ result: true,
+ data: data
+ });
}
});
}
*/
'use strict';
+
const JOBS_INIT_OFFSET = 0;
const JOBS_INIT_LIMIT = 10;
* Edit the job
*/
Jobs.prototype.editJob = function editJob (req, res) {
+ // TODO: need to modify according to rest api definition
var job_id, job_status;
job_id = req.params.id;
});
/**
- * Get The All Jobs
+ * Create Job
* @URI /api/jobs
* @TYPE POST
*/
// checks - id
if (!Number(req.params.id)) {
- return;
+ res.json({
+ result: false,
+ messaeg: 'The parameter is incorrect'
+ });
}
// checks - job_status
if (!req.body.job_status || req.body.job_status !== 'CANCELED') {
- return;
+ res.json({
+ result: false,
+ messaeg: 'The job status is incorrect'
+ });
}
// call
/**
* Read the log file
* @URI /api/logs/:id
- * @TYPE POST
+ * @TYPE GET
*/
router.get('/logs/:id', function (req, res) {
+ logger.info('an api called that /api/logs/');
if (!Number(req.params.id)) {
- return;
+ res.json({
+ result: false,
+ messaeg: 'The parameter is incorrect'
+ });
}
- logger.info('an api called that /api/logs/' + req.params.id);
filesystem.readLogFile(req, res);
});
/**
* Get The All Images
* @URI /api/image/list
- * @TYPE POST
+ * @TYPE GET
*/
router.get('/images', function (req, res) {
logger.info('an api called that /api/images');
});
});
- socket.on('forceDisconnect', function() {
- logger.error('socket on forceDisconnect.');
- socket.disconnect(true);
- });
-
socket.on('disconnect', function() {
logger.info('client disconnected');
});
</table>
</div>
<div class="panel-footer">
- <a type="button" id="tic-package-create" class="btn btn-primary disabled" href="#">Image Creation</a>
+ <a type="button" id="tic-package-create" class="btn btn-primary" href="#">Image Creation</a>
</div>
</div>
</div><!-- /End Package Right Column -->
function showExportDialog() {
Util.showConfirmDialog('Are you sure you want to export recipe?')
.then(function () {
- return Util.POST(CONFIG.EVENT.PACKAGE.EXPORT, {
- format: CONFIG.EVENT.PACKAGE.EXPORT_RECIPE,
+ return Util.POST(CONFIG.EVENT.REST.EXPORT, {
+ format: CONFIG.EVENT.REST.EXPORT_RECIPE,
recipes: require('js/page/settings').getRecipeStore(),
packages: _.map(require('js/page/package').getCheckedPackages(), 'name')
});
}
function getImages () {
- var strUrl = AppConfig.EVENT.IMAGE.GET_IMAGES + '?' + Util.encodeURIDataObj(pagingObj);
+ var strUrl = AppConfig.EVENT.REST.IMAGES + '?' + Util.encodeURIDataObj(pagingObj);
logger.info('getJobs : ' + strUrl);
return Util.GET(strUrl);
}
recipes : recipeStore
};
- return Util.POST(CONFIG.EVENT.PACKAGE.IMPORT, postBody)
+ return Util.POST(CONFIG.EVENT.REST.IMPORT, postBody)
.then(function (result) {
if (result.result === 'true') {
return result.data.recipes;
$('#tic-import-recipe-file-group-help').append(helpDomContent);
}
$('#tic-import-recipe-file-input').dropzone({
- url: CONFIG.EVENT.PACKAGE.RECIPE,
+ url: CONFIG.EVENT.REST.RECIPE,
method: 'post',
maxFilesize: 5, // MB
maxFiles: 2, // Hack for replacing file
}
}
- function updateJobsModel (jobs) {
+ function updateJobsModel (res) {
// successfully get the all jobs
return new Promise (function (resolve, reject) {
var targetPaging, targetTableBody;
+ if (res.result === false) {
+ reject(res);
+ }
ModelJobList = [];
// jobs model
- _.forEach(jobs.data, function (jobItem) {
+ _.forEach(res.data, function (jobItem) {
// add the information of user's group
jobItem['job_usergroup'] = _.isEmpty(UserInfo) ? USER_DEFAULT : UserInfo.group;
_.forEach(ModelJobList, function (value, index) {
targetTableBody.append(new JobTableItem(value, index).getRow());
if (value.getJobStatus() === JOB_STATUS_INPROGRESS) {
- Util.GET(AppConfig.EVENT.JOB.READ_LOG + value.getJobId())
- .then(function (line) {
- targetId = '#extended_job_table_row_' + value.getJobId();
- $(targetId).append(line);
+ Util.GET(AppConfig.EVENT.REST.LOGS + value.getJobId())
+ .then(function (res) {
+ if (res.result) {
+ targetId = '#extended_job_table_row_' + value.getJobId();
+ $(targetId).append(res.data);
+ } else {
+ logger.error(res.message);
+ }
});
}
});
job_status: JOB_STATUS_CANCELED
};
- Util.PUT(AppConfig.EVENT.JOB.CANCEL_JOB + jobId, msgData)
+ Util.PUT(AppConfig.EVENT.REST.JOBS + '/' + jobId, msgData)
.then(updateList);
});
}
// jobs paging
if (_.isEmpty(ModelJobPaging)) {
ModelJobPaging = new PagingModel({
- total: jobs.total,
- offset: jobs.offset,
- limit: jobs.limit
+ total: res.total,
+ offset: res.offset,
+ limit: res.limit
});
} else {
ModelJobPaging.update({
- total: jobs.total,
- offset: jobs.offset,
- limit: jobs.limit
+ total: res.total,
+ offset: res.offset,
+ limit: res.limit
});
}
var pagenum = Number($(this).data('pagenum'));
if (pagenum !== 0) {
updateList({
- offset: (pagenum-1)*jobs.limit,
- limit: jobs.limit
+ offset: (pagenum-1)*res.limit,
+ limit: res.limit
});
}
return;
* @description get all the jobs per page
*/
function getJobs () {
- var strUrl = AppConfig.EVENT.JOB.GET_JOBS + '?' + Util.encodeURIDataObj(pagingObj);
+ var strUrl = AppConfig.EVENT.REST.JOBS + '?' + Util.encodeURIDataObj(pagingObj);
logger.info('getJobs : ' + strUrl);
return Util.GET(strUrl);
}
'use strict';
var logger = Logger('login.js');
+ var CONFIG = null;
/**
* listener of input change in login
// prevent for sumbit of form
e.preventDefault();
- Util.POST('api/session', {
+ Util.POST(CONFIG.EVENT.REST.SESSION, {
email : $('#tic-page-login-form-email').val(),
password: $('#tic-page-login-form-password').val()
})
// prevent for sumbit of form
e.preventDefault();
- Util.DELETE('api/session')
+ Util.DELETE(CONFIG.EVENT.REST.SESSION)
.then(function (result) {
if (result.result) {
logger.info('logout success');
* FIXME: remove permission control in client side
*/
function updatePermission() {
- Util.GET('api/session')
+ Util.GET(CONFIG.EVENT.REST.SESSION)
.then(function (result) {
_updateLogin(result.data);
_updatePackagePage(result.data);
function init() {
logger.info('init');
- _loginFormHandler();
- _loginHandler();
- _logoutHandler();
+ Util.getAppConfig()
+ .then(function (conf) {
+ CONFIG = conf;
- updatePermission();
+ _loginFormHandler();
+ _loginHandler();
+ _logoutHandler();
+
+ updatePermission();
+ });
}
init();
function addJob () {
var msgObj = {
- format: AppConfig.EVENT.PACKAGE.EXPORT_KS,
+ format: AppConfig.EVENT.REST.EXPORT_KS,
recipes: Settings.getRecipeStore(),
packages: _.map(checkedPackagesList, 'name')
};
logger.info('onClickHandlerForImgCreationBtn.addJob');
- return Util.POST(AppConfig.EVENT.JOB.ADD_JOB, msgObj);
+ return Util.POST(AppConfig.EVENT.REST.JOBS, msgObj);
}
// confirm dialog
recipes : recipeStore
};
- return Util.POST(CONFIG.EVENT.PACKAGE.ANALYSIS, postBody)
+ return Util.POST(CONFIG.EVENT.REST.ANALYSIS, postBody)
.then(function (result) {
if (result.result === 'true') {
setRecipeStore(result.data.recipes);
*/
define([
- 'jquery'
+ 'jquery',
+ 'js/logger'
], function (
- $
+ $,
+ Logger
) {
'use strict';
+ var logger = Logger('util.js');
+
var socket = null;
var config = null;
}
function readLog(linkid) {
- GET(config.EVENT.JOB.READ_LOG + linkid)
- .then(function (line) {
- $('#' + targetId).append(line);
- $('#log-view-content').show();
+ GET(config.EVENT.REST.LOGS + linkid)
+ .then(function (res) {
+ if (res.result) {
+ $('#' + targetId).append(res.data);
+ $('#log-view-content').show();
+ } else {
+ logger.error(res.message);
+ }
});
}