Updated Branches: refs/heads/trunk 6d5b66759 -> 720671a1e
AMBARI-3977. Dont request all tasks fields during deploy. (onechiporenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/720671a1 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/720671a1 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/720671a1 Branch: refs/heads/trunk Commit: 720671a1e86baa6721debff81d01527c19a97f1d Parents: 6d5b667 Author: Oleg Nechiporenko <onechipore...@apache.org> Authored: Wed Dec 4 20:15:09 2013 +0200 Committer: Oleg Nechiporenko <onechipore...@apache.org> Committed: Wed Dec 4 20:17:43 2013 +0200 ---------------------------------------------------------------------- .../app/controllers/wizard/step9_controller.js | 97 ++++++++++++- ambari-web/app/templates/wizard/step9.hbs | 46 +++--- .../templates/wizard/step9HostTasksLogPopup.hbs | 19 ++- ambari-web/app/views/wizard/step9_view.js | 140 +++++++++---------- 4 files changed, 193 insertions(+), 109 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/720671a1/ambari-web/app/controllers/wizard/step9_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/wizard/step9_controller.js b/ambari-web/app/controllers/wizard/step9_controller.js index 29bf7e1..0647172 100644 --- a/ambari-web/app/controllers/wizard/step9_controller.js +++ b/ambari-web/app/controllers/wizard/step9_controller.js @@ -702,6 +702,16 @@ App.WizardStep9Controller = Em.Controller.extend({ // current requestId. return false; } + tasksData.setEach('Tasks.stderr', ''); + tasksData.setEach('Tasks.stdout', ''); + if (this.get('currentOpenTaskId')) { + var currentTask = tasksData.findProperty('Tasks.id', this.get('currentOpenTaskId')); + var log = this.get('currentOpenTaskLog'); + if (currentTask && log) { + currentTask.Tasks.stderr = log.stderr; + currentTask.Tasks.stdout = log.stdout; + } + } this.replacePolledData(tasksData); this.get('hosts').forEach(function (_host) { var actionsPerHost = tasksData.filterProperty('Tasks.host_name', _host.name); // retrieved from polled Data @@ -740,7 +750,7 @@ App.WizardStep9Controller = Em.Controller.extend({ getUrl: function (requestId) { var clusterName = this.get('content.cluster.name'); var requestId = requestId || this.get('content.cluster.requestId'); - var url = App.apiPrefix + '/clusters/' + clusterName + '/requests/' + requestId + '?fields=tasks/*'; + var url = App.apiPrefix + '/clusters/' + clusterName + '/requests/' + requestId + '?fields=*,tasks/Tasks/command,tasks/Tasks/exit_code,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status'; console.log("URL for step9 is: " + url); return url; }, @@ -762,6 +772,88 @@ App.WizardStep9Controller = Em.Controller.extend({ }, this); }, + /** + * {Number} + * <code>taskId</code> of current open task + */ + currentOpenTaskId: 0, + /** + * {Number} + * <code>requestId</code> of current open task + */ + currentOpenTaskRequestId: 0, + /** + * {Object} + * Log of current open task (loaded from server) + * Fields: { + * stdout: '', + * stderr: '' + * } + */ + currentOpenTaskLog: null, + + /** + * Load form server <code>stderr, stdout</code> of current open task + */ + loadCurrentTaskLog: function() { + var taskId = this.get('currentOpenTaskId'); + var requestId = this.get('currentOpenTaskRequestId'); + var clusterName = this.get('content.cluster.name'); + if (!taskId) { + console.log('taskId is null.'); + return; + } + App.ajax.send({ + name: 'background_operations.get_by_task', + sender: this, + data: { + 'taskId': taskId, + 'requestId': requestId, + 'clusterName': clusterName, + 'sync': true + }, + success: 'loadCurrentTaskLogSuccessCallback', + error: 'loadCurrentTaskLogErrorCallback' + }); + }, + + loadCurrentTaskLogSuccessCallback: function(data) { + this.set('currentOpenTaskLog', { + stdout: data.Tasks.stdout, + stderr: data.Tasks.stderr + }); + var taskId = this.get('currentOpenTaskId'); + if (taskId) { + var currentTask = this.get('polledData').findProperty('Tasks.id', taskId); + var log = this.get('currentOpenTaskLog'); + if (currentTask && log) { + currentTask.Tasks.stderr = data.Tasks.stderr; + currentTask.Tasks.stdout = data.Tasks.stdout; + this.updateHostLogTask(data.Tasks.host_name, data.Tasks.id, data.Tasks.stderr, data.Tasks.stdout); + } + } + this.set('logTasksChangesCounter', this.get('logTasksChangesCounter') + 1); + }, + + loadCurrentTaskLogErrorCallback: function() { + this.set('currentOpenTaskId', 0); + this.set('currentOpenTaskRequestId', 0); + }, + /** + * Update log task for provided host + * @param {String} hostName + * @param {Number} taskId + * @param {String} stderr + * @param {String} stdout + */ + updateHostLogTask: function(hostName, taskId, stderr, stdout) { + var logTask = this.get('hosts').findProperty('name', hostName).get('logTasks').findProperty('Tasks.id', taskId); + if (logTask) { + logTask.Tasks.stderr = stderr; + logTask.Tasks.stdout = stdout; + } + }, + // polling: whether to continue polling for status or not getLogsByRequest: function(url, polling){ var self = this; @@ -781,6 +873,9 @@ App.WizardStep9Controller = Em.Controller.extend({ } if (result !== true) { window.setTimeout(function () { + if (self.get('currentOpenTaskId')) { + self.loadCurrentTaskLog(); + } self.doPolling(); }, self.POLL_INTERVAL); } else { http://git-wip-us.apache.org/repos/asf/ambari/blob/720671a1/ambari-web/app/templates/wizard/step9.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/wizard/step9.hbs b/ambari-web/app/templates/wizard/step9.hbs index 9ede6c5..eff8425 100644 --- a/ambari-web/app/templates/wizard/step9.hbs +++ b/ambari-web/app/templates/wizard/step9.hbs @@ -78,32 +78,30 @@ <tbody> {{#if controller.visibleHosts.length}} - {{#each host in controller.visibleHosts}} - {{#view App.HostStatusView objBinding="host"}} - <td> - {{host.name}} - </td> - <td> - <div class="progress-bar pull-left"> - <div {{bindAttr class="view.isHostCompleted::progress-striped view.isHostCompleted::active view.barColor :progress"}}> - <div class="bar" {{bindAttr style="view.barWidth"}}> - </div> - </div> - </div> - <div class="progress-percentage pull-left">{{host.progress}}%</div> - </td> - <td> - <a {{bindAttr class="view.isFailed:text-error view.isSuccess:text-success view.isWarning:text-warning"}} - href="javascript:void(null)" - data-toggle="modal" {{action hostLogPopup host target="view"}}>{{host.message}}</a> - </td> - - {{/view}} - {{/each}} + {{#each host in controller.visibleHosts}} + {{#view App.HostStatusView objBinding="host" controllerBinding="controller"}} + <td> + {{host.name}} + </td> + <td> + <div class="progress-bar pull-left"> + <div {{bindAttr class="view.isHostCompleted::progress-striped view.isHostCompleted::active view.barColor :progress"}}> + <div class="bar" {{bindAttr style="view.barWidth"}}></div> + </div> + </div> + <div class="progress-percentage pull-left">{{host.progress}}%</div> + </td> + <td> + <a {{bindAttr class="view.isFailed:text-error view.isSuccess:text-success view.isWarning:text-warning"}} + href="javascript:void(null)" + data-toggle="modal" {{action hostLogPopup target="view"}}>{{host.message}}</a> + </td> + {{/view}} + {{/each}} {{else}} - <tr> + <tr> <td colspan="3"><p>{{t installer.step3.hosts.noHosts}}</p></td> - </tr> + </tr> {{/if}} </tbody> http://git-wip-us.apache.org/repos/asf/ambari/blob/720671a1/ambari-web/app/templates/wizard/step9HostTasksLogPopup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/wizard/step9HostTasksLogPopup.hbs b/ambari-web/app/templates/wizard/step9HostTasksLogPopup.hbs index 6c21f65..08c1df4 100644 --- a/ambari-web/app/templates/wizard/step9HostTasksLogPopup.hbs +++ b/ambari-web/app/templates/wizard/step9HostTasksLogPopup.hbs @@ -17,7 +17,7 @@ }} <div {{bindAttr class="view.isLogWrapHidden::hidden :task-list-main-warp"}}> <div class="task-top-wrap"> - {{t common.tasks}} + {{t common.tasks}} <div class="select-wrap"> {{t common.show}}: {{view Ember.Select @@ -30,15 +30,15 @@ </div> <div id="host-log"> {{#each taskInfo in view.tasks}} - <div {{bindAttr class="taskInfo.isVisible::hidden :log-list-wrap"}}> - <div {{action toggleTaskLog taskInfo}} class="task-list-line-cursor"> - <i {{bindAttr class="taskInfo.status taskInfo.icon"}}></i> - <a href="#" class="" > - {{taskInfo.role}} {{taskInfo.command}} - </a> - <div class="show-details"><i class="icon-caret-right"></i></div> + <div {{bindAttr class="taskInfo.isVisible::hidden :log-list-wrap"}}> + <div {{action toggleTaskLog taskInfo}} class="task-list-line-cursor"> + <i {{bindAttr class="taskInfo.status taskInfo.icon"}}></i> + <a href="#"> + {{taskInfo.role}} {{taskInfo.command}} + </a> + <div class="show-details"><i class="icon-caret-right"></i></div> + </div> </div> - </div> {{/each}} {{#if view.isEmptyList}} <div class="log-list-wrap">{{t installer.step9.hostLog.popup.noTasksToShow}}</div> @@ -50,7 +50,6 @@ <div class="task-top-wrap"> <a class="task-detail-back" href="javascript:void(null)" {{action backToTaskList}} ><i class="icon-arrow-left"></i> {{t common.tasks}}</a> <div> - <!--<img src="data:image/png;base64,R0lGODlhFAAUAIAAAP///wAAACH5BAEAAAAALAAAAAAUABQAAAIRhI+py+0Po5y02ouz3rz7rxUAOw==" class="task-detail-status-ico" />--> <i {{bindAttr class="view.openedTask.status :task-detail-status-ico view.openedTask.icon"}} class="task-detail-status-ico"></i> <span class="task-detail-log-rolename" >{{view.openedTask.role}} {{view.openedTask.command}}</span> </div> http://git-wip-us.apache.org/repos/asf/ambari/blob/720671a1/ambari-web/app/views/wizard/step9_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/wizard/step9_view.js b/ambari-web/app/views/wizard/step9_view.js index 87e4148..3221f74 100644 --- a/ambari-web/app/views/wizard/step9_view.js +++ b/ambari-web/app/views/wizard/step9_view.js @@ -65,12 +65,18 @@ App.WizardStep9View = Em.View.extend({ }); App.HostStatusView = Em.View.extend({ - tagName:'tr', - obj:'null', - barColor:'', + tagName: 'tr', + /** + * Current host + */ + obj: null, + /** + * wizardStep9Controller + */ + controller: null, + barColor: '', didInsertElement:function () { - var controller = this.get('controller'); this.onStatus(); }, @@ -117,64 +123,39 @@ App.HostStatusView = Em.View.extend({ }.property('controller.isStepCompleted', 'obj.progress'), hostLogPopup:function (event, context) { - var self = this; - var host = event.context; + var controller = this.get('controller'); + var host = this.get('obj'); + App.ModalPopup.show({ - header: event.context.get('name'), + header: host.get('name'), classNames: ['sixty-percent-width-modal'], autoHeight: false, - onPrimary:function () { + secondary:null, + /** + * Current host + */ + host: host, + /** + * wizardStep9Controller + */ + c: controller, + + onClose: function() { + this.set('c.currentOpenTaskId', 0); this.hide(); }, - secondary:null, bodyClass:Ember.View.extend({ templateName:require('templates/wizard/step9HostTasksLogPopup'), - isLogWrapHidden: true, - showTextArea: false, - isEmptyList:true, - controllerBinding:context, - hostObj:function () { - return this.get('parentView.obj'); - }.property('parentView.obj'), - task: null, // set in showTaskLog; contains task info including stdout and stderr - /** - * sort task array by Id - * @param tasks - * @return {Array} - */ + isLogWrapHidden: true, - sortTasksById: function(tasks){ - var result = []; - var id = 1; - for(var i = 0; i < tasks.length; i++){ - id = (tasks[i].Tasks.id > id) ? tasks[i].Tasks.id : id; - } - while(id >= 1){ - for(var j = 0; j < tasks.length; j++){ - if(id == tasks[j].Tasks.id){ - result.push(tasks[j]); - } - } - id--; - } - result.reverse(); - return result; - }, + showTextArea: false, - groupTasksByRole: function (tasks) { - var sortedTasks = []; - var taskRoles = tasks.mapProperty('Tasks.role').uniq(); - for (var i = 0; i < taskRoles.length; i++) { - sortedTasks = sortedTasks.concat(tasks.filterProperty('Tasks.role', taskRoles[i])) - } - return sortedTasks; - }, + isEmptyList: true, visibleTasks: function () { - var self = this; - self.set("isEmptyList", true); + this.set("isEmptyList", true); if (this.get('category.value')) { var filter = this.get('category.value'); var tasks = this.get('tasks'); @@ -204,7 +185,7 @@ App.HostStatusView = Em.View.extend({ } if (tasks.filterProperty("isVisible", true).length > 0) { - self.set("isEmptyList", false); + this.set("isEmptyList", false); } } }.observes('category', 'tasks'), @@ -223,16 +204,16 @@ App.HostStatusView = Em.View.extend({ tasks: function () { var tasksArr = []; + var host = this.get('parentView.host'); var tasks = this.getStartedTasks(host); - //tasks = this.sortTasksById(tasks); tasks = tasks.sort(function(a,b){ return a.Tasks.id - b.Tasks.id; }); - //tasks = this.groupTasksByRole(tasks); if (tasks.length) { tasks.forEach(function (_task) { var taskInfo = Ember.Object.create({}); taskInfo.set('id', _task.Tasks.id); + taskInfo.set('requestId', _task.Tasks.request_id); taskInfo.set('command', _task.Tasks.command.toLowerCase()); taskInfo.set('status', App.format.taskStatus(_task.Tasks.status)); taskInfo.set('role', App.format.role(_task.Tasks.role)); @@ -257,7 +238,7 @@ App.HostStatusView = Em.View.extend({ }, this); } return tasksArr; - }.property('App.router.wizardStep9Controller.logTasksChangesCounter'), + }.property('parentView.c.logTasksChangesCounter'), backToTaskList: function(event, context) { this.destroyClipBoard(); @@ -267,7 +248,6 @@ App.HostStatusView = Em.View.extend({ getStartedTasks:function (host) { var startedTasks = host.logTasks.filter(function (task) { return task.Tasks.status; - //return task.Tasks.status != 'PENDING' && task.Tasks.status != 'QUEUED'; }); return startedTasks; }, @@ -279,47 +259,59 @@ App.HostStatusView = Em.View.extend({ newdocument.close(); }, - openedTaskId: 0, - - openedTask: function () { - if (!this.get('openedTaskId')) { - return Ember.Object.create(); + openedTask: null, + /** + * Set logs (stderr, stdout) to the current opened task + */ + currentOpenTaskLogObserver: function() { + if (!this.get('parentView.c.currentOpenTaskId')) { + this.set('openedTask', Ember.Object.create()); + } + this.set('openedTask', this.get('tasks').findProperty('id', this.get('parentView.c.currentOpenTaskId'))); + if (this.get('openedTask.stdout') == '') { + this.set('openedTask.stdout', this.get('parentView.c.currentOpenTaskLog').stdout); + this.set('openedTask.stderr', this.get('parentView.c.currentOpenTaskLog').stderr); } - return this.get('tasks').findProperty('id', this.get('openedTaskId')); - }.property('tasks', 'openedTaskId'), + }.observes('tasks.@each', 'parentView.c.currentOpenTaskLog.stderr', 'parentView.c.currentOpenTaskLog.stdout'), toggleTaskLog: function (event, context) { - if (this.isLogWrapHidden) { + if (this.get('isLogWrapHidden')) { var taskInfo = event.context; this.set("isLogWrapHidden", false); - this.set('openedTaskId', taskInfo.id); + this.set('parentView.c.currentOpenTaskId', taskInfo.id); + this.set('parentView.c.currentOpenTaskRequestId', taskInfo.requestId); + this.get('parentView.c').loadCurrentTaskLog(); $(".modal").scrollTop(0); $(".modal-body").scrollTop(0); - } else { + } + else { this.set("isLogWrapHidden", true); - this.set('openedTaskId', 0); + this.set('parentView.c.currentOpenTaskId', 0); + this.set('parentView.c.currentOpenTaskRequestId', 0); } }, textTrigger:function (event) { - if($(".task-detail-log-clipboard").length > 0) - { + if($(".task-detail-log-clipboard").length > 0) { this.destroyClipBoard(); - }else - { + } + else { this.createClipBoard(); - }; + } }, - createClipBoard:function(){ + + createClipBoard:function() { + var log = $(".task-detail-log-maintext"); $(".task-detail-log-clipboard-wrap").html('<textarea class="task-detail-log-clipboard"></textarea>'); $(".task-detail-log-clipboard") .html("stderr: \n"+$(".stderr").html()+"\n stdout:\n"+$(".stdout").html()) .css("display","block") - .width($(".task-detail-log-maintext").width()) - .height($(".task-detail-log-maintext").height()) + .width(log.width()) + .height(log.height()) .select(); - $(".task-detail-log-maintext").css("display","none") + log.css("display","none") }, + destroyClipBoard:function(){ $(".task-detail-log-clipboard").remove(); $(".task-detail-log-maintext").css("display","block");