From 89cd82b439cf2d0fdbe2edfb478d4b1ad3c59995 Mon Sep 17 00:00:00 2001 From: "Heekyoung, Oh" Date: Wed, 22 Mar 2017 20:31:18 +0900 Subject: [PATCH] [TIC-Web] Update The Function For The Image Creation. - Limited Contions are added. - The jobs that an image creation are runned only 4 at the same time Change-Id: I5f897dfa0ef365687aca053d3f38ff3262869404 Signed-off-by: Heekyoung, Oh --- controller/mic.js | 63 ++++++++++++++++++++++++++++++------ controller/socketio.js | 4 +-- public/src/css/style.css | 4 ++- public/src/js/page/job.js | 10 +++++- public/src/js/widget/JobTableItem.js | 2 +- 5 files changed, 68 insertions(+), 15 deletions(-) diff --git a/controller/mic.js b/controller/mic.js index 46a8cae..132e0ee 100644 --- a/controller/mic.js +++ b/controller/mic.js @@ -18,24 +18,60 @@ var AppConfig = require('../config.json'); var logger = JL('mic.js'); var Mic = {}; -var ps = null; + +/** + * Process Manager + * ObjectArray + * processMgr = { + * 'jobId': jobId, + * 'jobProcessId': pid + * }); + */ +var processMgr = []; Mic.isAvailable = function isAvailable() { - return (ps === null); + if (processMgr.length > 0 && processMgr.length <= 4) { + return true; + } + return false; } -Mic.kill = function kill() { - if (ps === null) { +Mic.kill = function kill(paramObj) { + var strJobId, psIndex, psObj, psId; + logger.info('MIC Kill: paramObj = ' + JSON.stringify(paramObj)); + + if (this.isAvailable() === false) { return; } - TreeKill(ps.pid, 'SIGKILL'); - ps = null; + + strJobId = paramObj.jobId; + + psIndex = _.findIndex(processMgr, function (o) { + return o.jobId == strJobId; + }) + + if (psIndex < 0) { + return; + } + psObj = processMgr[psIndex]; + psId = psObj.jobProcessId; + + TreeKill(psId, 'SIGKILL'); + processMgr.pop(psIndex); } -Mic.process = function process(command, callback) { +Mic.process = function process(command, callback, jobId) { + var ps; + // execution ps = exec(command); + // Process Manager - add + processMgr.push({ + 'jobId': jobId, + 'jobProcessId': ps.pid + }); + ps.stdout.on('data', callback.stdout || function (out) { process.stdout.write(out); }); @@ -100,8 +136,14 @@ Mic.create = function create(paramObj, io) { sendMsg(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_FAIL, 'Failed (' + code + ')'); }, exit: function (code) { - // code is the final exit code of the process, otherwise null - ps = null; + // code is the final exit code of the process + var psIndex = _.findIndex(processMgr, function (o) { + return o.jobId == strJobId; + }); + if (psIndex >= 0) { + processMgr.pop(psIndex); + } + logger.error('Terminated (' + code + ')'); if (code === 0) { sendMsg(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_FINISH, { @@ -116,7 +158,8 @@ Mic.create = function create(paramObj, io) { }); } } - } + }, + paramObj.jobId ); }; diff --git a/controller/socketio.js b/controller/socketio.js index fdd7fbc..902722e 100644 --- a/controller/socketio.js +++ b/controller/socketio.js @@ -26,8 +26,8 @@ var listen = function listen (server) { /** * AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_KILL = 'ws/fs/image/add/kill' */ - socket.on(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_KILL, function () { - Mic.kill(); + socket.on(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_KILL, function (data) { + Mic.kill(data); io.sockets.emit(AppConfig.EVENT.SOCKET.MIC_AVAILABLE_TO, Mic.isAvailable()); }); diff --git a/public/src/css/style.css b/public/src/css/style.css index 4f86ef9..a768a5b 100644 --- a/public/src/css/style.css +++ b/public/src/css/style.css @@ -173,6 +173,7 @@ body { display: inline-block; width: 100%; text-align: center; + overflow: scroll; } #tic-job-section .panel-heading .pull-right { margin-top: -20px; @@ -263,8 +264,9 @@ tr.extended_job_table_row:hover td { overflow: auto; } #tic-image-list { + height: calc(100vh - 285px); display: inline-block; - overflow: auto; + overflow: scroll; text-overflow: ellipsis; width: 100%; } diff --git a/public/src/js/page/job.js b/public/src/js/page/job.js index 5dea968..5142c09 100644 --- a/public/src/js/page/job.js +++ b/public/src/js/page/job.js @@ -73,9 +73,17 @@ define([ // bind events - cancel button $('#tic-job-table a.btncancel').on('click', function (e) { + var msgData, jobId; e.preventDefault(); + $(this).addClass('btnnotactive'); - client.emit(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_KILL); + + jobId = $(this).data('jobid'); + msgData = { + jobId: jobId + }; + + client.emit(AppConfig.EVENT.SOCKET.FS_IMAGE_ADD_KILL, msgData); }); } }); diff --git a/public/src/js/widget/JobTableItem.js b/public/src/js/widget/JobTableItem.js index 3353960..4923d22 100644 --- a/public/src/js/widget/JobTableItem.js +++ b/public/src/js/widget/JobTableItem.js @@ -29,7 +29,7 @@ define([ 'Download', '<%= jobImageSize %>', '<%= jobUptime %>', - 'Cancel', + 'Cancel', 'KS', 'Log', '', -- 2.7.4