hostLogPopupBody_view.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var date = require('utils/date');
  20. App.WizardStep9HostLogPopupBodyView = Em.View.extend({
  21. templateName: require('templates/wizard/step9/step9HostTasksLogPopup'),
  22. /**
  23. * Does host lost heartbeat
  24. * @type {bool}
  25. */
  26. isHeartbeatLost: function() {
  27. return (this.get('parentView.host.status') === 'heartbeat_lost');
  28. }.property('parentView.host.status'),
  29. /**
  30. * Does host doesn't have scheduled tasks for install
  31. * @type {bool}
  32. */
  33. isNoTasksScheduled: function() {
  34. return this.get('parentView.host.isNoTasksForInstall');
  35. }.property('parentView.host.isNoTasksForInstall'),
  36. /**
  37. * Is log-box hidden
  38. * @type {bool}
  39. */
  40. isLogWrapHidden: true,
  41. /**
  42. * Is log-textarea visible
  43. * @type {bool}
  44. */
  45. showTextArea: false,
  46. /**
  47. * No tasks shown
  48. * @type {bool}
  49. */
  50. isEmptyList: true,
  51. /**
  52. * Checks if no visible tasks are in popup
  53. * @method visibleTasks
  54. */
  55. visibleTasks: function () {
  56. this.set("isEmptyList", true);
  57. if (this.get('category.value')) {
  58. var filter = this.get('category.value');
  59. var tasks = this.get('tasks');
  60. tasks.setEach("isVisible", false);
  61. if (filter == "all") {
  62. tasks.setEach("isVisible", true);
  63. }
  64. else if (filter == "pending") {
  65. tasks.filterProperty("status", "pending").setEach("isVisible", true);
  66. tasks.filterProperty("status", "queued").setEach("isVisible", true);
  67. }
  68. else if (filter == "in_progress") {
  69. tasks.filterProperty("status", "in_progress").setEach("isVisible", true);
  70. }
  71. else if (filter == "failed") {
  72. tasks.filterProperty("status", "failed").setEach("isVisible", true);
  73. }
  74. else if (filter == "completed") {
  75. tasks.filterProperty("status", "completed").setEach("isVisible", true);
  76. }
  77. else if (filter == "aborted") {
  78. tasks.filterProperty("status", "aborted").setEach("isVisible", true);
  79. }
  80. else if (filter == "timedout") {
  81. tasks.filterProperty("status", "timedout").setEach("isVisible", true);
  82. }
  83. if (tasks.filterProperty("isVisible", true).length > 0) {
  84. this.set("isEmptyList", false);
  85. }
  86. }
  87. }.observes('category', 'tasks'),
  88. /**
  89. * List categories (implements possible values for task status)
  90. * @type {Em.Object[]}
  91. */
  92. categories: [
  93. Em.Object.create({value: 'all', label: Em.I18n.t('installer.step9.hostLog.popup.categories.all') }),
  94. Em.Object.create({value: 'pending', label: Em.I18n.t('installer.step9.hostLog.popup.categories.pending')}),
  95. Em.Object.create({value: 'in_progress', label: Em.I18n.t('installer.step9.hostLog.popup.categories.in_progress')}),
  96. Em.Object.create({value: 'failed', label: Em.I18n.t('installer.step9.hostLog.popup.categories.failed') }),
  97. Em.Object.create({value: 'completed', label: Em.I18n.t('installer.step9.hostLog.popup.categories.completed') }),
  98. Em.Object.create({value: 'aborted', label: Em.I18n.t('installer.step9.hostLog.popup.categories.aborted') }),
  99. Em.Object.create({value: 'timedout', label: Em.I18n.t('installer.step9.hostLog.popup.categories.timedout') })
  100. ],
  101. /**
  102. * Current category
  103. * @type {Em.Object}
  104. */
  105. category: null,
  106. /**
  107. * List of tasks
  108. * @type {Em.Object[]}
  109. */
  110. tasks: function () {
  111. var tasksArr = [];
  112. var host = this.get('parentView.host');
  113. var tasks = this.getStartedTasks(host);
  114. tasks = tasks.sortProperty('Tasks.id');
  115. if (tasks.length) {
  116. tasks.forEach(function (_task) {
  117. var taskInfo = Em.Object.create({});
  118. taskInfo.set('id', _task.Tasks.id);
  119. taskInfo.set('requestId', _task.Tasks.request_id);
  120. taskInfo.set('command', _task.Tasks.command.toLowerCase() === 'service_check' ? '' : _task.Tasks.command.toLowerCase());
  121. taskInfo.set('status', App.format.taskStatus(_task.Tasks.status));
  122. taskInfo.set('role', App.format.role(_task.Tasks.role));
  123. taskInfo.set('stderr', _task.Tasks.stderr);
  124. taskInfo.set('stdout', _task.Tasks.stdout);
  125. taskInfo.set('startTime', date.startTime(_task.Tasks.start_time));
  126. taskInfo.set('duration', date.durationSummary(_task.Tasks.start_time, _task.Tasks.end_time));
  127. taskInfo.set('isVisible', true);
  128. taskInfo.set('icon', '');
  129. taskInfo.set('hostName', _task.Tasks.host_name);
  130. taskInfo.set('outputLog', Em.I18n.t('common.hostLog.popup.logDir.path') + Em.I18n.t('common.hostLog.popup.outputLog.value').format(_task.Tasks.id));
  131. taskInfo.set('errorLog', Em.I18n.t('common.hostLog.popup.logDir.path') + Em.I18n.t('common.hostLog.popup.errorLog.value').format(_task.Tasks.id));
  132. if (taskInfo.get('status') == 'pending' || taskInfo.get('status') == 'queued') {
  133. taskInfo.set('icon', 'icon-cog');
  134. } else if (taskInfo.get('status') == 'in_progress') {
  135. taskInfo.set('icon', 'icon-cogs');
  136. } else if (taskInfo.get('status') == 'completed') {
  137. taskInfo.set('icon', 'icon-ok');
  138. } else if (taskInfo.get('status') == 'failed') {
  139. taskInfo.set('icon', 'icon-exclamation-sign');
  140. } else if (taskInfo.get('status') == 'aborted') {
  141. taskInfo.set('icon', 'icon-minus');
  142. } else if (taskInfo.get('status') == 'timedout') {
  143. taskInfo.set('icon', 'icon-time');
  144. }
  145. tasksArr.push(taskInfo);
  146. }, this);
  147. }
  148. return tasksArr;
  149. }.property('parentView.c.logTasksChangesCounter'),
  150. /**
  151. * Navigate to task list from task view
  152. * @method backToTaskList
  153. */
  154. backToTaskList: function () {
  155. this.destroyClipBoard();
  156. this.set("isLogWrapHidden", true);
  157. },
  158. /**
  159. * Get list of host's started tasks
  160. * @param {object} host
  161. * @returns {object[]}
  162. * @method getStartedTasks
  163. */
  164. getStartedTasks: function (host) {
  165. return host.logTasks.filter(function (task) {
  166. return task.Tasks.status;
  167. });
  168. },
  169. /**
  170. * Open new window with task's log
  171. * @method openTaskLogInDialog
  172. */
  173. openTaskLogInDialog: function () {
  174. var newwindow = window.open();
  175. var newdocument = newwindow.document;
  176. newdocument.write($(".task-detail-log-info").html());
  177. newdocument.close();
  178. },
  179. /**
  180. * Currently open task
  181. * @type {Em.Object}
  182. */
  183. openedTask: function () {
  184. return this.get('tasks').findProperty('id', this.get('parentView.c.currentOpenTaskId'))
  185. }.property('parentView.c.currentOpenTaskId', 'tasks.@each'),
  186. /**
  187. * Click-handler for toggle task's log view (textarea to box and back)
  188. * @param {object} event
  189. * @method toggleTaskLog
  190. */
  191. toggleTaskLog: function (event) {
  192. if (this.get('isLogWrapHidden')) {
  193. var taskInfo = event.context;
  194. this.set("isLogWrapHidden", false);
  195. this.set('parentView.c.currentOpenTaskId', taskInfo.id);
  196. this.set('parentView.c.currentOpenTaskRequestId', taskInfo.requestId);
  197. this.get('parentView.c').loadCurrentTaskLog();
  198. $(".modal").scrollTop(0);
  199. $(".modal-body").scrollTop(0);
  200. }
  201. else {
  202. this.set("isLogWrapHidden", true);
  203. this.set('parentView.c.currentOpenTaskId', 0);
  204. this.set('parentView.c.currentOpenTaskRequestId', 0);
  205. }
  206. },
  207. /**
  208. * Create (if doesn't exist) or destroy (if exists) clipboard textarea
  209. * @method textTrigger
  210. */
  211. textTrigger: function () {
  212. if ($(".task-detail-log-clipboard").length > 0) {
  213. this.destroyClipBoard();
  214. }
  215. else {
  216. this.createClipBoard();
  217. }
  218. },
  219. /**
  220. * Create clipboard with task's log
  221. * @method createClipBoard
  222. */
  223. createClipBoard: function () {
  224. var log = $(".task-detail-log-maintext");
  225. $(".task-detail-log-clipboard-wrap").html('<textarea class="task-detail-log-clipboard"></textarea>');
  226. $(".task-detail-log-clipboard")
  227. .html("stderr: \n" + $(".stderr").html() + "\n stdout:\n" + $(".stdout").html())
  228. .css("display", "block")
  229. .width(log.width())
  230. .height(log.height())
  231. .select();
  232. log.css("display", "none")
  233. },
  234. /**
  235. * Destroy clipboard with task's log
  236. * @method destroyClipBoard
  237. */
  238. destroyClipBoard: function () {
  239. $(".task-detail-log-clipboard").remove();
  240. $(".task-detail-log-maintext").css("display", "block");
  241. }
  242. });